blob: cb88e7abfe8d0e6b3870d6131e052a48bafbdf75 [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",
Shannon Nelson1cdfd882015-09-28 14:12:34 -0400232 "veb-stats",
Greg Rose7e45ab42015-02-06 08:52:19 +0000233};
234
Shannon Nelson9ac77262015-08-27 11:42:40 -0400235#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
Greg Rose7e45ab42015-02-06 08:52:19 +0000236
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000237/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000238 * i40e_partition_setting_complaint - generic complaint for MFP restriction
239 * @pf: the PF struct
240 **/
241static void i40e_partition_setting_complaint(struct i40e_pf *pf)
242{
243 dev_info(&pf->pdev->dev,
244 "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");
245}
246
247/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000248 * i40e_get_settings_link_up - Get the Link settings for when link is up
249 * @hw: hw structure
250 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000251 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000252 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000253 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000254static void i40e_get_settings_link_up(struct i40e_hw *hw,
255 struct ethtool_cmd *ecmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400256 struct net_device *netdev,
257 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000258{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000259 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000260 u32 link_speed = hw_link_info->link_speed;
261
Catherine Sullivane8278452015-02-06 08:52:08 +0000262 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000263 switch (hw_link_info->phy_type) {
264 case I40E_PHY_TYPE_40GBASE_CR4:
265 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000266 ecmd->supported = SUPPORTED_Autoneg |
267 SUPPORTED_40000baseCR4_Full;
268 ecmd->advertising = ADVERTISED_Autoneg |
269 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000270 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000271 case I40E_PHY_TYPE_XLAUI:
272 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000273 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000274 ecmd->supported = SUPPORTED_40000baseCR4_Full;
275 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000276 case I40E_PHY_TYPE_40GBASE_SR4:
277 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000278 break;
279 case I40E_PHY_TYPE_40GBASE_LR4:
280 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000281 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000282 case I40E_PHY_TYPE_10GBASE_SR:
283 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000284 case I40E_PHY_TYPE_1000BASE_SX:
285 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400286 ecmd->supported = SUPPORTED_10000baseT_Full;
287 if (hw_link_info->module_type[2] &
288 I40E_MODULE_TYPE_1000BASE_SX ||
289 hw_link_info->module_type[2] &
290 I40E_MODULE_TYPE_1000BASE_LX) {
291 ecmd->supported |= SUPPORTED_1000baseT_Full;
292 if (hw_link_info->requested_speeds &
293 I40E_LINK_SPEED_1GB)
294 ecmd->advertising |= ADVERTISED_1000baseT_Full;
295 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000296 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
297 ecmd->advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000298 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000299 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000300 case I40E_PHY_TYPE_1000BASE_T:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000301 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000302 SUPPORTED_10000baseT_Full |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400303 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000304 ecmd->advertising = ADVERTISED_Autoneg;
305 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
306 ecmd->advertising |= ADVERTISED_10000baseT_Full;
307 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
308 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400309 break;
310 case I40E_PHY_TYPE_100BASE_TX:
311 ecmd->supported = SUPPORTED_Autoneg |
312 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000313 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
314 ecmd->advertising |= ADVERTISED_100baseT_Full;
315 break;
316 case I40E_PHY_TYPE_10GBASE_CR1_CU:
317 case I40E_PHY_TYPE_10GBASE_CR1:
318 ecmd->supported = SUPPORTED_Autoneg |
319 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000320 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000321 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000322 break;
323 case I40E_PHY_TYPE_XAUI:
324 case I40E_PHY_TYPE_XFI:
325 case I40E_PHY_TYPE_SFI:
326 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000327 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000328 ecmd->supported = SUPPORTED_10000baseT_Full;
329 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000330 case I40E_PHY_TYPE_SGMII:
331 ecmd->supported = SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400332 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000333 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
334 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400335 if (pf->hw.mac.type == I40E_MAC_X722) {
336 ecmd->supported |= SUPPORTED_100baseT_Full;
337 if (hw_link_info->requested_speeds &
338 I40E_LINK_SPEED_100MB)
339 ecmd->advertising |= ADVERTISED_100baseT_Full;
340 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000341 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400342 /* Backplane is set based on supported phy types in get_settings
343 * so don't set anything here but don't warn either
344 */
345 case I40E_PHY_TYPE_40GBASE_KR4:
346 case I40E_PHY_TYPE_20GBASE_KR2:
347 case I40E_PHY_TYPE_10GBASE_KR:
348 case I40E_PHY_TYPE_10GBASE_KX4:
349 case I40E_PHY_TYPE_1000BASE_KX:
350 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000351 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000352 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000353 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
354 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000355 }
356
Catherine Sullivane8278452015-02-06 08:52:08 +0000357 /* Set speed and duplex */
358 switch (link_speed) {
359 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400360 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000361 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700362 case I40E_LINK_SPEED_20GB:
363 ethtool_cmd_speed_set(ecmd, SPEED_20000);
364 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000365 case I40E_LINK_SPEED_10GB:
366 ethtool_cmd_speed_set(ecmd, SPEED_10000);
367 break;
368 case I40E_LINK_SPEED_1GB:
369 ethtool_cmd_speed_set(ecmd, SPEED_1000);
370 break;
371 case I40E_LINK_SPEED_100MB:
372 ethtool_cmd_speed_set(ecmd, SPEED_100);
373 break;
374 default:
375 break;
376 }
377 ecmd->duplex = DUPLEX_FULL;
378}
379
380/**
381 * i40e_get_settings_link_down - Get the Link settings for when link is down
382 * @hw: hw structure
383 * @ecmd: ethtool command to fill in
384 *
385 * Reports link settings that can be determined when link is down
386 **/
387static void i40e_get_settings_link_down(struct i40e_hw *hw,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400388 struct ethtool_cmd *ecmd,
389 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000390{
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400391 enum i40e_aq_capabilities_phy_type phy_types = hw->phy.phy_types;
Catherine Sullivane8278452015-02-06 08:52:08 +0000392
393 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400394 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000395 */
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400396 ecmd->supported = 0x0;
397 ecmd->advertising = 0x0;
398 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
399 ecmd->supported |= SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400400 SUPPORTED_1000baseT_Full;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400401 ecmd->advertising |= ADVERTISED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400402 ADVERTISED_1000baseT_Full;
403 if (pf->hw.mac.type == I40E_MAC_X722) {
404 ecmd->supported |= SUPPORTED_100baseT_Full;
405 ecmd->advertising |= ADVERTISED_100baseT_Full;
406 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000407 }
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400408 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
409 phy_types & I40E_CAP_PHY_TYPE_XFI ||
410 phy_types & I40E_CAP_PHY_TYPE_SFI ||
411 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
412 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
413 ecmd->supported |= SUPPORTED_10000baseT_Full;
414 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
415 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
416 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
417 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
418 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
419 ecmd->supported |= SUPPORTED_Autoneg |
420 SUPPORTED_10000baseT_Full;
421 ecmd->advertising |= ADVERTISED_Autoneg |
422 ADVERTISED_10000baseT_Full;
423 }
424 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
425 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
426 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
427 ecmd->supported |= SUPPORTED_40000baseCR4_Full;
428 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
429 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
430 ecmd->supported |= SUPPORTED_Autoneg |
431 SUPPORTED_40000baseCR4_Full;
432 ecmd->advertising |= ADVERTISED_Autoneg |
433 ADVERTISED_40000baseCR4_Full;
434 }
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400435 if ((phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) &&
436 !(phy_types & I40E_CAP_PHY_TYPE_1000BASE_T)) {
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400437 ecmd->supported |= SUPPORTED_Autoneg |
438 SUPPORTED_100baseT_Full;
439 ecmd->advertising |= ADVERTISED_Autoneg |
440 ADVERTISED_100baseT_Full;
441 }
442 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
443 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
444 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
445 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
446 ecmd->supported |= SUPPORTED_Autoneg |
447 SUPPORTED_1000baseT_Full;
448 ecmd->advertising |= ADVERTISED_Autoneg |
449 ADVERTISED_1000baseT_Full;
450 }
451 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
452 ecmd->supported |= SUPPORTED_40000baseSR4_Full;
453 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
454 ecmd->supported |= SUPPORTED_40000baseLR4_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000455
456 /* With no link speed and duplex are unknown */
457 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
458 ecmd->duplex = DUPLEX_UNKNOWN;
459}
460
461/**
462 * i40e_get_settings - Get Link Speed and Duplex settings
463 * @netdev: network interface device structure
464 * @ecmd: ethtool command
465 *
466 * Reports speed/duplex settings based on media_type
467 **/
468static int i40e_get_settings(struct net_device *netdev,
469 struct ethtool_cmd *ecmd)
470{
471 struct i40e_netdev_priv *np = netdev_priv(netdev);
472 struct i40e_pf *pf = np->vsi->back;
473 struct i40e_hw *hw = &pf->hw;
474 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
475 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
476
477 if (link_up)
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400478 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000479 else
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400480 i40e_get_settings_link_down(hw, ecmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000481
482 /* Now set the settings that don't rely on link being up/down */
483
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400484 /* For backplane, supported and advertised are only reliant on the
485 * phy types the NVM specifies are supported.
486 */
487 if (hw->device_id == I40E_DEV_ID_KX_B ||
488 hw->device_id == I40E_DEV_ID_KX_C ||
489 hw->device_id == I40E_DEV_ID_20G_KR2 ||
490 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
491 ecmd->supported = SUPPORTED_Autoneg;
492 ecmd->advertising = ADVERTISED_Autoneg;
493 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
494 ecmd->supported |= SUPPORTED_40000baseKR4_Full;
495 ecmd->advertising |= ADVERTISED_40000baseKR4_Full;
496 }
497 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
498 ecmd->supported |= SUPPORTED_20000baseKR2_Full;
499 ecmd->advertising |= ADVERTISED_20000baseKR2_Full;
500 }
501 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
502 ecmd->supported |= SUPPORTED_10000baseKR_Full;
503 ecmd->advertising |= ADVERTISED_10000baseKR_Full;
504 }
505 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
506 ecmd->supported |= SUPPORTED_10000baseKX4_Full;
507 ecmd->advertising |= ADVERTISED_10000baseKX4_Full;
508 }
509 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
510 ecmd->supported |= SUPPORTED_1000baseKX_Full;
511 ecmd->advertising |= ADVERTISED_1000baseKX_Full;
512 }
513 }
514
Catherine Sullivane8278452015-02-06 08:52:08 +0000515 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000516 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
517 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000518
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000519 switch (hw->phy.media_type) {
520 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000521 ecmd->supported |= SUPPORTED_Autoneg |
522 SUPPORTED_Backplane;
523 ecmd->advertising |= ADVERTISED_Autoneg |
524 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000525 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000526 break;
527 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000528 ecmd->supported |= SUPPORTED_TP;
529 ecmd->advertising |= ADVERTISED_TP;
530 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000531 break;
532 case I40E_MEDIA_TYPE_DA:
533 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000534 ecmd->supported |= SUPPORTED_FIBRE;
535 ecmd->advertising |= ADVERTISED_FIBRE;
536 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000537 break;
538 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000539 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000540 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000541 break;
542 case I40E_MEDIA_TYPE_UNKNOWN:
543 default:
544 ecmd->port = PORT_OTHER;
545 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000546 }
547
Catherine Sullivane8278452015-02-06 08:52:08 +0000548 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000549 ecmd->transceiver = XCVR_EXTERNAL;
550
Catherine Sullivane8278452015-02-06 08:52:08 +0000551 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000552 ecmd->supported |= SUPPORTED_Pause;
553
Catherine Sullivane8278452015-02-06 08:52:08 +0000554 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000555 case I40E_FC_FULL:
556 ecmd->advertising |= ADVERTISED_Pause;
557 break;
558 case I40E_FC_TX_PAUSE:
559 ecmd->advertising |= ADVERTISED_Asym_Pause;
560 break;
561 case I40E_FC_RX_PAUSE:
562 ecmd->advertising |= (ADVERTISED_Pause |
563 ADVERTISED_Asym_Pause);
564 break;
565 default:
566 ecmd->advertising &= ~(ADVERTISED_Pause |
567 ADVERTISED_Asym_Pause);
568 break;
569 }
570
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000571 return 0;
572}
573
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000574/**
575 * i40e_set_settings - Set Speed and Duplex
576 * @netdev: network interface device structure
577 * @ecmd: ethtool command
578 *
579 * Set speed/duplex per media_types advertised/forced
580 **/
581static int i40e_set_settings(struct net_device *netdev,
582 struct ethtool_cmd *ecmd)
583{
584 struct i40e_netdev_priv *np = netdev_priv(netdev);
585 struct i40e_aq_get_phy_abilities_resp abilities;
586 struct i40e_aq_set_phy_config config;
587 struct i40e_pf *pf = np->vsi->back;
588 struct i40e_vsi *vsi = np->vsi;
589 struct i40e_hw *hw = &pf->hw;
590 struct ethtool_cmd safe_ecmd;
591 i40e_status status = 0;
592 bool change = false;
593 int err = 0;
594 u8 autoneg;
595 u32 advertise;
596
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000597 /* Changing port settings is not supported if this isn't the
598 * port's controlling PF
599 */
600 if (hw->partition_id != 1) {
601 i40e_partition_setting_complaint(pf);
602 return -EOPNOTSUPP;
603 }
604
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000605 if (vsi != pf->vsi[pf->lan_vsi])
606 return -EOPNOTSUPP;
607
608 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
609 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000610 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
611 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000612 return -EOPNOTSUPP;
613
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400614 if (hw->device_id == I40E_DEV_ID_KX_B ||
615 hw->device_id == I40E_DEV_ID_KX_C ||
616 hw->device_id == I40E_DEV_ID_20G_KR2 ||
617 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
618 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
619 return -EOPNOTSUPP;
620 }
621
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000622 /* get our own copy of the bits to check against */
623 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
624 i40e_get_settings(netdev, &safe_ecmd);
625
626 /* save autoneg and speed out of ecmd */
627 autoneg = ecmd->autoneg;
628 advertise = ecmd->advertising;
629
630 /* set autoneg and speed back to what they currently are */
631 ecmd->autoneg = safe_ecmd.autoneg;
632 ecmd->advertising = safe_ecmd.advertising;
633
634 ecmd->cmd = safe_ecmd.cmd;
635 /* If ecmd and safe_ecmd are not the same now, then they are
636 * trying to set something that we do not support
637 */
638 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
639 return -EOPNOTSUPP;
640
641 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
642 usleep_range(1000, 2000);
643
644 /* Get the current phy config */
645 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
646 NULL);
647 if (status)
648 return -EAGAIN;
649
Catherine Sullivan124ed152014-07-12 07:28:12 +0000650 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000651 * set below
652 */
653 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000654 config.abilities = abilities.abilities;
655
656 /* Check autoneg */
657 if (autoneg == AUTONEG_ENABLE) {
658 /* If autoneg is not supported, return error */
659 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
660 netdev_info(netdev, "Autoneg not supported on this phy\n");
661 return -EINVAL;
662 }
663 /* If autoneg was not already enabled */
664 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
665 config.abilities = abilities.abilities |
666 I40E_AQ_PHY_ENABLE_AN;
667 change = true;
668 }
669 } else {
670 /* If autoneg is supported 10GBASE_T is the only phy that
671 * can disable it, so otherwise return error
672 */
673 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
674 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
675 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
676 return -EINVAL;
677 }
678 /* If autoneg is currently enabled */
679 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000680 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000681 ~I40E_AQ_PHY_ENABLE_AN;
682 change = true;
683 }
684 }
685
686 if (advertise & ~safe_ecmd.supported)
687 return -EINVAL;
688
689 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000690 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000691 if (advertise & ADVERTISED_1000baseT_Full ||
692 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000693 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000694 if (advertise & ADVERTISED_10000baseT_Full ||
695 advertise & ADVERTISED_10000baseKX4_Full ||
696 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000697 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700698 if (advertise & ADVERTISED_20000baseKR2_Full)
699 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000700 if (advertise & ADVERTISED_40000baseKR4_Full ||
701 advertise & ADVERTISED_40000baseCR4_Full ||
702 advertise & ADVERTISED_40000baseSR4_Full ||
703 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000704 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000705
Catherine Sullivan0002e112015-08-26 15:14:16 -0400706 /* If speed didn't get set, set it to what it currently is.
707 * This is needed because if advertise is 0 (as it is when autoneg
708 * is disabled) then speed won't get set.
709 */
710 if (!config.link_speed)
711 config.link_speed = abilities.link_speed;
712
Catherine Sullivan124ed152014-07-12 07:28:12 +0000713 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000714 /* copy over the rest of the abilities */
715 config.phy_type = abilities.phy_type;
716 config.eee_capability = abilities.eee_capability;
717 config.eeer = abilities.eeer_val;
718 config.low_power_ctrl = abilities.d3_lpan;
719
Catherine Sullivane8278452015-02-06 08:52:08 +0000720 /* save the requested speeds */
721 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000722 /* set link and auto negotiation so changes take effect */
723 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
724 /* If link is up put link down */
725 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
726 /* Tell the OS link is going down, the link will go
727 * back up when fw says it is ready asynchronously
728 */
Matt Jaredc156f852015-08-27 11:42:39 -0400729 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000730 netif_carrier_off(netdev);
731 netif_tx_stop_all_queues(netdev);
732 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000733
734 /* make the aq call */
735 status = i40e_aq_set_phy_config(hw, &config, NULL);
736 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400737 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
738 i40e_stat_str(hw, status),
739 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000740 return -EAGAIN;
741 }
742
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400743 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000744 if (status)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400745 netdev_info(netdev, "Updating link info failed with err %s aq_err %s\n",
746 i40e_stat_str(hw, status),
747 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000748
749 } else {
750 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
751 }
752
753 return err;
754}
755
Jesse Brandeburga6599722014-06-04 08:45:25 +0000756static int i40e_nway_reset(struct net_device *netdev)
757{
758 /* restart autonegotiation */
759 struct i40e_netdev_priv *np = netdev_priv(netdev);
760 struct i40e_pf *pf = np->vsi->back;
761 struct i40e_hw *hw = &pf->hw;
762 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
763 i40e_status ret = 0;
764
765 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
766 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400767 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
768 i40e_stat_str(hw, ret),
769 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000770 return -EIO;
771 }
772
773 return 0;
774}
775
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000776/**
777 * i40e_get_pauseparam - Get Flow Control status
778 * Return tx/rx-pause status
779 **/
780static void i40e_get_pauseparam(struct net_device *netdev,
781 struct ethtool_pauseparam *pause)
782{
783 struct i40e_netdev_priv *np = netdev_priv(netdev);
784 struct i40e_pf *pf = np->vsi->back;
785 struct i40e_hw *hw = &pf->hw;
786 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000787 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000788
789 pause->autoneg =
790 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
791 AUTONEG_ENABLE : AUTONEG_DISABLE);
792
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000793 /* PFC enabled so report LFC as off */
794 if (dcbx_cfg->pfc.pfcenable) {
795 pause->rx_pause = 0;
796 pause->tx_pause = 0;
797 return;
798 }
799
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000800 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000801 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000802 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000803 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000804 } else if (hw->fc.current_mode == I40E_FC_FULL) {
805 pause->rx_pause = 1;
806 pause->tx_pause = 1;
807 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000808}
809
Catherine Sullivan2becc352014-06-04 08:45:27 +0000810/**
811 * i40e_set_pauseparam - Set Flow Control parameter
812 * @netdev: network interface device structure
813 * @pause: return tx/rx flow control status
814 **/
815static int i40e_set_pauseparam(struct net_device *netdev,
816 struct ethtool_pauseparam *pause)
817{
818 struct i40e_netdev_priv *np = netdev_priv(netdev);
819 struct i40e_pf *pf = np->vsi->back;
820 struct i40e_vsi *vsi = np->vsi;
821 struct i40e_hw *hw = &pf->hw;
822 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000823 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000824 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
825 i40e_status status;
826 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000827 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000828
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000829 /* Changing the port's flow control is not supported if this isn't the
830 * port's controlling PF
831 */
832 if (hw->partition_id != 1) {
833 i40e_partition_setting_complaint(pf);
834 return -EOPNOTSUPP;
835 }
836
Catherine Sullivan2becc352014-06-04 08:45:27 +0000837 if (vsi != pf->vsi[pf->lan_vsi])
838 return -EOPNOTSUPP;
839
840 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
841 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
842 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
843 return -EOPNOTSUPP;
844 }
845
846 /* If we have link and don't have autoneg */
847 if (!test_bit(__I40E_DOWN, &pf->state) &&
848 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
849 /* Send message that it might not necessarily work*/
850 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
851 }
852
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000853 if (dcbx_cfg->pfc.pfcenable) {
854 netdev_info(netdev,
855 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000856 return -EOPNOTSUPP;
857 }
858
859 if (pause->rx_pause && pause->tx_pause)
860 hw->fc.requested_mode = I40E_FC_FULL;
861 else if (pause->rx_pause && !pause->tx_pause)
862 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
863 else if (!pause->rx_pause && pause->tx_pause)
864 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
865 else if (!pause->rx_pause && !pause->tx_pause)
866 hw->fc.requested_mode = I40E_FC_NONE;
867 else
868 return -EINVAL;
869
Catherine Sullivan94128512014-07-12 07:28:16 +0000870 /* Tell the OS link is going down, the link will go back up when fw
871 * says it is ready asynchronously
872 */
Matt Jaredc156f852015-08-27 11:42:39 -0400873 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000874 netif_carrier_off(netdev);
875 netif_tx_stop_all_queues(netdev);
876
Catherine Sullivan2becc352014-06-04 08:45:27 +0000877 /* Set the fc mode and only restart an if link is up*/
878 status = i40e_set_fc(hw, &aq_failures, link_up);
879
880 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400881 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
882 i40e_stat_str(hw, status),
883 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000884 err = -EAGAIN;
885 }
886 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400887 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
888 i40e_stat_str(hw, status),
889 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000890 err = -EAGAIN;
891 }
892 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400893 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
894 i40e_stat_str(hw, status),
895 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000896 err = -EAGAIN;
897 }
898
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000899 if (!test_bit(__I40E_DOWN, &pf->state)) {
900 /* Give it a little more time to try to come back */
901 msleep(75);
902 if (!test_bit(__I40E_DOWN, &pf->state))
903 return i40e_nway_reset(netdev);
904 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000905
906 return err;
907}
908
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000909static u32 i40e_get_msglevel(struct net_device *netdev)
910{
911 struct i40e_netdev_priv *np = netdev_priv(netdev);
912 struct i40e_pf *pf = np->vsi->back;
913
914 return pf->msg_enable;
915}
916
917static void i40e_set_msglevel(struct net_device *netdev, u32 data)
918{
919 struct i40e_netdev_priv *np = netdev_priv(netdev);
920 struct i40e_pf *pf = np->vsi->back;
921
922 if (I40E_DEBUG_USER & data)
923 pf->hw.debug_mask = data;
924 pf->msg_enable = data;
925}
926
927static int i40e_get_regs_len(struct net_device *netdev)
928{
929 int reg_count = 0;
930 int i;
931
932 for (i = 0; i40e_reg_list[i].offset != 0; i++)
933 reg_count += i40e_reg_list[i].elements;
934
935 return reg_count * sizeof(u32);
936}
937
938static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
939 void *p)
940{
941 struct i40e_netdev_priv *np = netdev_priv(netdev);
942 struct i40e_pf *pf = np->vsi->back;
943 struct i40e_hw *hw = &pf->hw;
944 u32 *reg_buf = p;
945 int i, j, ri;
946 u32 reg;
947
948 /* Tell ethtool which driver-version-specific regs output we have.
949 *
950 * At some point, if we have ethtool doing special formatting of
951 * this data, it will rely on this version number to know how to
952 * interpret things. Hence, this needs to be updated if/when the
953 * diags register table is changed.
954 */
955 regs->version = 1;
956
957 /* loop through the diags reg table for what to print */
958 ri = 0;
959 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
960 for (j = 0; j < i40e_reg_list[i].elements; j++) {
961 reg = i40e_reg_list[i].offset
962 + (j * i40e_reg_list[i].stride);
963 reg_buf[ri++] = rd32(hw, reg);
964 }
965 }
966
967}
968
969static int i40e_get_eeprom(struct net_device *netdev,
970 struct ethtool_eeprom *eeprom, u8 *bytes)
971{
972 struct i40e_netdev_priv *np = netdev_priv(netdev);
973 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000974 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000975 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000976 u8 *eeprom_buff;
977 u16 i, sectors;
978 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000979 u32 magic;
980
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000981#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000982 if (eeprom->len == 0)
983 return -EINVAL;
984
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000985 /* check for NVMUpdate access method */
986 magic = hw->vendor_id | (hw->device_id << 16);
987 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000988 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000989 int errno;
990
991 /* make sure it is the right magic for NVMUpdate */
992 if ((eeprom->magic >> 16) != hw->device_id)
993 return -EINVAL;
994
Shannon Nelsonc150a502014-11-13 08:23:13 +0000995 cmd = (struct i40e_nvm_access *)eeprom;
996 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson3c5c4202015-09-28 14:12:32 -0400997 if (ret_val && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000998 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000999 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1000 ret_val, hw->aq.asq_last_status, errno,
1001 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1002 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001003
1004 return errno;
1005 }
1006
1007 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001008 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1009
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001010 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001011 if (!eeprom_buff)
1012 return -ENOMEM;
1013
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001014 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1015 if (ret_val) {
1016 dev_info(&pf->pdev->dev,
1017 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1018 ret_val, hw->aq.asq_last_status);
1019 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001020 }
1021
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001022 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1023 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1024 len = I40E_NVM_SECTOR_SIZE;
1025 last = false;
1026 for (i = 0; i < sectors; i++) {
1027 if (i == (sectors - 1)) {
1028 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1029 last = true;
1030 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001031 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1032 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001033 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001034 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001035 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001036 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001037 "read NVM failed, invalid offset 0x%x\n",
1038 offset);
1039 break;
1040 } else if (ret_val &&
1041 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1042 dev_info(&pf->pdev->dev,
1043 "read NVM failed, access, offset 0x%x\n",
1044 offset);
1045 break;
1046 } else if (ret_val) {
1047 dev_info(&pf->pdev->dev,
1048 "read NVM failed offset %d err=%d status=0x%x\n",
1049 offset, ret_val, hw->aq.asq_last_status);
1050 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001051 }
1052 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001053
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001054 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001055 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001056free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001057 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001058 return ret_val;
1059}
1060
1061static int i40e_get_eeprom_len(struct net_device *netdev)
1062{
1063 struct i40e_netdev_priv *np = netdev_priv(netdev);
1064 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001065 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001066
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001067 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1068 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1069 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1070 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001071 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001072 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001073}
1074
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001075static int i40e_set_eeprom(struct net_device *netdev,
1076 struct ethtool_eeprom *eeprom, u8 *bytes)
1077{
1078 struct i40e_netdev_priv *np = netdev_priv(netdev);
1079 struct i40e_hw *hw = &np->vsi->back->hw;
1080 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001081 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001082 int ret_val = 0;
1083 int errno;
1084 u32 magic;
1085
1086 /* normal ethtool set_eeprom is not supported */
1087 magic = hw->vendor_id | (hw->device_id << 16);
1088 if (eeprom->magic == magic)
1089 return -EOPNOTSUPP;
1090
1091 /* check for NVMUpdate access method */
1092 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1093 return -EINVAL;
1094
1095 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1096 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1097 return -EBUSY;
1098
Shannon Nelsonc150a502014-11-13 08:23:13 +00001099 cmd = (struct i40e_nvm_access *)eeprom;
1100 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson3c5c4202015-09-28 14:12:32 -04001101 if (ret_val && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001102 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001103 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1104 ret_val, hw->aq.asq_last_status, errno,
1105 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1106 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001107
1108 return errno;
1109}
1110
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001111static void i40e_get_drvinfo(struct net_device *netdev,
1112 struct ethtool_drvinfo *drvinfo)
1113{
1114 struct i40e_netdev_priv *np = netdev_priv(netdev);
1115 struct i40e_vsi *vsi = np->vsi;
1116 struct i40e_pf *pf = vsi->back;
1117
1118 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1119 strlcpy(drvinfo->version, i40e_driver_version_str,
1120 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001121 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001122 sizeof(drvinfo->fw_version));
1123 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1124 sizeof(drvinfo->bus_info));
1125}
1126
1127static void i40e_get_ringparam(struct net_device *netdev,
1128 struct ethtool_ringparam *ring)
1129{
1130 struct i40e_netdev_priv *np = netdev_priv(netdev);
1131 struct i40e_pf *pf = np->vsi->back;
1132 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1133
1134 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1135 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1136 ring->rx_mini_max_pending = 0;
1137 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001138 ring->rx_pending = vsi->rx_rings[0]->count;
1139 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001140 ring->rx_mini_pending = 0;
1141 ring->rx_jumbo_pending = 0;
1142}
1143
1144static int i40e_set_ringparam(struct net_device *netdev,
1145 struct ethtool_ringparam *ring)
1146{
1147 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1148 struct i40e_netdev_priv *np = netdev_priv(netdev);
1149 struct i40e_vsi *vsi = np->vsi;
1150 struct i40e_pf *pf = vsi->back;
1151 u32 new_rx_count, new_tx_count;
1152 int i, err = 0;
1153
1154 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1155 return -EINVAL;
1156
Shannon Nelson1fa18372013-11-20 10:03:08 +00001157 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1158 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1159 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1160 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1161 netdev_info(netdev,
1162 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1163 ring->tx_pending, ring->rx_pending,
1164 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1165 return -EINVAL;
1166 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001167
Shannon Nelson1fa18372013-11-20 10:03:08 +00001168 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1169 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001170
1171 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001172 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1173 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001174 return 0;
1175
1176 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1177 usleep_range(1000, 2000);
1178
1179 if (!netif_running(vsi->netdev)) {
1180 /* simple case - set for the next time the netdev is started */
1181 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001182 vsi->tx_rings[i]->count = new_tx_count;
1183 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001184 }
1185 goto done;
1186 }
1187
1188 /* We can't just free everything and then setup again,
1189 * because the ISRs in MSI-X mode get passed pointers
1190 * to the Tx and Rx ring structs.
1191 */
1192
1193 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001194 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001195 netdev_info(netdev,
1196 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001197 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001198 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1199 sizeof(struct i40e_ring), GFP_KERNEL);
1200 if (!tx_rings) {
1201 err = -ENOMEM;
1202 goto done;
1203 }
1204
1205 for (i = 0; i < vsi->num_queue_pairs; i++) {
1206 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001207 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001208 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001209 /* the desc and bi pointers will be reallocated in the
1210 * setup call
1211 */
1212 tx_rings[i].desc = NULL;
1213 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001214 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1215 if (err) {
1216 while (i) {
1217 i--;
1218 i40e_free_tx_resources(&tx_rings[i]);
1219 }
1220 kfree(tx_rings);
1221 tx_rings = NULL;
1222
1223 goto done;
1224 }
1225 }
1226 }
1227
1228 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001229 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001230 netdev_info(netdev,
1231 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001232 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001233 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1234 sizeof(struct i40e_ring), GFP_KERNEL);
1235 if (!rx_rings) {
1236 err = -ENOMEM;
1237 goto free_tx;
1238 }
1239
1240 for (i = 0; i < vsi->num_queue_pairs; i++) {
1241 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001242 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001243 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001244 /* the desc and bi pointers will be reallocated in the
1245 * setup call
1246 */
1247 rx_rings[i].desc = NULL;
1248 rx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001249 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1250 if (err) {
1251 while (i) {
1252 i--;
1253 i40e_free_rx_resources(&rx_rings[i]);
1254 }
1255 kfree(rx_rings);
1256 rx_rings = NULL;
1257
1258 goto free_tx;
1259 }
1260 }
1261 }
1262
1263 /* Bring interface down, copy in the new ring info,
1264 * then restore the interface
1265 */
1266 i40e_down(vsi);
1267
1268 if (tx_rings) {
1269 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001270 i40e_free_tx_resources(vsi->tx_rings[i]);
1271 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001272 }
1273 kfree(tx_rings);
1274 tx_rings = NULL;
1275 }
1276
1277 if (rx_rings) {
1278 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001279 i40e_free_rx_resources(vsi->rx_rings[i]);
1280 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001281 }
1282 kfree(rx_rings);
1283 rx_rings = NULL;
1284 }
1285
1286 i40e_up(vsi);
1287
1288free_tx:
1289 /* error cleanup if the Rx allocations failed after getting Tx */
1290 if (tx_rings) {
1291 for (i = 0; i < vsi->num_queue_pairs; i++)
1292 i40e_free_tx_resources(&tx_rings[i]);
1293 kfree(tx_rings);
1294 tx_rings = NULL;
1295 }
1296
1297done:
1298 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1299
1300 return err;
1301}
1302
1303static int i40e_get_sset_count(struct net_device *netdev, int sset)
1304{
1305 struct i40e_netdev_priv *np = netdev_priv(netdev);
1306 struct i40e_vsi *vsi = np->vsi;
1307 struct i40e_pf *pf = vsi->back;
1308
1309 switch (sset) {
1310 case ETH_SS_TEST:
1311 return I40E_TEST_LEN;
1312 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001313 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001314 int len = I40E_PF_STATS_LEN(netdev);
1315
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001316 if ((pf->lan_veb != I40E_NO_VEB) &&
1317 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001318 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001319 return len;
1320 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001321 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001322 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001323 case ETH_SS_PRIV_FLAGS:
1324 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001325 default:
1326 return -EOPNOTSUPP;
1327 }
1328}
1329
1330static void i40e_get_ethtool_stats(struct net_device *netdev,
1331 struct ethtool_stats *stats, u64 *data)
1332{
1333 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001334 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001335 struct i40e_vsi *vsi = np->vsi;
1336 struct i40e_pf *pf = vsi->back;
1337 int i = 0;
1338 char *p;
1339 int j;
1340 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001341 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001342
1343 i40e_update_stats(vsi);
1344
1345 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1346 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1347 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1348 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1349 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001350 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1351 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1352 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1353 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1354 }
Vasu Dev38e00432014-08-01 13:27:03 -07001355#ifdef I40E_FCOE
1356 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1357 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1358 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1359 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1360 }
1361#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001362 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001363 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001364 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001365
1366 if (!tx_ring)
1367 continue;
1368
1369 /* process Tx ring statistics */
1370 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001371 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001372 data[i] = tx_ring->stats.packets;
1373 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001374 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001375 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001376
1377 /* Rx ring is the 2nd half of the queue pair */
1378 rx_ring = &tx_ring[1];
1379 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001380 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001381 data[i] = rx_ring->stats.packets;
1382 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001383 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001384 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001385 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001386 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001387 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001388 return;
1389
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001390 if ((pf->lan_veb != I40E_NO_VEB) &&
1391 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001392 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001393
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001394 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1395 p = (char *)veb;
1396 p += i40e_gstrings_veb_stats[j].stat_offset;
1397 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1398 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001399 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001400 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001401 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1402 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1403 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1404 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1405 }
1406 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1407 data[i++] = pf->stats.priority_xon_tx[j];
1408 data[i++] = pf->stats.priority_xoff_tx[j];
1409 }
1410 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1411 data[i++] = pf->stats.priority_xon_rx[j];
1412 data[i++] = pf->stats.priority_xoff_rx[j];
1413 }
1414 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1415 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001416}
1417
1418static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1419 u8 *data)
1420{
1421 struct i40e_netdev_priv *np = netdev_priv(netdev);
1422 struct i40e_vsi *vsi = np->vsi;
1423 struct i40e_pf *pf = vsi->back;
1424 char *p = (char *)data;
1425 int i;
1426
1427 switch (stringset) {
1428 case ETH_SS_TEST:
1429 for (i = 0; i < I40E_TEST_LEN; i++) {
1430 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1431 data += ETH_GSTRING_LEN;
1432 }
1433 break;
1434 case ETH_SS_STATS:
1435 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1436 snprintf(p, ETH_GSTRING_LEN, "%s",
1437 i40e_gstrings_net_stats[i].stat_string);
1438 p += ETH_GSTRING_LEN;
1439 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001440 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1441 snprintf(p, ETH_GSTRING_LEN, "%s",
1442 i40e_gstrings_misc_stats[i].stat_string);
1443 p += ETH_GSTRING_LEN;
1444 }
Vasu Dev38e00432014-08-01 13:27:03 -07001445#ifdef I40E_FCOE
1446 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1447 snprintf(p, ETH_GSTRING_LEN, "%s",
1448 i40e_gstrings_fcoe_stats[i].stat_string);
1449 p += ETH_GSTRING_LEN;
1450 }
1451#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001452 for (i = 0; i < vsi->num_queue_pairs; i++) {
1453 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1454 p += ETH_GSTRING_LEN;
1455 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1456 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001457 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1458 p += ETH_GSTRING_LEN;
1459 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1460 p += ETH_GSTRING_LEN;
1461 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001462 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001463 return;
1464
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001465 if ((pf->lan_veb != I40E_NO_VEB) &&
1466 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001467 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1468 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1469 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001470 p += ETH_GSTRING_LEN;
1471 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001472 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1473 snprintf(p, ETH_GSTRING_LEN,
1474 "veb.tc_%u_tx_packets", i);
1475 p += ETH_GSTRING_LEN;
1476 snprintf(p, ETH_GSTRING_LEN,
1477 "veb.tc_%u_tx_bytes", i);
1478 p += ETH_GSTRING_LEN;
1479 snprintf(p, ETH_GSTRING_LEN,
1480 "veb.tc_%u_rx_packets", i);
1481 p += ETH_GSTRING_LEN;
1482 snprintf(p, ETH_GSTRING_LEN,
1483 "veb.tc_%u_rx_bytes", i);
1484 p += ETH_GSTRING_LEN;
1485 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001486 }
1487 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1488 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1489 i40e_gstrings_stats[i].stat_string);
1490 p += ETH_GSTRING_LEN;
1491 }
1492 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1493 snprintf(p, ETH_GSTRING_LEN,
1494 "port.tx_priority_%u_xon", i);
1495 p += ETH_GSTRING_LEN;
1496 snprintf(p, ETH_GSTRING_LEN,
1497 "port.tx_priority_%u_xoff", i);
1498 p += ETH_GSTRING_LEN;
1499 }
1500 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1501 snprintf(p, ETH_GSTRING_LEN,
1502 "port.rx_priority_%u_xon", i);
1503 p += ETH_GSTRING_LEN;
1504 snprintf(p, ETH_GSTRING_LEN,
1505 "port.rx_priority_%u_xoff", i);
1506 p += ETH_GSTRING_LEN;
1507 }
1508 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1509 snprintf(p, ETH_GSTRING_LEN,
1510 "port.rx_priority_%u_xon_2_xoff", i);
1511 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001512 }
1513 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1514 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001515 case ETH_SS_PRIV_FLAGS:
1516 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1517 memcpy(data, i40e_priv_flags_strings[i],
1518 ETH_GSTRING_LEN);
1519 data += ETH_GSTRING_LEN;
1520 }
1521 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001522 default:
1523 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001524 }
1525}
1526
1527static int i40e_get_ts_info(struct net_device *dev,
1528 struct ethtool_ts_info *info)
1529{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001530 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1531
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001532 /* only report HW timestamping if PTP is enabled */
1533 if (!(pf->flags & I40E_FLAG_PTP))
1534 return ethtool_op_get_ts_info(dev, info);
1535
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001536 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1537 SOF_TIMESTAMPING_RX_SOFTWARE |
1538 SOF_TIMESTAMPING_SOFTWARE |
1539 SOF_TIMESTAMPING_TX_HARDWARE |
1540 SOF_TIMESTAMPING_RX_HARDWARE |
1541 SOF_TIMESTAMPING_RAW_HARDWARE;
1542
1543 if (pf->ptp_clock)
1544 info->phc_index = ptp_clock_index(pf->ptp_clock);
1545 else
1546 info->phc_index = -1;
1547
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001548 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001549
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001550 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1551 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1552 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001553
1554 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001555}
1556
Shannon Nelson7b086392013-11-20 10:02:59 +00001557static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001558{
Shannon Nelson7b086392013-11-20 10:02:59 +00001559 struct i40e_netdev_priv *np = netdev_priv(netdev);
1560 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001561 i40e_status status;
1562 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001563
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001564 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001565 status = i40e_get_link_status(&pf->hw, &link_up);
1566 if (status) {
1567 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1568 *data = 1;
1569 return *data;
1570 }
1571
1572 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001573 *data = 0;
1574 else
1575 *data = 1;
1576
1577 return *data;
1578}
1579
Shannon Nelson7b086392013-11-20 10:02:59 +00001580static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001581{
Shannon Nelson7b086392013-11-20 10:02:59 +00001582 struct i40e_netdev_priv *np = netdev_priv(netdev);
1583 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001584
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001585 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001586 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001587
Shannon Nelson7b086392013-11-20 10:02:59 +00001588 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001589}
1590
Shannon Nelson7b086392013-11-20 10:02:59 +00001591static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001592{
Shannon Nelson7b086392013-11-20 10:02:59 +00001593 struct i40e_netdev_priv *np = netdev_priv(netdev);
1594 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001595
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001596 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001597 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001598
Shannon Nelson4443ec92014-11-13 08:23:12 +00001599 /* forcebly clear the NVM Update state machine */
1600 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1601
Shannon Nelson7b086392013-11-20 10:02:59 +00001602 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001603}
1604
Shannon Nelson7b086392013-11-20 10:02:59 +00001605static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001606{
Shannon Nelson7b086392013-11-20 10:02:59 +00001607 struct i40e_netdev_priv *np = netdev_priv(netdev);
1608 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001609 u16 swc_old = pf->sw_int_count;
1610
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001611 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001612 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1613 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001614 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1615 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1616 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1617 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001618 usleep_range(1000, 2000);
1619 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001620
1621 return *data;
1622}
1623
Shannon Nelson7b086392013-11-20 10:02:59 +00001624static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001625{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001626 struct i40e_netdev_priv *np = netdev_priv(netdev);
1627 struct i40e_pf *pf = np->vsi->back;
1628
1629 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001630 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001631
1632 return *data;
1633}
1634
Greg Rosee17bc412015-04-16 20:05:59 -04001635static inline bool i40e_active_vfs(struct i40e_pf *pf)
1636{
1637 struct i40e_vf *vfs = pf->vf;
1638 int i;
1639
1640 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001641 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001642 return true;
1643 return false;
1644}
1645
Greg Rose510efb22015-07-10 19:36:01 -04001646static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1647{
1648 struct i40e_vsi **vsi = pf->vsi;
1649 int i;
1650
1651 for (i = 0; i < pf->num_alloc_vsi; i++) {
1652 if (!vsi[i])
1653 continue;
1654 if (vsi[i]->type == I40E_VSI_VMDQ2)
1655 return true;
1656 }
1657
1658 return false;
1659}
1660
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001661static void i40e_diag_test(struct net_device *netdev,
1662 struct ethtool_test *eth_test, u64 *data)
1663{
1664 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001665 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001666 struct i40e_pf *pf = np->vsi->back;
1667
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001668 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1669 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001670 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001671
Shannon Nelsonf551b432013-11-26 10:49:12 +00001672 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001673
Greg Rose510efb22015-07-10 19:36:01 -04001674 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001675 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001676 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001677 data[I40E_ETH_TEST_REG] = 1;
1678 data[I40E_ETH_TEST_EEPROM] = 1;
1679 data[I40E_ETH_TEST_INTR] = 1;
1680 data[I40E_ETH_TEST_LOOPBACK] = 1;
1681 data[I40E_ETH_TEST_LINK] = 1;
1682 eth_test->flags |= ETH_TEST_FL_FAILED;
1683 clear_bit(__I40E_TESTING, &pf->state);
1684 goto skip_ol_tests;
1685 }
1686
Greg Rose5b86c5c2015-02-26 16:14:35 +00001687 /* If the device is online then take it offline */
1688 if (if_running)
1689 /* indicate we're in test mode */
1690 dev_close(netdev);
1691 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001692 /* This reset does not affect link - if it is
1693 * changed to a type of reset that does affect
1694 * link then the following link test would have
1695 * to be moved to before the reset
1696 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001697 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001698
Shannon Nelson7b086392013-11-20 10:02:59 +00001699 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001700 eth_test->flags |= ETH_TEST_FL_FAILED;
1701
Shannon Nelson7b086392013-11-20 10:02:59 +00001702 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001703 eth_test->flags |= ETH_TEST_FL_FAILED;
1704
Shannon Nelson7b086392013-11-20 10:02:59 +00001705 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001706 eth_test->flags |= ETH_TEST_FL_FAILED;
1707
Shannon Nelson7b086392013-11-20 10:02:59 +00001708 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001709 eth_test->flags |= ETH_TEST_FL_FAILED;
1710
Shannon Nelsonf551b432013-11-26 10:49:12 +00001711 /* run reg test last, a reset is required after it */
1712 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1713 eth_test->flags |= ETH_TEST_FL_FAILED;
1714
1715 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001716 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001717
1718 if (if_running)
1719 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001720 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001721 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001722 netif_info(pf, drv, netdev, "online testing starting\n");
1723
Shannon Nelson7b086392013-11-20 10:02:59 +00001724 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001725 eth_test->flags |= ETH_TEST_FL_FAILED;
1726
1727 /* Offline only tests, not run in online; pass by default */
1728 data[I40E_ETH_TEST_REG] = 0;
1729 data[I40E_ETH_TEST_EEPROM] = 0;
1730 data[I40E_ETH_TEST_INTR] = 0;
1731 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001732 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001733
Greg Rosee17bc412015-04-16 20:05:59 -04001734skip_ol_tests:
1735
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001736 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001737}
1738
1739static void i40e_get_wol(struct net_device *netdev,
1740 struct ethtool_wolinfo *wol)
1741{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001742 struct i40e_netdev_priv *np = netdev_priv(netdev);
1743 struct i40e_pf *pf = np->vsi->back;
1744 struct i40e_hw *hw = &pf->hw;
1745 u16 wol_nvm_bits;
1746
1747 /* NVM bit on means WoL disabled for the port */
1748 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001749 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001750 wol->supported = 0;
1751 wol->wolopts = 0;
1752 } else {
1753 wol->supported = WAKE_MAGIC;
1754 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1755 }
1756}
1757
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001758/**
1759 * i40e_set_wol - set the WakeOnLAN configuration
1760 * @netdev: the netdev in question
1761 * @wol: the ethtool WoL setting data
1762 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001763static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1764{
1765 struct i40e_netdev_priv *np = netdev_priv(netdev);
1766 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001767 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001768 struct i40e_hw *hw = &pf->hw;
1769 u16 wol_nvm_bits;
1770
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001771 /* WoL not supported if this isn't the controlling PF on the port */
1772 if (hw->partition_id != 1) {
1773 i40e_partition_setting_complaint(pf);
1774 return -EOPNOTSUPP;
1775 }
1776
1777 if (vsi != pf->vsi[pf->lan_vsi])
1778 return -EOPNOTSUPP;
1779
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001780 /* NVM bit on means WoL disabled for the port */
1781 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001782 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001783 return -EOPNOTSUPP;
1784
1785 /* only magic packet is supported */
1786 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1787 return -EOPNOTSUPP;
1788
1789 /* is this a new value? */
1790 if (pf->wol_en != !!wol->wolopts) {
1791 pf->wol_en = !!wol->wolopts;
1792 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1793 }
1794
1795 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001796}
1797
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001798static int i40e_set_phys_id(struct net_device *netdev,
1799 enum ethtool_phys_id_state state)
1800{
1801 struct i40e_netdev_priv *np = netdev_priv(netdev);
1802 struct i40e_pf *pf = np->vsi->back;
1803 struct i40e_hw *hw = &pf->hw;
1804 int blink_freq = 2;
1805
1806 switch (state) {
1807 case ETHTOOL_ID_ACTIVE:
1808 pf->led_status = i40e_led_get(hw);
1809 return blink_freq;
1810 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001811 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001812 break;
1813 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001814 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001815 break;
1816 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001817 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001818 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001819 default:
1820 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001821 }
1822
1823 return 0;
1824}
1825
1826/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1827 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1828 * 125us (8000 interrupts per second) == ITR(62)
1829 */
1830
1831static int i40e_get_coalesce(struct net_device *netdev,
1832 struct ethtool_coalesce *ec)
1833{
1834 struct i40e_netdev_priv *np = netdev_priv(netdev);
1835 struct i40e_vsi *vsi = np->vsi;
1836
1837 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1838 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1839
1840 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001841 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001842
1843 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001844 ec->use_adaptive_tx_coalesce = 1;
1845
1846 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1847 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001848
1849 return 0;
1850}
1851
1852static int i40e_set_coalesce(struct net_device *netdev,
1853 struct ethtool_coalesce *ec)
1854{
1855 struct i40e_netdev_priv *np = netdev_priv(netdev);
1856 struct i40e_q_vector *q_vector;
1857 struct i40e_vsi *vsi = np->vsi;
1858 struct i40e_pf *pf = vsi->back;
1859 struct i40e_hw *hw = &pf->hw;
1860 u16 vector;
1861 int i;
1862
1863 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1864 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1865
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001866 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001867 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001868 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001869 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001870 } else if (ec->rx_coalesce_usecs == 0) {
1871 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001872 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001873 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 +00001874 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001875 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001876 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001877 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001878
Mitch Williams32f5f542014-04-04 04:43:10 +00001879 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001880 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001881 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001882 } else if (ec->tx_coalesce_usecs == 0) {
1883 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001884 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001885 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 +00001886 } else {
1887 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001888 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001889 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001890 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001891
1892 if (ec->use_adaptive_rx_coalesce)
1893 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1894 else
1895 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1896
1897 if (ec->use_adaptive_tx_coalesce)
1898 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1899 else
1900 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001901
Alexander Duyck493fb302013-09-28 07:01:44 +00001902 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1903 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001904 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1905 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1906 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1907 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1908 i40e_flush(hw);
1909 }
1910
1911 return 0;
1912}
1913
1914/**
1915 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1916 * @pf: pointer to the physical function struct
1917 * @cmd: ethtool rxnfc command
1918 *
1919 * Returns Success if the flow is supported, else Invalid Input.
1920 **/
1921static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1922{
1923 cmd->data = 0;
1924
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001925 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1926 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1927 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1928 return 0;
1929 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001930 /* Report default options for RSS on i40e */
1931 switch (cmd->flow_type) {
1932 case TCP_V4_FLOW:
1933 case UDP_V4_FLOW:
1934 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1935 /* fall through to add IP fields */
1936 case SCTP_V4_FLOW:
1937 case AH_ESP_V4_FLOW:
1938 case AH_V4_FLOW:
1939 case ESP_V4_FLOW:
1940 case IPV4_FLOW:
1941 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1942 break;
1943 case TCP_V6_FLOW:
1944 case UDP_V6_FLOW:
1945 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1946 /* fall through to add IP fields */
1947 case SCTP_V6_FLOW:
1948 case AH_ESP_V6_FLOW:
1949 case AH_V6_FLOW:
1950 case ESP_V6_FLOW:
1951 case IPV6_FLOW:
1952 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1953 break;
1954 default:
1955 return -EINVAL;
1956 }
1957
1958 return 0;
1959}
1960
1961/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001962 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1963 * @pf: Pointer to the physical function struct
1964 * @cmd: The command to get or set Rx flow classification rules
1965 * @rule_locs: Array of used rule locations
1966 *
1967 * This function populates both the total and actual rule count of
1968 * the ethtool flow classification command
1969 *
1970 * Returns 0 on success or -EMSGSIZE if entry not found
1971 **/
1972static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1973 struct ethtool_rxnfc *cmd,
1974 u32 *rule_locs)
1975{
1976 struct i40e_fdir_filter *rule;
1977 struct hlist_node *node2;
1978 int cnt = 0;
1979
1980 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001981 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001982
1983 hlist_for_each_entry_safe(rule, node2,
1984 &pf->fdir_filter_list, fdir_node) {
1985 if (cnt == cmd->rule_cnt)
1986 return -EMSGSIZE;
1987
1988 rule_locs[cnt] = rule->fd_id;
1989 cnt++;
1990 }
1991
1992 cmd->rule_cnt = cnt;
1993
1994 return 0;
1995}
1996
1997/**
1998 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1999 * @pf: Pointer to the physical function struct
2000 * @cmd: The command to get or set Rx flow classification rules
2001 *
2002 * This function looks up a filter based on the Rx flow classification
2003 * command and fills the flow spec info for it if found
2004 *
2005 * Returns 0 on success or -EINVAL if filter not found
2006 **/
2007static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2008 struct ethtool_rxnfc *cmd)
2009{
2010 struct ethtool_rx_flow_spec *fsp =
2011 (struct ethtool_rx_flow_spec *)&cmd->fs;
2012 struct i40e_fdir_filter *rule = NULL;
2013 struct hlist_node *node2;
2014
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002015 hlist_for_each_entry_safe(rule, node2,
2016 &pf->fdir_filter_list, fdir_node) {
2017 if (fsp->location <= rule->fd_id)
2018 break;
2019 }
2020
2021 if (!rule || fsp->location != rule->fd_id)
2022 return -EINVAL;
2023
2024 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002025 if (fsp->flow_type == IP_USER_FLOW) {
2026 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2027 fsp->h_u.usr_ip4_spec.proto = 0;
2028 fsp->m_u.usr_ip4_spec.proto = 0;
2029 }
2030
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002031 /* Reverse the src and dest notion, since the HW views them from
2032 * Tx perspective where as the user expects it from Rx filter view.
2033 */
2034 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2035 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2036 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2037 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002038
2039 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2040 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2041 else
2042 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002043
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002044 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2045 struct i40e_vsi *vsi;
2046
2047 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2048 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2049 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2050 fsp->m_ext.data[1] = htonl(0x1);
2051 }
2052 }
2053
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002054 return 0;
2055}
2056
2057/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002058 * i40e_get_rxnfc - command to get RX flow classification rules
2059 * @netdev: network interface device structure
2060 * @cmd: ethtool rxnfc command
2061 *
2062 * Returns Success if the command is supported.
2063 **/
2064static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2065 u32 *rule_locs)
2066{
2067 struct i40e_netdev_priv *np = netdev_priv(netdev);
2068 struct i40e_vsi *vsi = np->vsi;
2069 struct i40e_pf *pf = vsi->back;
2070 int ret = -EOPNOTSUPP;
2071
2072 switch (cmd->cmd) {
2073 case ETHTOOL_GRXRINGS:
2074 cmd->data = vsi->alloc_queue_pairs;
2075 ret = 0;
2076 break;
2077 case ETHTOOL_GRXFH:
2078 ret = i40e_get_rss_hash_opts(pf, cmd);
2079 break;
2080 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002081 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002082 /* report total rule count */
2083 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002084 ret = 0;
2085 break;
2086 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002087 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002088 break;
2089 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002090 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2091 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002092 default:
2093 break;
2094 }
2095
2096 return ret;
2097}
2098
2099/**
2100 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2101 * @pf: pointer to the physical function struct
2102 * @cmd: ethtool rxnfc command
2103 *
2104 * Returns Success if the flow input set is supported.
2105 **/
2106static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2107{
2108 struct i40e_hw *hw = &pf->hw;
2109 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2110 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2111
2112 /* RSS does not support anything other than hashing
2113 * to queues on src and dst IPs and ports
2114 */
2115 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2116 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2117 return -EINVAL;
2118
2119 /* We need at least the IP SRC and DEST fields for hashing */
2120 if (!(nfc->data & RXH_IP_SRC) ||
2121 !(nfc->data & RXH_IP_DST))
2122 return -EINVAL;
2123
2124 switch (nfc->flow_type) {
2125 case TCP_V4_FLOW:
2126 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2127 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002128 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002129 break;
2130 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002131 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002132 break;
2133 default:
2134 return -EINVAL;
2135 }
2136 break;
2137 case TCP_V6_FLOW:
2138 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2139 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002140 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002141 break;
2142 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002143 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002144 break;
2145 default:
2146 return -EINVAL;
2147 }
2148 break;
2149 case UDP_V4_FLOW:
2150 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2151 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002152 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2153 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002154 break;
2155 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002156 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2157 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002158 break;
2159 default:
2160 return -EINVAL;
2161 }
2162 break;
2163 case UDP_V6_FLOW:
2164 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2165 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002166 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2167 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002168 break;
2169 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002170 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2171 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002172 break;
2173 default:
2174 return -EINVAL;
2175 }
2176 break;
2177 case AH_ESP_V4_FLOW:
2178 case AH_V4_FLOW:
2179 case ESP_V4_FLOW:
2180 case SCTP_V4_FLOW:
2181 if ((nfc->data & RXH_L4_B_0_1) ||
2182 (nfc->data & RXH_L4_B_2_3))
2183 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002184 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002185 break;
2186 case AH_ESP_V6_FLOW:
2187 case AH_V6_FLOW:
2188 case ESP_V6_FLOW:
2189 case SCTP_V6_FLOW:
2190 if ((nfc->data & RXH_L4_B_0_1) ||
2191 (nfc->data & RXH_L4_B_2_3))
2192 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002193 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002194 break;
2195 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002196 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2197 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002198 break;
2199 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002200 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2201 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002202 break;
2203 default:
2204 return -EINVAL;
2205 }
2206
2207 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2208 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2209 i40e_flush(hw);
2210
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002211 /* Save setting for future output/update */
2212 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2213
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002214 return 0;
2215}
2216
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002217/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002218 * i40e_match_fdir_input_set - Match a new filter against an existing one
2219 * @rule: The filter already added
2220 * @input: The new filter to comapre against
2221 *
2222 * Returns true if the two input set match
2223 **/
2224static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2225 struct i40e_fdir_filter *input)
2226{
2227 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2228 (rule->src_ip[0] != input->src_ip[0]) ||
2229 (rule->dst_port != input->dst_port) ||
2230 (rule->src_port != input->src_port))
2231 return false;
2232 return true;
2233}
2234
2235/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002236 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2237 * @vsi: Pointer to the targeted VSI
2238 * @input: The filter to update or NULL to indicate deletion
2239 * @sw_idx: Software index to the filter
2240 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002241 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002242 * This function updates (or deletes) a Flow Director entry from
2243 * the hlist of the corresponding PF
2244 *
2245 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002246 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002247static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2248 struct i40e_fdir_filter *input,
2249 u16 sw_idx,
2250 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002251{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002252 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002253 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002254 struct hlist_node *node2;
2255 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002256
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002257 parent = NULL;
2258 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002259
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002260 hlist_for_each_entry_safe(rule, node2,
2261 &pf->fdir_filter_list, fdir_node) {
2262 /* hash found, or no matching entry */
2263 if (rule->fd_id >= sw_idx)
2264 break;
2265 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002266 }
2267
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002268 /* if there is an old rule occupying our place remove it */
2269 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002270 if (input && !i40e_match_fdir_input_set(rule, input))
2271 err = i40e_add_del_fdir(vsi, rule, false);
2272 else if (!input)
2273 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002274 hlist_del(&rule->fdir_node);
2275 kfree(rule);
2276 pf->fdir_pf_active_filters--;
2277 }
2278
2279 /* If no input this was a delete, err should be 0 if a rule was
2280 * successfully found and removed from the list else -EINVAL
2281 */
2282 if (!input)
2283 return err;
2284
2285 /* initialize node and set software index */
2286 INIT_HLIST_NODE(&input->fdir_node);
2287
2288 /* add filter to the list */
2289 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002290 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002291 else
2292 hlist_add_head(&input->fdir_node,
2293 &pf->fdir_filter_list);
2294
2295 /* update counts */
2296 pf->fdir_pf_active_filters++;
2297
2298 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002299}
2300
2301/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002302 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2303 * @vsi: Pointer to the targeted VSI
2304 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002305 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002306 * The function removes a Flow Director filter entry from the
2307 * hlist of the corresponding PF
2308 *
2309 * Returns 0 on success
2310 */
2311static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2312 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002313{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002314 struct ethtool_rx_flow_spec *fsp =
2315 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002316 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002317 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002318
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002319 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2320 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2321 return -EBUSY;
2322
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002323 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2324 return -EBUSY;
2325
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002326 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002327
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002328 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002329 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002330}
2331
2332/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002333 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002334 * @vsi: pointer to the targeted VSI
2335 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002336 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002337 * Add Flow Director filters for a specific flow spec based on their
2338 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002339 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002340static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2341 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002342{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002343 struct ethtool_rx_flow_spec *fsp;
2344 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002345 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002346 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002347 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002348
2349 if (!vsi)
2350 return -EINVAL;
2351
2352 pf = vsi->back;
2353
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002354 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2355 return -EOPNOTSUPP;
2356
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002357 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002358 return -ENOSPC;
2359
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002360 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2361 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2362 return -EBUSY;
2363
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002364 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2365 return -EBUSY;
2366
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002367 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2368
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002369 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2370 pf->hw.func_caps.fd_filters_guaranteed)) {
2371 return -EINVAL;
2372 }
2373
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002374 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2375 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002376 return -EINVAL;
2377
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002378 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002379
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002380 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002381 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002382
2383 input->fd_id = fsp->location;
2384
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002385 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2386 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2387 else
2388 input->dest_ctl =
2389 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2390
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002391 input->q_index = fsp->ring_cookie;
2392 input->flex_off = 0;
2393 input->pctype = 0;
2394 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002395 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002396 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002397 input->flow_type = fsp->flow_type;
2398 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002399
2400 /* Reverse the src and dest notion, since the HW expects them to be from
2401 * Tx perspective where as the input from user is from Rx filter view.
2402 */
2403 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2404 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2405 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2406 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002407
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002408 if (ntohl(fsp->m_ext.data[1])) {
2409 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2410 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2411 goto free_input;
2412 }
2413 vf_id = ntohl(fsp->h_ext.data[1]);
2414 /* Find vsi id from vf id and override dest vsi */
2415 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2416 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2417 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2418 goto free_input;
2419 }
2420 }
2421
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002422 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002423free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002424 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002425 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002426 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002427 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002428
2429 return ret;
2430}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002431
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002432/**
2433 * i40e_set_rxnfc - command to set RX flow classification rules
2434 * @netdev: network interface device structure
2435 * @cmd: ethtool rxnfc command
2436 *
2437 * Returns Success if the command is supported.
2438 **/
2439static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2440{
2441 struct i40e_netdev_priv *np = netdev_priv(netdev);
2442 struct i40e_vsi *vsi = np->vsi;
2443 struct i40e_pf *pf = vsi->back;
2444 int ret = -EOPNOTSUPP;
2445
2446 switch (cmd->cmd) {
2447 case ETHTOOL_SRXFH:
2448 ret = i40e_set_rss_hash_opt(pf, cmd);
2449 break;
2450 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002451 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002452 break;
2453 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002454 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002455 break;
2456 default:
2457 break;
2458 }
2459
2460 return ret;
2461}
2462
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002463/**
2464 * i40e_max_channels - get Max number of combined channels supported
2465 * @vsi: vsi pointer
2466 **/
2467static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2468{
2469 /* TODO: This code assumes DCB and FD is disabled for now. */
2470 return vsi->alloc_queue_pairs;
2471}
2472
2473/**
2474 * i40e_get_channels - Get the current channels enabled and max supported etc.
2475 * @netdev: network interface device structure
2476 * @ch: ethtool channels structure
2477 *
2478 * We don't support separate tx and rx queues as channels. The other count
2479 * represents how many queues are being used for control. max_combined counts
2480 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2481 * q_vectors since we support a lot more queue pairs than q_vectors.
2482 **/
2483static void i40e_get_channels(struct net_device *dev,
2484 struct ethtool_channels *ch)
2485{
2486 struct i40e_netdev_priv *np = netdev_priv(dev);
2487 struct i40e_vsi *vsi = np->vsi;
2488 struct i40e_pf *pf = vsi->back;
2489
2490 /* report maximum channels */
2491 ch->max_combined = i40e_max_channels(vsi);
2492
2493 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002494 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002495 ch->max_other = ch->other_count;
2496
2497 /* Note: This code assumes DCB is disabled for now. */
2498 ch->combined_count = vsi->num_queue_pairs;
2499}
2500
2501/**
2502 * i40e_set_channels - Set the new channels count.
2503 * @netdev: network interface device structure
2504 * @ch: ethtool channels structure
2505 *
2506 * The new channels count may not be the same as requested by the user
2507 * since it gets rounded down to a power of 2 value.
2508 **/
2509static int i40e_set_channels(struct net_device *dev,
2510 struct ethtool_channels *ch)
2511{
2512 struct i40e_netdev_priv *np = netdev_priv(dev);
2513 unsigned int count = ch->combined_count;
2514 struct i40e_vsi *vsi = np->vsi;
2515 struct i40e_pf *pf = vsi->back;
2516 int new_count;
2517
2518 /* We do not support setting channels for any other VSI at present */
2519 if (vsi->type != I40E_VSI_MAIN)
2520 return -EINVAL;
2521
2522 /* verify they are not requesting separate vectors */
2523 if (!count || ch->rx_count || ch->tx_count)
2524 return -EINVAL;
2525
2526 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002527 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002528 return -EINVAL;
2529
2530 /* verify the number of channels does not exceed hardware limits */
2531 if (count > i40e_max_channels(vsi))
2532 return -EINVAL;
2533
2534 /* update feature limits from largest to smallest supported values */
2535 /* TODO: Flow director limit, DCB etc */
2536
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002537 /* use rss_reconfig to rebuild with new queue count and update traffic
2538 * class queue mapping
2539 */
2540 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002541 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002542 return 0;
2543 else
2544 return -EINVAL;
2545}
2546
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002547#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2548/**
2549 * i40e_get_rxfh_key_size - get the RSS hash key size
2550 * @netdev: network interface device structure
2551 *
2552 * Returns the table size.
2553 **/
2554static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2555{
2556 return I40E_HKEY_ARRAY_SIZE;
2557}
2558
2559/**
2560 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2561 * @netdev: network interface device structure
2562 *
2563 * Returns the table size.
2564 **/
2565static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2566{
2567 return I40E_HLUT_ARRAY_SIZE;
2568}
2569
2570static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2571 u8 *hfunc)
2572{
2573 struct i40e_netdev_priv *np = netdev_priv(netdev);
2574 struct i40e_vsi *vsi = np->vsi;
2575 struct i40e_pf *pf = vsi->back;
2576 struct i40e_hw *hw = &pf->hw;
2577 u32 reg_val;
2578 int i, j;
2579
2580 if (hfunc)
2581 *hfunc = ETH_RSS_HASH_TOP;
2582
2583 if (!indir)
2584 return 0;
2585
2586 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2587 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2588 indir[j++] = reg_val & 0xff;
2589 indir[j++] = (reg_val >> 8) & 0xff;
2590 indir[j++] = (reg_val >> 16) & 0xff;
2591 indir[j++] = (reg_val >> 24) & 0xff;
2592 }
2593
2594 if (key) {
2595 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2596 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2597 key[j++] = (u8)(reg_val & 0xff);
2598 key[j++] = (u8)((reg_val >> 8) & 0xff);
2599 key[j++] = (u8)((reg_val >> 16) & 0xff);
2600 key[j++] = (u8)((reg_val >> 24) & 0xff);
2601 }
2602 }
2603 return 0;
2604}
2605
2606/**
2607 * i40e_set_rxfh - set the rx flow hash indirection table
2608 * @netdev: network interface device structure
2609 * @indir: indirection table
2610 * @key: hash key
2611 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002612 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002613 * returns 0 after programming the table.
2614 **/
2615static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2616 const u8 *key, const u8 hfunc)
2617{
2618 struct i40e_netdev_priv *np = netdev_priv(netdev);
2619 struct i40e_vsi *vsi = np->vsi;
2620 struct i40e_pf *pf = vsi->back;
2621 struct i40e_hw *hw = &pf->hw;
2622 u32 reg_val;
2623 int i, j;
2624
2625 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2626 return -EOPNOTSUPP;
2627
2628 if (!indir)
2629 return 0;
2630
2631 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2632 reg_val = indir[j++];
2633 reg_val |= indir[j++] << 8;
2634 reg_val |= indir[j++] << 16;
2635 reg_val |= indir[j++] << 24;
2636 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2637 }
2638
2639 if (key) {
2640 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2641 reg_val = key[j++];
2642 reg_val |= key[j++] << 8;
2643 reg_val |= key[j++] << 16;
2644 reg_val |= key[j++] << 24;
2645 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2646 }
2647 }
2648 return 0;
2649}
2650
Greg Rose7e45ab42015-02-06 08:52:19 +00002651/**
2652 * i40e_get_priv_flags - report device private flags
2653 * @dev: network interface device structure
2654 *
2655 * The get string set count and the string set should be matched for each
2656 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2657 * array.
2658 *
2659 * Returns a u32 bitmap of flags.
2660 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002661static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002662{
2663 struct i40e_netdev_priv *np = netdev_priv(dev);
2664 struct i40e_vsi *vsi = np->vsi;
2665 struct i40e_pf *pf = vsi->back;
2666 u32 ret_flags = 0;
2667
2668 ret_flags |= pf->hw.func_caps.npar_enable ?
2669 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
Shannon Nelson9ac77262015-08-27 11:42:40 -04002670 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2671 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04002672 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
2673 I40E_PRIV_FLAGS_FD_ATR : 0;
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002674 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
2675 I40E_PRIV_FLAGS_VEB_STATS : 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00002676
2677 return ret_flags;
2678}
2679
Shannon Nelson9ac77262015-08-27 11:42:40 -04002680/**
2681 * i40e_set_priv_flags - set private flags
2682 * @dev: network interface device structure
2683 * @flags: bit flags to be set
2684 **/
2685static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2686{
2687 struct i40e_netdev_priv *np = netdev_priv(dev);
2688 struct i40e_vsi *vsi = np->vsi;
2689 struct i40e_pf *pf = vsi->back;
2690
2691 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2692 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2693 else
2694 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2695
Jesse Brandeburgef171782015-09-03 17:18:49 -04002696 /* allow the user to control the state of the Flow
2697 * Director ATR (Application Targeted Routing) feature
2698 * of the driver
2699 */
2700 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
2701 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
2702 } else {
2703 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
2704 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
2705 }
2706
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002707 if (flags & I40E_PRIV_FLAGS_VEB_STATS)
2708 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
2709 else
2710 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
2711
Shannon Nelson9ac77262015-08-27 11:42:40 -04002712 return 0;
2713}
2714
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002715static const struct ethtool_ops i40e_ethtool_ops = {
2716 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002717 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002718 .get_drvinfo = i40e_get_drvinfo,
2719 .get_regs_len = i40e_get_regs_len,
2720 .get_regs = i40e_get_regs,
2721 .nway_reset = i40e_nway_reset,
2722 .get_link = ethtool_op_get_link,
2723 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002724 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002725 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002726 .get_eeprom_len = i40e_get_eeprom_len,
2727 .get_eeprom = i40e_get_eeprom,
2728 .get_ringparam = i40e_get_ringparam,
2729 .set_ringparam = i40e_set_ringparam,
2730 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002731 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002732 .get_msglevel = i40e_get_msglevel,
2733 .set_msglevel = i40e_set_msglevel,
2734 .get_rxnfc = i40e_get_rxnfc,
2735 .set_rxnfc = i40e_set_rxnfc,
2736 .self_test = i40e_diag_test,
2737 .get_strings = i40e_get_strings,
2738 .set_phys_id = i40e_set_phys_id,
2739 .get_sset_count = i40e_get_sset_count,
2740 .get_ethtool_stats = i40e_get_ethtool_stats,
2741 .get_coalesce = i40e_get_coalesce,
2742 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002743 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2744 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2745 .get_rxfh = i40e_get_rxfh,
2746 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002747 .get_channels = i40e_get_channels,
2748 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002749 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002750 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04002751 .set_priv_flags = i40e_set_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002752};
2753
2754void i40e_set_ethtool_ops(struct net_device *netdev)
2755{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002756 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002757}