blob: cd5083e91566c7b4bd8b29a2662b682a831e90d6 [file] [log] [blame]
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Greg Rosedc641b72013-12-18 13:45:51 +00004 * Copyright(c) 2013 - 2014 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),
Shannon Nelson41a9e552014-04-23 04:50:20 +000090};
91
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +000092static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
93 struct ethtool_rxnfc *cmd);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +000094
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000095/* These PF_STATs might look like duplicates of some NETDEV_STATs,
96 * but they are separate. This device supports Virtualization, and
97 * as such might have several netdevs supporting VMDq and FCoE going
98 * through a single port. The NETDEV_STATs are for individual netdevs
99 * seen at the top of the stack, and the PF_STATs are for the physical
100 * function at the bottom of the stack hosting those netdevs.
101 *
102 * The PF_STATs are appended to the netdev stats only when ethtool -S
103 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
104 */
105static struct i40e_stats i40e_gstrings_stats[] = {
106 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
107 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000108 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
109 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
110 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
111 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
112 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
113 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000114 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
115 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000116 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
117 I40E_PF_STAT("crc_errors", stats.crc_errors),
118 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
119 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
120 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000121 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000122 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000123 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
124 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
125 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
126 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
127 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
128 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
129 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
130 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
131 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
132 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
133 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
134 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
135 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
136 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
137 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
138 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
139 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
140 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
141 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
142 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
143 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
144 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
145 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
146 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000147 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000148 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000149 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
150 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
151
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000152 /* LPI stats */
153 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
154 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
155 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
156 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000157};
158
Vasu Dev38e00432014-08-01 13:27:03 -0700159#ifdef I40E_FCOE
160static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
161 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
162 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
163 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
164 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
165 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
166 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
167 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
168 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
169};
170
171#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000172#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000173 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
174 * 2 /* Tx and Rx together */ \
175 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000176#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
177#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000178#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700179#ifdef I40E_FCOE
180#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
181#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
182 I40E_FCOE_STATS_LEN + \
183 I40E_MISC_STATS_LEN + \
184 I40E_QUEUE_STATS_LEN((n)))
185#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000186#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000187 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000188 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700189#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000190#define I40E_PFC_STATS_LEN ( \
191 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
192 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
193 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
194 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
196 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000197#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000198#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
199 I40E_PFC_STATS_LEN + \
200 I40E_VSI_STATS_LEN((n)))
201
202enum i40e_ethtool_test_id {
203 I40E_ETH_TEST_REG = 0,
204 I40E_ETH_TEST_EEPROM,
205 I40E_ETH_TEST_INTR,
206 I40E_ETH_TEST_LOOPBACK,
207 I40E_ETH_TEST_LINK,
208};
209
210static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
211 "Register test (offline)",
212 "Eeprom test (offline)",
213 "Interrupt test (offline)",
214 "Loopback test (offline)",
215 "Link test (on/offline)"
216};
217
218#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
219
220/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000221 * i40e_partition_setting_complaint - generic complaint for MFP restriction
222 * @pf: the PF struct
223 **/
224static void i40e_partition_setting_complaint(struct i40e_pf *pf)
225{
226 dev_info(&pf->pdev->dev,
227 "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");
228}
229
230/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000231 * i40e_get_settings - Get Link Speed and Duplex settings
232 * @netdev: network interface device structure
233 * @ecmd: ethtool command
234 *
235 * Reports speed/duplex settings based on media_type
236 **/
237static int i40e_get_settings(struct net_device *netdev,
238 struct ethtool_cmd *ecmd)
239{
240 struct i40e_netdev_priv *np = netdev_priv(netdev);
241 struct i40e_pf *pf = np->vsi->back;
242 struct i40e_hw *hw = &pf->hw;
243 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
244 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
245 u32 link_speed = hw_link_info->link_speed;
246
247 /* hardware is either in 40G mode or 10G mode
248 * NOTE: this section initializes supported and advertising
249 */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000250 if (!link_up) {
251 /* link is down and the driver needs to fall back on
252 * device ID to determine what kinds of info to display,
253 * it's mostly a guess that may change when link is up
254 */
255 switch (hw->device_id) {
256 case I40E_DEV_ID_QSFP_A:
257 case I40E_DEV_ID_QSFP_B:
258 case I40E_DEV_ID_QSFP_C:
259 /* pluggable QSFP */
260 ecmd->supported = SUPPORTED_40000baseSR4_Full |
261 SUPPORTED_40000baseCR4_Full |
262 SUPPORTED_40000baseLR4_Full;
263 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
264 ADVERTISED_40000baseCR4_Full |
265 ADVERTISED_40000baseLR4_Full;
266 break;
267 case I40E_DEV_ID_KX_B:
268 /* backplane 40G */
269 ecmd->supported = SUPPORTED_40000baseKR4_Full;
270 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
271 break;
272 case I40E_DEV_ID_KX_C:
273 /* backplane 10G */
274 ecmd->supported = SUPPORTED_10000baseKR_Full;
275 ecmd->advertising = ADVERTISED_10000baseKR_Full;
276 break;
Mitch Williams5960d332014-09-13 07:40:47 +0000277 case I40E_DEV_ID_10G_BASE_T:
278 ecmd->supported = SUPPORTED_10000baseT_Full |
279 SUPPORTED_1000baseT_Full |
280 SUPPORTED_100baseT_Full;
281 ecmd->advertising = ADVERTISED_10000baseT_Full |
282 ADVERTISED_1000baseT_Full |
283 ADVERTISED_100baseT_Full;
284 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000285 default:
286 /* all the rest are 10G/1G */
287 ecmd->supported = SUPPORTED_10000baseT_Full |
288 SUPPORTED_1000baseT_Full;
289 ecmd->advertising = ADVERTISED_10000baseT_Full |
290 ADVERTISED_1000baseT_Full;
291 break;
292 }
293
294 /* skip phy_type use as it is zero when link is down */
295 goto no_valid_phy_type;
296 }
297
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000298 switch (hw_link_info->phy_type) {
299 case I40E_PHY_TYPE_40GBASE_CR4:
300 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000301 ecmd->supported = SUPPORTED_Autoneg |
302 SUPPORTED_40000baseCR4_Full;
303 ecmd->advertising = ADVERTISED_Autoneg |
304 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000305 break;
306 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000307 ecmd->supported = SUPPORTED_Autoneg |
308 SUPPORTED_40000baseKR4_Full;
309 ecmd->advertising = ADVERTISED_Autoneg |
310 ADVERTISED_40000baseKR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000311 break;
312 case I40E_PHY_TYPE_40GBASE_SR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000313 case I40E_PHY_TYPE_XLPPI:
314 case I40E_PHY_TYPE_XLAUI:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000315 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000316 break;
317 case I40E_PHY_TYPE_40GBASE_LR4:
318 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000319 break;
320 case I40E_PHY_TYPE_10GBASE_KX4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000321 ecmd->supported = SUPPORTED_Autoneg |
322 SUPPORTED_10000baseKX4_Full;
323 ecmd->advertising = ADVERTISED_Autoneg |
324 ADVERTISED_10000baseKX4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000325 break;
326 case I40E_PHY_TYPE_10GBASE_KR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000327 ecmd->supported = SUPPORTED_Autoneg |
328 SUPPORTED_10000baseKR_Full;
329 ecmd->advertising = ADVERTISED_Autoneg |
330 ADVERTISED_10000baseKR_Full;
331 break;
332 case I40E_PHY_TYPE_10GBASE_SR:
333 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000334 case I40E_PHY_TYPE_1000BASE_SX:
335 case I40E_PHY_TYPE_1000BASE_LX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000336 ecmd->supported = SUPPORTED_10000baseT_Full;
Catherine Sullivan124ed152014-07-12 07:28:12 +0000337 ecmd->supported |= SUPPORTED_1000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000338 break;
339 case I40E_PHY_TYPE_10GBASE_CR1_CU:
340 case I40E_PHY_TYPE_10GBASE_CR1:
341 case I40E_PHY_TYPE_10GBASE_T:
342 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000343 SUPPORTED_10000baseT_Full |
344 SUPPORTED_1000baseT_Full |
345 SUPPORTED_100baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000346 ecmd->advertising = ADVERTISED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000347 ADVERTISED_10000baseT_Full |
348 ADVERTISED_1000baseT_Full |
349 ADVERTISED_100baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000350 break;
351 case I40E_PHY_TYPE_XAUI:
352 case I40E_PHY_TYPE_XFI:
353 case I40E_PHY_TYPE_SFI:
354 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
355 ecmd->supported = SUPPORTED_10000baseT_Full;
356 break;
357 case I40E_PHY_TYPE_1000BASE_KX:
358 case I40E_PHY_TYPE_1000BASE_T:
359 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000360 SUPPORTED_10000baseT_Full |
361 SUPPORTED_1000baseT_Full |
362 SUPPORTED_100baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000363 ecmd->advertising = ADVERTISED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000364 ADVERTISED_10000baseT_Full |
365 ADVERTISED_1000baseT_Full |
366 ADVERTISED_100baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000367 break;
368 case I40E_PHY_TYPE_100BASE_TX:
369 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000370 SUPPORTED_10000baseT_Full |
371 SUPPORTED_1000baseT_Full |
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000372 SUPPORTED_100baseT_Full;
373 ecmd->advertising = ADVERTISED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000374 ADVERTISED_10000baseT_Full |
375 ADVERTISED_1000baseT_Full |
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000376 ADVERTISED_100baseT_Full;
377 break;
378 case I40E_PHY_TYPE_SGMII:
379 ecmd->supported = SUPPORTED_Autoneg |
380 SUPPORTED_1000baseT_Full |
381 SUPPORTED_100baseT_Full;
382 ecmd->advertising = ADVERTISED_Autoneg |
383 ADVERTISED_1000baseT_Full |
384 ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000385 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000386 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000387 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000388 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
389 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000390 }
391
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000392no_valid_phy_type:
393 /* this is if autoneg is enabled or disabled */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000394 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
395 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000396
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000397 switch (hw->phy.media_type) {
398 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000399 ecmd->supported |= SUPPORTED_Autoneg |
400 SUPPORTED_Backplane;
401 ecmd->advertising |= ADVERTISED_Autoneg |
402 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000403 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000404 break;
405 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000406 ecmd->supported |= SUPPORTED_TP;
407 ecmd->advertising |= ADVERTISED_TP;
408 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000409 break;
410 case I40E_MEDIA_TYPE_DA:
411 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000412 ecmd->supported |= SUPPORTED_FIBRE;
413 ecmd->advertising |= ADVERTISED_FIBRE;
414 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000415 break;
416 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000417 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000418 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000419 break;
420 case I40E_MEDIA_TYPE_UNKNOWN:
421 default:
422 ecmd->port = PORT_OTHER;
423 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000424 }
425
426 ecmd->transceiver = XCVR_EXTERNAL;
427
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000428 ecmd->supported |= SUPPORTED_Pause;
429
430 switch (hw->fc.current_mode) {
431 case I40E_FC_FULL:
432 ecmd->advertising |= ADVERTISED_Pause;
433 break;
434 case I40E_FC_TX_PAUSE:
435 ecmd->advertising |= ADVERTISED_Asym_Pause;
436 break;
437 case I40E_FC_RX_PAUSE:
438 ecmd->advertising |= (ADVERTISED_Pause |
439 ADVERTISED_Asym_Pause);
440 break;
441 default:
442 ecmd->advertising &= ~(ADVERTISED_Pause |
443 ADVERTISED_Asym_Pause);
444 break;
445 }
446
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000447 if (link_up) {
448 switch (link_speed) {
449 case I40E_LINK_SPEED_40GB:
450 /* need a SPEED_40000 in ethtool.h */
451 ethtool_cmd_speed_set(ecmd, 40000);
452 break;
453 case I40E_LINK_SPEED_10GB:
454 ethtool_cmd_speed_set(ecmd, SPEED_10000);
455 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000456 case I40E_LINK_SPEED_1GB:
457 ethtool_cmd_speed_set(ecmd, SPEED_1000);
458 break;
Mitch Williams5960d332014-09-13 07:40:47 +0000459 case I40E_LINK_SPEED_100MB:
460 ethtool_cmd_speed_set(ecmd, SPEED_100);
461 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000462 default:
463 break;
464 }
465 ecmd->duplex = DUPLEX_FULL;
466 } else {
467 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
468 ecmd->duplex = DUPLEX_UNKNOWN;
469 }
470
471 return 0;
472}
473
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000474/**
475 * i40e_set_settings - Set Speed and Duplex
476 * @netdev: network interface device structure
477 * @ecmd: ethtool command
478 *
479 * Set speed/duplex per media_types advertised/forced
480 **/
481static int i40e_set_settings(struct net_device *netdev,
482 struct ethtool_cmd *ecmd)
483{
484 struct i40e_netdev_priv *np = netdev_priv(netdev);
485 struct i40e_aq_get_phy_abilities_resp abilities;
486 struct i40e_aq_set_phy_config config;
487 struct i40e_pf *pf = np->vsi->back;
488 struct i40e_vsi *vsi = np->vsi;
489 struct i40e_hw *hw = &pf->hw;
490 struct ethtool_cmd safe_ecmd;
491 i40e_status status = 0;
492 bool change = false;
493 int err = 0;
494 u8 autoneg;
495 u32 advertise;
496
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000497 /* Changing port settings is not supported if this isn't the
498 * port's controlling PF
499 */
500 if (hw->partition_id != 1) {
501 i40e_partition_setting_complaint(pf);
502 return -EOPNOTSUPP;
503 }
504
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000505 if (vsi != pf->vsi[pf->lan_vsi])
506 return -EOPNOTSUPP;
507
508 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
509 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000510 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
511 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000512 return -EOPNOTSUPP;
513
514 /* get our own copy of the bits to check against */
515 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
516 i40e_get_settings(netdev, &safe_ecmd);
517
518 /* save autoneg and speed out of ecmd */
519 autoneg = ecmd->autoneg;
520 advertise = ecmd->advertising;
521
522 /* set autoneg and speed back to what they currently are */
523 ecmd->autoneg = safe_ecmd.autoneg;
524 ecmd->advertising = safe_ecmd.advertising;
525
526 ecmd->cmd = safe_ecmd.cmd;
527 /* If ecmd and safe_ecmd are not the same now, then they are
528 * trying to set something that we do not support
529 */
530 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
531 return -EOPNOTSUPP;
532
533 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
534 usleep_range(1000, 2000);
535
536 /* Get the current phy config */
537 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
538 NULL);
539 if (status)
540 return -EAGAIN;
541
Catherine Sullivan124ed152014-07-12 07:28:12 +0000542 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000543 * set below
544 */
545 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000546 config.abilities = abilities.abilities;
547
548 /* Check autoneg */
549 if (autoneg == AUTONEG_ENABLE) {
550 /* If autoneg is not supported, return error */
551 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
552 netdev_info(netdev, "Autoneg not supported on this phy\n");
553 return -EINVAL;
554 }
555 /* If autoneg was not already enabled */
556 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
557 config.abilities = abilities.abilities |
558 I40E_AQ_PHY_ENABLE_AN;
559 change = true;
560 }
561 } else {
562 /* If autoneg is supported 10GBASE_T is the only phy that
563 * can disable it, so otherwise return error
564 */
565 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
566 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
567 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
568 return -EINVAL;
569 }
570 /* If autoneg is currently enabled */
571 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000572 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000573 ~I40E_AQ_PHY_ENABLE_AN;
574 change = true;
575 }
576 }
577
578 if (advertise & ~safe_ecmd.supported)
579 return -EINVAL;
580
581 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000582 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000583 if (advertise & ADVERTISED_1000baseT_Full ||
584 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000585 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000586 if (advertise & ADVERTISED_10000baseT_Full ||
587 advertise & ADVERTISED_10000baseKX4_Full ||
588 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000589 config.link_speed |= I40E_LINK_SPEED_10GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000590 if (advertise & ADVERTISED_40000baseKR4_Full ||
591 advertise & ADVERTISED_40000baseCR4_Full ||
592 advertise & ADVERTISED_40000baseSR4_Full ||
593 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000594 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000595
Catherine Sullivan124ed152014-07-12 07:28:12 +0000596 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000597 /* copy over the rest of the abilities */
598 config.phy_type = abilities.phy_type;
599 config.eee_capability = abilities.eee_capability;
600 config.eeer = abilities.eeer_val;
601 config.low_power_ctrl = abilities.d3_lpan;
602
Catherine Sullivan94128512014-07-12 07:28:16 +0000603 /* set link and auto negotiation so changes take effect */
604 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
605 /* If link is up put link down */
606 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
607 /* Tell the OS link is going down, the link will go
608 * back up when fw says it is ready asynchronously
609 */
610 netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
611 netif_carrier_off(netdev);
612 netif_tx_stop_all_queues(netdev);
613 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000614
615 /* make the aq call */
616 status = i40e_aq_set_phy_config(hw, &config, NULL);
617 if (status) {
618 netdev_info(netdev, "Set phy config failed with error %d.\n",
619 status);
620 return -EAGAIN;
621 }
622
623 status = i40e_update_link_info(hw, true);
624 if (status)
625 netdev_info(netdev, "Updating link info failed with error %d\n",
626 status);
627
628 } else {
629 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
630 }
631
632 return err;
633}
634
Jesse Brandeburga6599722014-06-04 08:45:25 +0000635static int i40e_nway_reset(struct net_device *netdev)
636{
637 /* restart autonegotiation */
638 struct i40e_netdev_priv *np = netdev_priv(netdev);
639 struct i40e_pf *pf = np->vsi->back;
640 struct i40e_hw *hw = &pf->hw;
641 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
642 i40e_status ret = 0;
643
644 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
645 if (ret) {
646 netdev_info(netdev, "link restart failed, aq_err=%d\n",
647 pf->hw.aq.asq_last_status);
648 return -EIO;
649 }
650
651 return 0;
652}
653
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000654/**
655 * i40e_get_pauseparam - Get Flow Control status
656 * Return tx/rx-pause status
657 **/
658static void i40e_get_pauseparam(struct net_device *netdev,
659 struct ethtool_pauseparam *pause)
660{
661 struct i40e_netdev_priv *np = netdev_priv(netdev);
662 struct i40e_pf *pf = np->vsi->back;
663 struct i40e_hw *hw = &pf->hw;
664 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000665 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000666
667 pause->autoneg =
668 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
669 AUTONEG_ENABLE : AUTONEG_DISABLE);
670
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000671 /* PFC enabled so report LFC as off */
672 if (dcbx_cfg->pfc.pfcenable) {
673 pause->rx_pause = 0;
674 pause->tx_pause = 0;
675 return;
676 }
677
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000678 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000679 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000680 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000681 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000682 } else if (hw->fc.current_mode == I40E_FC_FULL) {
683 pause->rx_pause = 1;
684 pause->tx_pause = 1;
685 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000686}
687
Catherine Sullivan2becc352014-06-04 08:45:27 +0000688/**
689 * i40e_set_pauseparam - Set Flow Control parameter
690 * @netdev: network interface device structure
691 * @pause: return tx/rx flow control status
692 **/
693static int i40e_set_pauseparam(struct net_device *netdev,
694 struct ethtool_pauseparam *pause)
695{
696 struct i40e_netdev_priv *np = netdev_priv(netdev);
697 struct i40e_pf *pf = np->vsi->back;
698 struct i40e_vsi *vsi = np->vsi;
699 struct i40e_hw *hw = &pf->hw;
700 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000701 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000702 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
703 i40e_status status;
704 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000705 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000706
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000707 /* Changing the port's flow control is not supported if this isn't the
708 * port's controlling PF
709 */
710 if (hw->partition_id != 1) {
711 i40e_partition_setting_complaint(pf);
712 return -EOPNOTSUPP;
713 }
714
Catherine Sullivan2becc352014-06-04 08:45:27 +0000715 if (vsi != pf->vsi[pf->lan_vsi])
716 return -EOPNOTSUPP;
717
718 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
719 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
720 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
721 return -EOPNOTSUPP;
722 }
723
724 /* If we have link and don't have autoneg */
725 if (!test_bit(__I40E_DOWN, &pf->state) &&
726 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
727 /* Send message that it might not necessarily work*/
728 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
729 }
730
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000731 if (dcbx_cfg->pfc.pfcenable) {
732 netdev_info(netdev,
733 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000734 return -EOPNOTSUPP;
735 }
736
737 if (pause->rx_pause && pause->tx_pause)
738 hw->fc.requested_mode = I40E_FC_FULL;
739 else if (pause->rx_pause && !pause->tx_pause)
740 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
741 else if (!pause->rx_pause && pause->tx_pause)
742 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
743 else if (!pause->rx_pause && !pause->tx_pause)
744 hw->fc.requested_mode = I40E_FC_NONE;
745 else
746 return -EINVAL;
747
Catherine Sullivan94128512014-07-12 07:28:16 +0000748 /* Tell the OS link is going down, the link will go back up when fw
749 * says it is ready asynchronously
750 */
751 netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
752 netif_carrier_off(netdev);
753 netif_tx_stop_all_queues(netdev);
754
Catherine Sullivan2becc352014-06-04 08:45:27 +0000755 /* Set the fc mode and only restart an if link is up*/
756 status = i40e_set_fc(hw, &aq_failures, link_up);
757
758 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
759 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
760 status, hw->aq.asq_last_status);
761 err = -EAGAIN;
762 }
763 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
764 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
765 status, hw->aq.asq_last_status);
766 err = -EAGAIN;
767 }
768 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
769 netdev_info(netdev, "Set fc failed on the update_link_info call with error %d and status %d\n",
770 status, hw->aq.asq_last_status);
771 err = -EAGAIN;
772 }
773
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000774 if (!test_bit(__I40E_DOWN, &pf->state)) {
775 /* Give it a little more time to try to come back */
776 msleep(75);
777 if (!test_bit(__I40E_DOWN, &pf->state))
778 return i40e_nway_reset(netdev);
779 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000780
781 return err;
782}
783
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000784static u32 i40e_get_msglevel(struct net_device *netdev)
785{
786 struct i40e_netdev_priv *np = netdev_priv(netdev);
787 struct i40e_pf *pf = np->vsi->back;
788
789 return pf->msg_enable;
790}
791
792static void i40e_set_msglevel(struct net_device *netdev, u32 data)
793{
794 struct i40e_netdev_priv *np = netdev_priv(netdev);
795 struct i40e_pf *pf = np->vsi->back;
796
797 if (I40E_DEBUG_USER & data)
798 pf->hw.debug_mask = data;
799 pf->msg_enable = data;
800}
801
802static int i40e_get_regs_len(struct net_device *netdev)
803{
804 int reg_count = 0;
805 int i;
806
807 for (i = 0; i40e_reg_list[i].offset != 0; i++)
808 reg_count += i40e_reg_list[i].elements;
809
810 return reg_count * sizeof(u32);
811}
812
813static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
814 void *p)
815{
816 struct i40e_netdev_priv *np = netdev_priv(netdev);
817 struct i40e_pf *pf = np->vsi->back;
818 struct i40e_hw *hw = &pf->hw;
819 u32 *reg_buf = p;
820 int i, j, ri;
821 u32 reg;
822
823 /* Tell ethtool which driver-version-specific regs output we have.
824 *
825 * At some point, if we have ethtool doing special formatting of
826 * this data, it will rely on this version number to know how to
827 * interpret things. Hence, this needs to be updated if/when the
828 * diags register table is changed.
829 */
830 regs->version = 1;
831
832 /* loop through the diags reg table for what to print */
833 ri = 0;
834 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
835 for (j = 0; j < i40e_reg_list[i].elements; j++) {
836 reg = i40e_reg_list[i].offset
837 + (j * i40e_reg_list[i].stride);
838 reg_buf[ri++] = rd32(hw, reg);
839 }
840 }
841
842}
843
844static int i40e_get_eeprom(struct net_device *netdev,
845 struct ethtool_eeprom *eeprom, u8 *bytes)
846{
847 struct i40e_netdev_priv *np = netdev_priv(netdev);
848 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000849 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000850 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000851 u8 *eeprom_buff;
852 u16 i, sectors;
853 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000854 u32 magic;
855
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000856#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000857 if (eeprom->len == 0)
858 return -EINVAL;
859
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000860 /* check for NVMUpdate access method */
861 magic = hw->vendor_id | (hw->device_id << 16);
862 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000863 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000864 int errno;
865
866 /* make sure it is the right magic for NVMUpdate */
867 if ((eeprom->magic >> 16) != hw->device_id)
868 return -EINVAL;
869
Shannon Nelsonc150a502014-11-13 08:23:13 +0000870 cmd = (struct i40e_nvm_access *)eeprom;
871 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000872 if (ret_val)
873 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000874 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
875 ret_val, hw->aq.asq_last_status, errno,
876 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
877 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000878
879 return errno;
880 }
881
882 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000883 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
884
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000885 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000886 if (!eeprom_buff)
887 return -ENOMEM;
888
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000889 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
890 if (ret_val) {
891 dev_info(&pf->pdev->dev,
892 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
893 ret_val, hw->aq.asq_last_status);
894 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000895 }
896
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000897 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
898 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
899 len = I40E_NVM_SECTOR_SIZE;
900 last = false;
901 for (i = 0; i < sectors; i++) {
902 if (i == (sectors - 1)) {
903 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
904 last = true;
905 }
Shannon Nelsonc150a502014-11-13 08:23:13 +0000906 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
907 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000908 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000909 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +0000910 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000911 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000912 "read NVM failed, invalid offset 0x%x\n",
913 offset);
914 break;
915 } else if (ret_val &&
916 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
917 dev_info(&pf->pdev->dev,
918 "read NVM failed, access, offset 0x%x\n",
919 offset);
920 break;
921 } else if (ret_val) {
922 dev_info(&pf->pdev->dev,
923 "read NVM failed offset %d err=%d status=0x%x\n",
924 offset, ret_val, hw->aq.asq_last_status);
925 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000926 }
927 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000928
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000929 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000930 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000931free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000932 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000933 return ret_val;
934}
935
936static int i40e_get_eeprom_len(struct net_device *netdev)
937{
938 struct i40e_netdev_priv *np = netdev_priv(netdev);
939 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000940 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000941
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000942 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
943 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
944 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
945 /* register returns value in power of 2, 64Kbyte chunks. */
946 val = (64 * 1024) * (1 << val);
947 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000948}
949
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000950static int i40e_set_eeprom(struct net_device *netdev,
951 struct ethtool_eeprom *eeprom, u8 *bytes)
952{
953 struct i40e_netdev_priv *np = netdev_priv(netdev);
954 struct i40e_hw *hw = &np->vsi->back->hw;
955 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000956 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000957 int ret_val = 0;
958 int errno;
959 u32 magic;
960
961 /* normal ethtool set_eeprom is not supported */
962 magic = hw->vendor_id | (hw->device_id << 16);
963 if (eeprom->magic == magic)
964 return -EOPNOTSUPP;
965
966 /* check for NVMUpdate access method */
967 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
968 return -EINVAL;
969
970 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
971 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
972 return -EBUSY;
973
Shannon Nelsonc150a502014-11-13 08:23:13 +0000974 cmd = (struct i40e_nvm_access *)eeprom;
975 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
976 if (ret_val && hw->aq.asq_last_status != I40E_AQ_RC_EBUSY)
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000977 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000978 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
979 ret_val, hw->aq.asq_last_status, errno,
980 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
981 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000982
983 return errno;
984}
985
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000986static void i40e_get_drvinfo(struct net_device *netdev,
987 struct ethtool_drvinfo *drvinfo)
988{
989 struct i40e_netdev_priv *np = netdev_priv(netdev);
990 struct i40e_vsi *vsi = np->vsi;
991 struct i40e_pf *pf = vsi->back;
992
993 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
994 strlcpy(drvinfo->version, i40e_driver_version_str,
995 sizeof(drvinfo->version));
996 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
997 sizeof(drvinfo->fw_version));
998 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
999 sizeof(drvinfo->bus_info));
1000}
1001
1002static void i40e_get_ringparam(struct net_device *netdev,
1003 struct ethtool_ringparam *ring)
1004{
1005 struct i40e_netdev_priv *np = netdev_priv(netdev);
1006 struct i40e_pf *pf = np->vsi->back;
1007 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1008
1009 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1010 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1011 ring->rx_mini_max_pending = 0;
1012 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001013 ring->rx_pending = vsi->rx_rings[0]->count;
1014 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001015 ring->rx_mini_pending = 0;
1016 ring->rx_jumbo_pending = 0;
1017}
1018
1019static int i40e_set_ringparam(struct net_device *netdev,
1020 struct ethtool_ringparam *ring)
1021{
1022 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1023 struct i40e_netdev_priv *np = netdev_priv(netdev);
1024 struct i40e_vsi *vsi = np->vsi;
1025 struct i40e_pf *pf = vsi->back;
1026 u32 new_rx_count, new_tx_count;
1027 int i, err = 0;
1028
1029 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1030 return -EINVAL;
1031
Shannon Nelson1fa18372013-11-20 10:03:08 +00001032 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1033 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1034 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1035 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1036 netdev_info(netdev,
1037 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1038 ring->tx_pending, ring->rx_pending,
1039 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1040 return -EINVAL;
1041 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001042
Shannon Nelson1fa18372013-11-20 10:03:08 +00001043 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1044 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001045
1046 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001047 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1048 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001049 return 0;
1050
1051 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1052 usleep_range(1000, 2000);
1053
1054 if (!netif_running(vsi->netdev)) {
1055 /* simple case - set for the next time the netdev is started */
1056 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001057 vsi->tx_rings[i]->count = new_tx_count;
1058 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001059 }
1060 goto done;
1061 }
1062
1063 /* We can't just free everything and then setup again,
1064 * because the ISRs in MSI-X mode get passed pointers
1065 * to the Tx and Rx ring structs.
1066 */
1067
1068 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001069 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001070 netdev_info(netdev,
1071 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001072 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001073 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1074 sizeof(struct i40e_ring), GFP_KERNEL);
1075 if (!tx_rings) {
1076 err = -ENOMEM;
1077 goto done;
1078 }
1079
1080 for (i = 0; i < vsi->num_queue_pairs; i++) {
1081 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001082 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001083 tx_rings[i].count = new_tx_count;
1084 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1085 if (err) {
1086 while (i) {
1087 i--;
1088 i40e_free_tx_resources(&tx_rings[i]);
1089 }
1090 kfree(tx_rings);
1091 tx_rings = NULL;
1092
1093 goto done;
1094 }
1095 }
1096 }
1097
1098 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001099 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001100 netdev_info(netdev,
1101 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001102 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001103 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1104 sizeof(struct i40e_ring), GFP_KERNEL);
1105 if (!rx_rings) {
1106 err = -ENOMEM;
1107 goto free_tx;
1108 }
1109
1110 for (i = 0; i < vsi->num_queue_pairs; i++) {
1111 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001112 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001113 rx_rings[i].count = new_rx_count;
1114 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1115 if (err) {
1116 while (i) {
1117 i--;
1118 i40e_free_rx_resources(&rx_rings[i]);
1119 }
1120 kfree(rx_rings);
1121 rx_rings = NULL;
1122
1123 goto free_tx;
1124 }
1125 }
1126 }
1127
1128 /* Bring interface down, copy in the new ring info,
1129 * then restore the interface
1130 */
1131 i40e_down(vsi);
1132
1133 if (tx_rings) {
1134 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001135 i40e_free_tx_resources(vsi->tx_rings[i]);
1136 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001137 }
1138 kfree(tx_rings);
1139 tx_rings = NULL;
1140 }
1141
1142 if (rx_rings) {
1143 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001144 i40e_free_rx_resources(vsi->rx_rings[i]);
1145 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001146 }
1147 kfree(rx_rings);
1148 rx_rings = NULL;
1149 }
1150
1151 i40e_up(vsi);
1152
1153free_tx:
1154 /* error cleanup if the Rx allocations failed after getting Tx */
1155 if (tx_rings) {
1156 for (i = 0; i < vsi->num_queue_pairs; i++)
1157 i40e_free_tx_resources(&tx_rings[i]);
1158 kfree(tx_rings);
1159 tx_rings = NULL;
1160 }
1161
1162done:
1163 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1164
1165 return err;
1166}
1167
1168static int i40e_get_sset_count(struct net_device *netdev, int sset)
1169{
1170 struct i40e_netdev_priv *np = netdev_priv(netdev);
1171 struct i40e_vsi *vsi = np->vsi;
1172 struct i40e_pf *pf = vsi->back;
1173
1174 switch (sset) {
1175 case ETH_SS_TEST:
1176 return I40E_TEST_LEN;
1177 case ETH_SS_STATS:
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001178 if (vsi == pf->vsi[pf->lan_vsi]) {
1179 int len = I40E_PF_STATS_LEN(netdev);
1180
1181 if (pf->lan_veb != I40E_NO_VEB)
1182 len += I40E_VEB_STATS_LEN;
1183 return len;
1184 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001185 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001186 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001187 default:
1188 return -EOPNOTSUPP;
1189 }
1190}
1191
1192static void i40e_get_ethtool_stats(struct net_device *netdev,
1193 struct ethtool_stats *stats, u64 *data)
1194{
1195 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001196 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001197 struct i40e_vsi *vsi = np->vsi;
1198 struct i40e_pf *pf = vsi->back;
1199 int i = 0;
1200 char *p;
1201 int j;
1202 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001203 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001204
1205 i40e_update_stats(vsi);
1206
1207 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1208 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1209 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1210 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1211 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001212 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1213 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1214 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1215 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1216 }
Vasu Dev38e00432014-08-01 13:27:03 -07001217#ifdef I40E_FCOE
1218 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1219 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1220 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1221 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1222 }
1223#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001224 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001225 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001226 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001227
1228 if (!tx_ring)
1229 continue;
1230
1231 /* process Tx ring statistics */
1232 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001233 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001234 data[i] = tx_ring->stats.packets;
1235 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001236 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001237 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001238
1239 /* Rx ring is the 2nd half of the queue pair */
1240 rx_ring = &tx_ring[1];
1241 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001242 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001243 data[i] = rx_ring->stats.packets;
1244 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001245 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001246 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001247 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001248 rcu_read_unlock();
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001249 if (vsi != pf->vsi[pf->lan_vsi])
1250 return;
1251
1252 if (pf->lan_veb != I40E_NO_VEB) {
1253 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1254 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1255 p = (char *)veb;
1256 p += i40e_gstrings_veb_stats[j].stat_offset;
1257 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1258 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001259 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001260 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001261 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1262 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1263 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1264 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1265 }
1266 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1267 data[i++] = pf->stats.priority_xon_tx[j];
1268 data[i++] = pf->stats.priority_xoff_tx[j];
1269 }
1270 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1271 data[i++] = pf->stats.priority_xon_rx[j];
1272 data[i++] = pf->stats.priority_xoff_rx[j];
1273 }
1274 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1275 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001276}
1277
1278static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1279 u8 *data)
1280{
1281 struct i40e_netdev_priv *np = netdev_priv(netdev);
1282 struct i40e_vsi *vsi = np->vsi;
1283 struct i40e_pf *pf = vsi->back;
1284 char *p = (char *)data;
1285 int i;
1286
1287 switch (stringset) {
1288 case ETH_SS_TEST:
1289 for (i = 0; i < I40E_TEST_LEN; i++) {
1290 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1291 data += ETH_GSTRING_LEN;
1292 }
1293 break;
1294 case ETH_SS_STATS:
1295 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1296 snprintf(p, ETH_GSTRING_LEN, "%s",
1297 i40e_gstrings_net_stats[i].stat_string);
1298 p += ETH_GSTRING_LEN;
1299 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001300 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1301 snprintf(p, ETH_GSTRING_LEN, "%s",
1302 i40e_gstrings_misc_stats[i].stat_string);
1303 p += ETH_GSTRING_LEN;
1304 }
Vasu Dev38e00432014-08-01 13:27:03 -07001305#ifdef I40E_FCOE
1306 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1307 snprintf(p, ETH_GSTRING_LEN, "%s",
1308 i40e_gstrings_fcoe_stats[i].stat_string);
1309 p += ETH_GSTRING_LEN;
1310 }
1311#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001312 for (i = 0; i < vsi->num_queue_pairs; i++) {
1313 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1314 p += ETH_GSTRING_LEN;
1315 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1316 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001317 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1318 p += ETH_GSTRING_LEN;
1319 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1320 p += ETH_GSTRING_LEN;
1321 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001322 if (vsi != pf->vsi[pf->lan_vsi])
1323 return;
1324
1325 if (pf->lan_veb != I40E_NO_VEB) {
1326 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1327 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1328 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001329 p += ETH_GSTRING_LEN;
1330 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001331 }
1332 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1333 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1334 i40e_gstrings_stats[i].stat_string);
1335 p += ETH_GSTRING_LEN;
1336 }
1337 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1338 snprintf(p, ETH_GSTRING_LEN,
1339 "port.tx_priority_%u_xon", i);
1340 p += ETH_GSTRING_LEN;
1341 snprintf(p, ETH_GSTRING_LEN,
1342 "port.tx_priority_%u_xoff", i);
1343 p += ETH_GSTRING_LEN;
1344 }
1345 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1346 snprintf(p, ETH_GSTRING_LEN,
1347 "port.rx_priority_%u_xon", i);
1348 p += ETH_GSTRING_LEN;
1349 snprintf(p, ETH_GSTRING_LEN,
1350 "port.rx_priority_%u_xoff", i);
1351 p += ETH_GSTRING_LEN;
1352 }
1353 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1354 snprintf(p, ETH_GSTRING_LEN,
1355 "port.rx_priority_%u_xon_2_xoff", i);
1356 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001357 }
1358 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1359 break;
1360 }
1361}
1362
1363static int i40e_get_ts_info(struct net_device *dev,
1364 struct ethtool_ts_info *info)
1365{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001366 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1367
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001368 /* only report HW timestamping if PTP is enabled */
1369 if (!(pf->flags & I40E_FLAG_PTP))
1370 return ethtool_op_get_ts_info(dev, info);
1371
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001372 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1373 SOF_TIMESTAMPING_RX_SOFTWARE |
1374 SOF_TIMESTAMPING_SOFTWARE |
1375 SOF_TIMESTAMPING_TX_HARDWARE |
1376 SOF_TIMESTAMPING_RX_HARDWARE |
1377 SOF_TIMESTAMPING_RAW_HARDWARE;
1378
1379 if (pf->ptp_clock)
1380 info->phc_index = ptp_clock_index(pf->ptp_clock);
1381 else
1382 info->phc_index = -1;
1383
1384 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1385
1386 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1387 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1388 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1389 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1390 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1391 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1392 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1393 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1394 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1395 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1396 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1397 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1398
1399 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001400}
1401
Shannon Nelson7b086392013-11-20 10:02:59 +00001402static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001403{
Shannon Nelson7b086392013-11-20 10:02:59 +00001404 struct i40e_netdev_priv *np = netdev_priv(netdev);
1405 struct i40e_pf *pf = np->vsi->back;
1406
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001407 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001408 if (i40e_get_link_status(&pf->hw))
1409 *data = 0;
1410 else
1411 *data = 1;
1412
1413 return *data;
1414}
1415
Shannon Nelson7b086392013-11-20 10:02:59 +00001416static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001417{
Shannon Nelson7b086392013-11-20 10:02:59 +00001418 struct i40e_netdev_priv *np = netdev_priv(netdev);
1419 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001420
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001421 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001422 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001423
Shannon Nelson7b086392013-11-20 10:02:59 +00001424 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001425}
1426
Shannon Nelson7b086392013-11-20 10:02:59 +00001427static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001428{
Shannon Nelson7b086392013-11-20 10:02:59 +00001429 struct i40e_netdev_priv *np = netdev_priv(netdev);
1430 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001431
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001432 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001433 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001434
Shannon Nelson4443ec92014-11-13 08:23:12 +00001435 /* forcebly clear the NVM Update state machine */
1436 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1437
Shannon Nelson7b086392013-11-20 10:02:59 +00001438 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001439}
1440
Shannon Nelson7b086392013-11-20 10:02:59 +00001441static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001442{
Shannon Nelson7b086392013-11-20 10:02:59 +00001443 struct i40e_netdev_priv *np = netdev_priv(netdev);
1444 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001445 u16 swc_old = pf->sw_int_count;
1446
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001447 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001448 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1449 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001450 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1451 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1452 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1453 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001454 usleep_range(1000, 2000);
1455 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001456
1457 return *data;
1458}
1459
Shannon Nelson7b086392013-11-20 10:02:59 +00001460static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001461{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001462 struct i40e_netdev_priv *np = netdev_priv(netdev);
1463 struct i40e_pf *pf = np->vsi->back;
1464
1465 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001466 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001467
1468 return *data;
1469}
1470
1471static void i40e_diag_test(struct net_device *netdev,
1472 struct ethtool_test *eth_test, u64 *data)
1473{
1474 struct i40e_netdev_priv *np = netdev_priv(netdev);
1475 struct i40e_pf *pf = np->vsi->back;
1476
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001477 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1478 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001479 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001480
Shannon Nelsonf551b432013-11-26 10:49:12 +00001481 set_bit(__I40E_TESTING, &pf->state);
1482
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001483 /* Link test performed before hardware reset
1484 * so autoneg doesn't interfere with test result
1485 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001486 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001487 eth_test->flags |= ETH_TEST_FL_FAILED;
1488
Shannon Nelson7b086392013-11-20 10:02:59 +00001489 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001490 eth_test->flags |= ETH_TEST_FL_FAILED;
1491
Shannon Nelson7b086392013-11-20 10:02:59 +00001492 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001493 eth_test->flags |= ETH_TEST_FL_FAILED;
1494
Shannon Nelson7b086392013-11-20 10:02:59 +00001495 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001496 eth_test->flags |= ETH_TEST_FL_FAILED;
1497
Shannon Nelsonf551b432013-11-26 10:49:12 +00001498 /* run reg test last, a reset is required after it */
1499 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1500 eth_test->flags |= ETH_TEST_FL_FAILED;
1501
1502 clear_bit(__I40E_TESTING, &pf->state);
1503 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001504 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001505 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001506 netif_info(pf, drv, netdev, "online testing starting\n");
1507
Shannon Nelson7b086392013-11-20 10:02:59 +00001508 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001509 eth_test->flags |= ETH_TEST_FL_FAILED;
1510
1511 /* Offline only tests, not run in online; pass by default */
1512 data[I40E_ETH_TEST_REG] = 0;
1513 data[I40E_ETH_TEST_EEPROM] = 0;
1514 data[I40E_ETH_TEST_INTR] = 0;
1515 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001516 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001517
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001518 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001519}
1520
1521static void i40e_get_wol(struct net_device *netdev,
1522 struct ethtool_wolinfo *wol)
1523{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001524 struct i40e_netdev_priv *np = netdev_priv(netdev);
1525 struct i40e_pf *pf = np->vsi->back;
1526 struct i40e_hw *hw = &pf->hw;
1527 u16 wol_nvm_bits;
1528
1529 /* NVM bit on means WoL disabled for the port */
1530 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001531 if ((1 << hw->port) & wol_nvm_bits || hw->partition_id != 1) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001532 wol->supported = 0;
1533 wol->wolopts = 0;
1534 } else {
1535 wol->supported = WAKE_MAGIC;
1536 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1537 }
1538}
1539
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001540/**
1541 * i40e_set_wol - set the WakeOnLAN configuration
1542 * @netdev: the netdev in question
1543 * @wol: the ethtool WoL setting data
1544 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001545static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1546{
1547 struct i40e_netdev_priv *np = netdev_priv(netdev);
1548 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001549 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001550 struct i40e_hw *hw = &pf->hw;
1551 u16 wol_nvm_bits;
1552
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001553 /* WoL not supported if this isn't the controlling PF on the port */
1554 if (hw->partition_id != 1) {
1555 i40e_partition_setting_complaint(pf);
1556 return -EOPNOTSUPP;
1557 }
1558
1559 if (vsi != pf->vsi[pf->lan_vsi])
1560 return -EOPNOTSUPP;
1561
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001562 /* NVM bit on means WoL disabled for the port */
1563 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1564 if (((1 << hw->port) & wol_nvm_bits))
1565 return -EOPNOTSUPP;
1566
1567 /* only magic packet is supported */
1568 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1569 return -EOPNOTSUPP;
1570
1571 /* is this a new value? */
1572 if (pf->wol_en != !!wol->wolopts) {
1573 pf->wol_en = !!wol->wolopts;
1574 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1575 }
1576
1577 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001578}
1579
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001580static int i40e_set_phys_id(struct net_device *netdev,
1581 enum ethtool_phys_id_state state)
1582{
1583 struct i40e_netdev_priv *np = netdev_priv(netdev);
1584 struct i40e_pf *pf = np->vsi->back;
1585 struct i40e_hw *hw = &pf->hw;
1586 int blink_freq = 2;
1587
1588 switch (state) {
1589 case ETHTOOL_ID_ACTIVE:
1590 pf->led_status = i40e_led_get(hw);
1591 return blink_freq;
1592 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001593 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001594 break;
1595 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001596 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001597 break;
1598 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001599 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001600 break;
1601 }
1602
1603 return 0;
1604}
1605
1606/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1607 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1608 * 125us (8000 interrupts per second) == ITR(62)
1609 */
1610
1611static int i40e_get_coalesce(struct net_device *netdev,
1612 struct ethtool_coalesce *ec)
1613{
1614 struct i40e_netdev_priv *np = netdev_priv(netdev);
1615 struct i40e_vsi *vsi = np->vsi;
1616
1617 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1618 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1619
1620 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001621 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001622
1623 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001624 ec->use_adaptive_tx_coalesce = 1;
1625
1626 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1627 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001628
1629 return 0;
1630}
1631
1632static int i40e_set_coalesce(struct net_device *netdev,
1633 struct ethtool_coalesce *ec)
1634{
1635 struct i40e_netdev_priv *np = netdev_priv(netdev);
1636 struct i40e_q_vector *q_vector;
1637 struct i40e_vsi *vsi = np->vsi;
1638 struct i40e_pf *pf = vsi->back;
1639 struct i40e_hw *hw = &pf->hw;
1640 u16 vector;
1641 int i;
1642
1643 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1644 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1645
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001646 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001647 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001648 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001649 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001650 } else if (ec->rx_coalesce_usecs == 0) {
1651 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001652 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001653 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 +00001654 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001655 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001656 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001657 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001658
Mitch Williams32f5f542014-04-04 04:43:10 +00001659 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001660 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001661 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001662 } else if (ec->tx_coalesce_usecs == 0) {
1663 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001664 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001665 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 +00001666 } else {
1667 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001668 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001669 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001670 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001671
1672 if (ec->use_adaptive_rx_coalesce)
1673 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1674 else
1675 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1676
1677 if (ec->use_adaptive_tx_coalesce)
1678 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1679 else
1680 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001681
Alexander Duyck493fb302013-09-28 07:01:44 +00001682 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1683 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001684 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1685 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1686 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1687 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1688 i40e_flush(hw);
1689 }
1690
1691 return 0;
1692}
1693
1694/**
1695 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1696 * @pf: pointer to the physical function struct
1697 * @cmd: ethtool rxnfc command
1698 *
1699 * Returns Success if the flow is supported, else Invalid Input.
1700 **/
1701static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1702{
1703 cmd->data = 0;
1704
1705 /* Report default options for RSS on i40e */
1706 switch (cmd->flow_type) {
1707 case TCP_V4_FLOW:
1708 case UDP_V4_FLOW:
1709 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1710 /* fall through to add IP fields */
1711 case SCTP_V4_FLOW:
1712 case AH_ESP_V4_FLOW:
1713 case AH_V4_FLOW:
1714 case ESP_V4_FLOW:
1715 case IPV4_FLOW:
1716 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1717 break;
1718 case TCP_V6_FLOW:
1719 case UDP_V6_FLOW:
1720 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1721 /* fall through to add IP fields */
1722 case SCTP_V6_FLOW:
1723 case AH_ESP_V6_FLOW:
1724 case AH_V6_FLOW:
1725 case ESP_V6_FLOW:
1726 case IPV6_FLOW:
1727 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1728 break;
1729 default:
1730 return -EINVAL;
1731 }
1732
1733 return 0;
1734}
1735
1736/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001737 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1738 * @pf: Pointer to the physical function struct
1739 * @cmd: The command to get or set Rx flow classification rules
1740 * @rule_locs: Array of used rule locations
1741 *
1742 * This function populates both the total and actual rule count of
1743 * the ethtool flow classification command
1744 *
1745 * Returns 0 on success or -EMSGSIZE if entry not found
1746 **/
1747static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1748 struct ethtool_rxnfc *cmd,
1749 u32 *rule_locs)
1750{
1751 struct i40e_fdir_filter *rule;
1752 struct hlist_node *node2;
1753 int cnt = 0;
1754
1755 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001756 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001757
1758 hlist_for_each_entry_safe(rule, node2,
1759 &pf->fdir_filter_list, fdir_node) {
1760 if (cnt == cmd->rule_cnt)
1761 return -EMSGSIZE;
1762
1763 rule_locs[cnt] = rule->fd_id;
1764 cnt++;
1765 }
1766
1767 cmd->rule_cnt = cnt;
1768
1769 return 0;
1770}
1771
1772/**
1773 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1774 * @pf: Pointer to the physical function struct
1775 * @cmd: The command to get or set Rx flow classification rules
1776 *
1777 * This function looks up a filter based on the Rx flow classification
1778 * command and fills the flow spec info for it if found
1779 *
1780 * Returns 0 on success or -EINVAL if filter not found
1781 **/
1782static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1783 struct ethtool_rxnfc *cmd)
1784{
1785 struct ethtool_rx_flow_spec *fsp =
1786 (struct ethtool_rx_flow_spec *)&cmd->fs;
1787 struct i40e_fdir_filter *rule = NULL;
1788 struct hlist_node *node2;
1789
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001790 hlist_for_each_entry_safe(rule, node2,
1791 &pf->fdir_filter_list, fdir_node) {
1792 if (fsp->location <= rule->fd_id)
1793 break;
1794 }
1795
1796 if (!rule || fsp->location != rule->fd_id)
1797 return -EINVAL;
1798
1799 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001800 if (fsp->flow_type == IP_USER_FLOW) {
1801 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1802 fsp->h_u.usr_ip4_spec.proto = 0;
1803 fsp->m_u.usr_ip4_spec.proto = 0;
1804 }
1805
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001806 /* Reverse the src and dest notion, since the HW views them from
1807 * Tx perspective where as the user expects it from Rx filter view.
1808 */
1809 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1810 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1811 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1812 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001813
1814 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1815 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1816 else
1817 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001818
1819 return 0;
1820}
1821
1822/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001823 * i40e_get_rxnfc - command to get RX flow classification rules
1824 * @netdev: network interface device structure
1825 * @cmd: ethtool rxnfc command
1826 *
1827 * Returns Success if the command is supported.
1828 **/
1829static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1830 u32 *rule_locs)
1831{
1832 struct i40e_netdev_priv *np = netdev_priv(netdev);
1833 struct i40e_vsi *vsi = np->vsi;
1834 struct i40e_pf *pf = vsi->back;
1835 int ret = -EOPNOTSUPP;
1836
1837 switch (cmd->cmd) {
1838 case ETHTOOL_GRXRINGS:
1839 cmd->data = vsi->alloc_queue_pairs;
1840 ret = 0;
1841 break;
1842 case ETHTOOL_GRXFH:
1843 ret = i40e_get_rss_hash_opts(pf, cmd);
1844 break;
1845 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001846 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001847 /* report total rule count */
1848 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001849 ret = 0;
1850 break;
1851 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001852 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001853 break;
1854 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001855 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1856 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001857 default:
1858 break;
1859 }
1860
1861 return ret;
1862}
1863
1864/**
1865 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1866 * @pf: pointer to the physical function struct
1867 * @cmd: ethtool rxnfc command
1868 *
1869 * Returns Success if the flow input set is supported.
1870 **/
1871static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1872{
1873 struct i40e_hw *hw = &pf->hw;
1874 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1875 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1876
1877 /* RSS does not support anything other than hashing
1878 * to queues on src and dst IPs and ports
1879 */
1880 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1881 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1882 return -EINVAL;
1883
1884 /* We need at least the IP SRC and DEST fields for hashing */
1885 if (!(nfc->data & RXH_IP_SRC) ||
1886 !(nfc->data & RXH_IP_DST))
1887 return -EINVAL;
1888
1889 switch (nfc->flow_type) {
1890 case TCP_V4_FLOW:
1891 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1892 case 0:
1893 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1894 break;
1895 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1896 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1897 break;
1898 default:
1899 return -EINVAL;
1900 }
1901 break;
1902 case TCP_V6_FLOW:
1903 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1904 case 0:
1905 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1906 break;
1907 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1908 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1909 break;
1910 default:
1911 return -EINVAL;
1912 }
1913 break;
1914 case UDP_V4_FLOW:
1915 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1916 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001917 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1918 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001919 break;
1920 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001921 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1922 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001923 break;
1924 default:
1925 return -EINVAL;
1926 }
1927 break;
1928 case UDP_V6_FLOW:
1929 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1930 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001931 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1932 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001933 break;
1934 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001935 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1936 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001937 break;
1938 default:
1939 return -EINVAL;
1940 }
1941 break;
1942 case AH_ESP_V4_FLOW:
1943 case AH_V4_FLOW:
1944 case ESP_V4_FLOW:
1945 case SCTP_V4_FLOW:
1946 if ((nfc->data & RXH_L4_B_0_1) ||
1947 (nfc->data & RXH_L4_B_2_3))
1948 return -EINVAL;
1949 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1950 break;
1951 case AH_ESP_V6_FLOW:
1952 case AH_V6_FLOW:
1953 case ESP_V6_FLOW:
1954 case SCTP_V6_FLOW:
1955 if ((nfc->data & RXH_L4_B_0_1) ||
1956 (nfc->data & RXH_L4_B_2_3))
1957 return -EINVAL;
1958 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1959 break;
1960 case IPV4_FLOW:
1961 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1962 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1963 break;
1964 case IPV6_FLOW:
1965 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1966 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1967 break;
1968 default:
1969 return -EINVAL;
1970 }
1971
1972 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1973 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1974 i40e_flush(hw);
1975
1976 return 0;
1977}
1978
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001979/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001980 * i40e_match_fdir_input_set - Match a new filter against an existing one
1981 * @rule: The filter already added
1982 * @input: The new filter to comapre against
1983 *
1984 * Returns true if the two input set match
1985 **/
1986static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1987 struct i40e_fdir_filter *input)
1988{
1989 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1990 (rule->src_ip[0] != input->src_ip[0]) ||
1991 (rule->dst_port != input->dst_port) ||
1992 (rule->src_port != input->src_port))
1993 return false;
1994 return true;
1995}
1996
1997/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001998 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1999 * @vsi: Pointer to the targeted VSI
2000 * @input: The filter to update or NULL to indicate deletion
2001 * @sw_idx: Software index to the filter
2002 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002003 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002004 * This function updates (or deletes) a Flow Director entry from
2005 * the hlist of the corresponding PF
2006 *
2007 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002008 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002009static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2010 struct i40e_fdir_filter *input,
2011 u16 sw_idx,
2012 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002013{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002014 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002015 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002016 struct hlist_node *node2;
2017 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002018
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002019 parent = NULL;
2020 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002021
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002022 hlist_for_each_entry_safe(rule, node2,
2023 &pf->fdir_filter_list, fdir_node) {
2024 /* hash found, or no matching entry */
2025 if (rule->fd_id >= sw_idx)
2026 break;
2027 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002028 }
2029
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002030 /* if there is an old rule occupying our place remove it */
2031 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002032 if (input && !i40e_match_fdir_input_set(rule, input))
2033 err = i40e_add_del_fdir(vsi, rule, false);
2034 else if (!input)
2035 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002036 hlist_del(&rule->fdir_node);
2037 kfree(rule);
2038 pf->fdir_pf_active_filters--;
2039 }
2040
2041 /* If no input this was a delete, err should be 0 if a rule was
2042 * successfully found and removed from the list else -EINVAL
2043 */
2044 if (!input)
2045 return err;
2046
2047 /* initialize node and set software index */
2048 INIT_HLIST_NODE(&input->fdir_node);
2049
2050 /* add filter to the list */
2051 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002052 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002053 else
2054 hlist_add_head(&input->fdir_node,
2055 &pf->fdir_filter_list);
2056
2057 /* update counts */
2058 pf->fdir_pf_active_filters++;
2059
2060 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002061}
2062
2063/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002064 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2065 * @vsi: Pointer to the targeted VSI
2066 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002067 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002068 * The function removes a Flow Director filter entry from the
2069 * hlist of the corresponding PF
2070 *
2071 * Returns 0 on success
2072 */
2073static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2074 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002075{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002076 struct ethtool_rx_flow_spec *fsp =
2077 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002078 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002079 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002080
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002081 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2082 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2083 return -EBUSY;
2084
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002085 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2086 return -EBUSY;
2087
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002088 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002089
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002090 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002091 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002092}
2093
2094/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002095 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002096 * @vsi: pointer to the targeted VSI
2097 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002098 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002099 * Add Flow Director filters for a specific flow spec based on their
2100 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002101 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002102static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2103 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002104{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002105 struct ethtool_rx_flow_spec *fsp;
2106 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002107 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002108 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002109
2110 if (!vsi)
2111 return -EINVAL;
2112
2113 pf = vsi->back;
2114
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002115 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2116 return -EOPNOTSUPP;
2117
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002118 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002119 return -ENOSPC;
2120
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002121 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2122 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2123 return -EBUSY;
2124
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002125 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2126 return -EBUSY;
2127
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002128 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2129
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002130 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2131 pf->hw.func_caps.fd_filters_guaranteed)) {
2132 return -EINVAL;
2133 }
2134
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002135 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2136 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002137 return -EINVAL;
2138
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002139 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002140
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002141 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002142 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002143
2144 input->fd_id = fsp->location;
2145
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002146 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2147 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2148 else
2149 input->dest_ctl =
2150 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2151
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002152 input->q_index = fsp->ring_cookie;
2153 input->flex_off = 0;
2154 input->pctype = 0;
2155 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002156 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00002157 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002158 input->flow_type = fsp->flow_type;
2159 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002160
2161 /* Reverse the src and dest notion, since the HW expects them to be from
2162 * Tx perspective where as the input from user is from Rx filter view.
2163 */
2164 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2165 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2166 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2167 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002168
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002169 ret = i40e_add_del_fdir(vsi, input, true);
2170 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002171 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002172 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002173 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002174
2175 return ret;
2176}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002177
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002178/**
2179 * i40e_set_rxnfc - command to set RX flow classification rules
2180 * @netdev: network interface device structure
2181 * @cmd: ethtool rxnfc command
2182 *
2183 * Returns Success if the command is supported.
2184 **/
2185static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2186{
2187 struct i40e_netdev_priv *np = netdev_priv(netdev);
2188 struct i40e_vsi *vsi = np->vsi;
2189 struct i40e_pf *pf = vsi->back;
2190 int ret = -EOPNOTSUPP;
2191
2192 switch (cmd->cmd) {
2193 case ETHTOOL_SRXFH:
2194 ret = i40e_set_rss_hash_opt(pf, cmd);
2195 break;
2196 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002197 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002198 break;
2199 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002200 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002201 break;
2202 default:
2203 break;
2204 }
2205
2206 return ret;
2207}
2208
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002209/**
2210 * i40e_max_channels - get Max number of combined channels supported
2211 * @vsi: vsi pointer
2212 **/
2213static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2214{
2215 /* TODO: This code assumes DCB and FD is disabled for now. */
2216 return vsi->alloc_queue_pairs;
2217}
2218
2219/**
2220 * i40e_get_channels - Get the current channels enabled and max supported etc.
2221 * @netdev: network interface device structure
2222 * @ch: ethtool channels structure
2223 *
2224 * We don't support separate tx and rx queues as channels. The other count
2225 * represents how many queues are being used for control. max_combined counts
2226 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2227 * q_vectors since we support a lot more queue pairs than q_vectors.
2228 **/
2229static void i40e_get_channels(struct net_device *dev,
2230 struct ethtool_channels *ch)
2231{
2232 struct i40e_netdev_priv *np = netdev_priv(dev);
2233 struct i40e_vsi *vsi = np->vsi;
2234 struct i40e_pf *pf = vsi->back;
2235
2236 /* report maximum channels */
2237 ch->max_combined = i40e_max_channels(vsi);
2238
2239 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002240 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002241 ch->max_other = ch->other_count;
2242
2243 /* Note: This code assumes DCB is disabled for now. */
2244 ch->combined_count = vsi->num_queue_pairs;
2245}
2246
2247/**
2248 * i40e_set_channels - Set the new channels count.
2249 * @netdev: network interface device structure
2250 * @ch: ethtool channels structure
2251 *
2252 * The new channels count may not be the same as requested by the user
2253 * since it gets rounded down to a power of 2 value.
2254 **/
2255static int i40e_set_channels(struct net_device *dev,
2256 struct ethtool_channels *ch)
2257{
2258 struct i40e_netdev_priv *np = netdev_priv(dev);
2259 unsigned int count = ch->combined_count;
2260 struct i40e_vsi *vsi = np->vsi;
2261 struct i40e_pf *pf = vsi->back;
2262 int new_count;
2263
2264 /* We do not support setting channels for any other VSI at present */
2265 if (vsi->type != I40E_VSI_MAIN)
2266 return -EINVAL;
2267
2268 /* verify they are not requesting separate vectors */
2269 if (!count || ch->rx_count || ch->tx_count)
2270 return -EINVAL;
2271
2272 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002273 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002274 return -EINVAL;
2275
2276 /* verify the number of channels does not exceed hardware limits */
2277 if (count > i40e_max_channels(vsi))
2278 return -EINVAL;
2279
2280 /* update feature limits from largest to smallest supported values */
2281 /* TODO: Flow director limit, DCB etc */
2282
2283 /* cap RSS limit */
2284 if (count > pf->rss_size_max)
2285 count = pf->rss_size_max;
2286
2287 /* use rss_reconfig to rebuild with new queue count and update traffic
2288 * class queue mapping
2289 */
2290 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002291 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002292 return 0;
2293 else
2294 return -EINVAL;
2295}
2296
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002297static const struct ethtool_ops i40e_ethtool_ops = {
2298 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002299 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002300 .get_drvinfo = i40e_get_drvinfo,
2301 .get_regs_len = i40e_get_regs_len,
2302 .get_regs = i40e_get_regs,
2303 .nway_reset = i40e_nway_reset,
2304 .get_link = ethtool_op_get_link,
2305 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002306 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002307 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002308 .get_eeprom_len = i40e_get_eeprom_len,
2309 .get_eeprom = i40e_get_eeprom,
2310 .get_ringparam = i40e_get_ringparam,
2311 .set_ringparam = i40e_set_ringparam,
2312 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002313 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002314 .get_msglevel = i40e_get_msglevel,
2315 .set_msglevel = i40e_set_msglevel,
2316 .get_rxnfc = i40e_get_rxnfc,
2317 .set_rxnfc = i40e_set_rxnfc,
2318 .self_test = i40e_diag_test,
2319 .get_strings = i40e_get_strings,
2320 .set_phys_id = i40e_set_phys_id,
2321 .get_sset_count = i40e_get_sset_count,
2322 .get_ethtool_stats = i40e_get_ethtool_stats,
2323 .get_coalesce = i40e_get_coalesce,
2324 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002325 .get_channels = i40e_get_channels,
2326 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002327 .get_ts_info = i40e_get_ts_info,
2328};
2329
2330void i40e_set_ethtool_ops(struct net_device *netdev)
2331{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002332 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002333}