blob: 571d527e7920754be4d796ff5f9b16996abb260e [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}
43#define I40E_NETDEV_STAT(_net_stat) \
44 I40E_STAT(struct net_device_stats, #_net_stat, _net_stat)
45#define I40E_PF_STAT(_name, _stat) \
46 I40E_STAT(struct i40e_pf, _name, _stat)
47#define I40E_VSI_STAT(_name, _stat) \
48 I40E_STAT(struct i40e_vsi, _name, _stat)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000049#define I40E_VEB_STAT(_name, _stat) \
50 I40E_STAT(struct i40e_veb, _name, _stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000051
52static const struct i40e_stats i40e_gstrings_net_stats[] = {
53 I40E_NETDEV_STAT(rx_packets),
54 I40E_NETDEV_STAT(tx_packets),
55 I40E_NETDEV_STAT(rx_bytes),
56 I40E_NETDEV_STAT(tx_bytes),
57 I40E_NETDEV_STAT(rx_errors),
58 I40E_NETDEV_STAT(tx_errors),
59 I40E_NETDEV_STAT(rx_dropped),
60 I40E_NETDEV_STAT(tx_dropped),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000061 I40E_NETDEV_STAT(collisions),
62 I40E_NETDEV_STAT(rx_length_errors),
63 I40E_NETDEV_STAT(rx_crc_errors),
64};
65
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000066static const struct i40e_stats i40e_gstrings_veb_stats[] = {
67 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
68 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
69 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
70 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
71 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
72 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
73 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
74 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
75 I40E_VEB_STAT("rx_discards", stats.rx_discards),
76 I40E_VEB_STAT("tx_discards", stats.tx_discards),
77 I40E_VEB_STAT("tx_errors", stats.tx_errors),
78 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
79};
80
Shannon Nelson41a9e552014-04-23 04:50:20 +000081static const struct i40e_stats i40e_gstrings_misc_stats[] = {
Shannon Nelson418631d2014-04-23 04:50:07 +000082 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
83 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
84 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
85 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
Shannon Nelson41a9e552014-04-23 04:50:20 +000086 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
87 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
Shannon Nelson418631d2014-04-23 04:50:07 +000088 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
Shannon Nelson41a9e552014-04-23 04:50:20 +000089};
90
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +000091static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
92 struct ethtool_rxnfc *cmd);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +000093
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000094/* These PF_STATs might look like duplicates of some NETDEV_STATs,
95 * but they are separate. This device supports Virtualization, and
96 * as such might have several netdevs supporting VMDq and FCoE going
97 * through a single port. The NETDEV_STATs are for individual netdevs
98 * seen at the top of the stack, and the PF_STATs are for the physical
99 * function at the bottom of the stack hosting those netdevs.
100 *
101 * The PF_STATs are appended to the netdev stats only when ethtool -S
102 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
103 */
104static struct i40e_stats i40e_gstrings_stats[] = {
105 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
106 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000107 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
108 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
109 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
110 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
111 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
112 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000113 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
114 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
115 I40E_PF_STAT("tx_dropped", stats.eth.tx_discards),
116 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/**
221 * i40e_get_settings - Get Link Speed and Duplex settings
222 * @netdev: network interface device structure
223 * @ecmd: ethtool command
224 *
225 * Reports speed/duplex settings based on media_type
226 **/
227static int i40e_get_settings(struct net_device *netdev,
228 struct ethtool_cmd *ecmd)
229{
230 struct i40e_netdev_priv *np = netdev_priv(netdev);
231 struct i40e_pf *pf = np->vsi->back;
232 struct i40e_hw *hw = &pf->hw;
233 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
234 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
235 u32 link_speed = hw_link_info->link_speed;
236
237 /* hardware is either in 40G mode or 10G mode
238 * NOTE: this section initializes supported and advertising
239 */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000240 if (!link_up) {
241 /* link is down and the driver needs to fall back on
242 * device ID to determine what kinds of info to display,
243 * it's mostly a guess that may change when link is up
244 */
245 switch (hw->device_id) {
246 case I40E_DEV_ID_QSFP_A:
247 case I40E_DEV_ID_QSFP_B:
248 case I40E_DEV_ID_QSFP_C:
249 /* pluggable QSFP */
250 ecmd->supported = SUPPORTED_40000baseSR4_Full |
251 SUPPORTED_40000baseCR4_Full |
252 SUPPORTED_40000baseLR4_Full;
253 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
254 ADVERTISED_40000baseCR4_Full |
255 ADVERTISED_40000baseLR4_Full;
256 break;
257 case I40E_DEV_ID_KX_B:
258 /* backplane 40G */
259 ecmd->supported = SUPPORTED_40000baseKR4_Full;
260 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
261 break;
262 case I40E_DEV_ID_KX_C:
263 /* backplane 10G */
264 ecmd->supported = SUPPORTED_10000baseKR_Full;
265 ecmd->advertising = ADVERTISED_10000baseKR_Full;
266 break;
267 default:
268 /* all the rest are 10G/1G */
269 ecmd->supported = SUPPORTED_10000baseT_Full |
270 SUPPORTED_1000baseT_Full;
271 ecmd->advertising = ADVERTISED_10000baseT_Full |
272 ADVERTISED_1000baseT_Full;
273 break;
274 }
275
276 /* skip phy_type use as it is zero when link is down */
277 goto no_valid_phy_type;
278 }
279
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000280 switch (hw_link_info->phy_type) {
281 case I40E_PHY_TYPE_40GBASE_CR4:
282 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000283 ecmd->supported = SUPPORTED_Autoneg |
284 SUPPORTED_40000baseCR4_Full;
285 ecmd->advertising = ADVERTISED_Autoneg |
286 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000287 break;
288 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000289 ecmd->supported = SUPPORTED_Autoneg |
290 SUPPORTED_40000baseKR4_Full;
291 ecmd->advertising = ADVERTISED_Autoneg |
292 ADVERTISED_40000baseKR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000293 break;
294 case I40E_PHY_TYPE_40GBASE_SR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000295 case I40E_PHY_TYPE_XLPPI:
296 case I40E_PHY_TYPE_XLAUI:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000297 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000298 break;
299 case I40E_PHY_TYPE_40GBASE_LR4:
300 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000301 break;
302 case I40E_PHY_TYPE_10GBASE_KX4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000303 ecmd->supported = SUPPORTED_Autoneg |
304 SUPPORTED_10000baseKX4_Full;
305 ecmd->advertising = ADVERTISED_Autoneg |
306 ADVERTISED_10000baseKX4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000307 break;
308 case I40E_PHY_TYPE_10GBASE_KR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000309 ecmd->supported = SUPPORTED_Autoneg |
310 SUPPORTED_10000baseKR_Full;
311 ecmd->advertising = ADVERTISED_Autoneg |
312 ADVERTISED_10000baseKR_Full;
313 break;
314 case I40E_PHY_TYPE_10GBASE_SR:
315 case I40E_PHY_TYPE_10GBASE_LR:
316 ecmd->supported = SUPPORTED_10000baseT_Full;
317 break;
318 case I40E_PHY_TYPE_10GBASE_CR1_CU:
319 case I40E_PHY_TYPE_10GBASE_CR1:
320 case I40E_PHY_TYPE_10GBASE_T:
321 ecmd->supported = SUPPORTED_Autoneg |
322 SUPPORTED_10000baseT_Full;
323 ecmd->advertising = ADVERTISED_Autoneg |
324 ADVERTISED_10000baseT_Full;
325 break;
326 case I40E_PHY_TYPE_XAUI:
327 case I40E_PHY_TYPE_XFI:
328 case I40E_PHY_TYPE_SFI:
329 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
330 ecmd->supported = SUPPORTED_10000baseT_Full;
331 break;
332 case I40E_PHY_TYPE_1000BASE_KX:
333 case I40E_PHY_TYPE_1000BASE_T:
334 ecmd->supported = SUPPORTED_Autoneg |
335 SUPPORTED_1000baseT_Full;
336 ecmd->advertising = ADVERTISED_Autoneg |
337 ADVERTISED_1000baseT_Full;
338 break;
339 case I40E_PHY_TYPE_100BASE_TX:
340 ecmd->supported = SUPPORTED_Autoneg |
341 SUPPORTED_100baseT_Full;
342 ecmd->advertising = ADVERTISED_Autoneg |
343 ADVERTISED_100baseT_Full;
344 break;
345 case I40E_PHY_TYPE_SGMII:
346 ecmd->supported = SUPPORTED_Autoneg |
347 SUPPORTED_1000baseT_Full |
348 SUPPORTED_100baseT_Full;
349 ecmd->advertising = ADVERTISED_Autoneg |
350 ADVERTISED_1000baseT_Full |
351 ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000352 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000353 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000354 /* if we got here and link is up something bad is afoot */
355 WARN_ON(link_up);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000356 }
357
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000358no_valid_phy_type:
359 /* this is if autoneg is enabled or disabled */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000360 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
361 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000362
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000363 switch (hw->phy.media_type) {
364 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000365 ecmd->supported |= SUPPORTED_Autoneg |
366 SUPPORTED_Backplane;
367 ecmd->advertising |= ADVERTISED_Autoneg |
368 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000369 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000370 break;
371 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000372 ecmd->supported |= SUPPORTED_TP;
373 ecmd->advertising |= ADVERTISED_TP;
374 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000375 break;
376 case I40E_MEDIA_TYPE_DA:
377 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000378 ecmd->supported |= SUPPORTED_FIBRE;
379 ecmd->advertising |= ADVERTISED_FIBRE;
380 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000381 break;
382 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000383 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000384 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000385 break;
386 case I40E_MEDIA_TYPE_UNKNOWN:
387 default:
388 ecmd->port = PORT_OTHER;
389 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000390 }
391
392 ecmd->transceiver = XCVR_EXTERNAL;
393
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000394 ecmd->supported |= SUPPORTED_Pause;
395
396 switch (hw->fc.current_mode) {
397 case I40E_FC_FULL:
398 ecmd->advertising |= ADVERTISED_Pause;
399 break;
400 case I40E_FC_TX_PAUSE:
401 ecmd->advertising |= ADVERTISED_Asym_Pause;
402 break;
403 case I40E_FC_RX_PAUSE:
404 ecmd->advertising |= (ADVERTISED_Pause |
405 ADVERTISED_Asym_Pause);
406 break;
407 default:
408 ecmd->advertising &= ~(ADVERTISED_Pause |
409 ADVERTISED_Asym_Pause);
410 break;
411 }
412
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000413 if (link_up) {
414 switch (link_speed) {
415 case I40E_LINK_SPEED_40GB:
416 /* need a SPEED_40000 in ethtool.h */
417 ethtool_cmd_speed_set(ecmd, 40000);
418 break;
419 case I40E_LINK_SPEED_10GB:
420 ethtool_cmd_speed_set(ecmd, SPEED_10000);
421 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000422 case I40E_LINK_SPEED_1GB:
423 ethtool_cmd_speed_set(ecmd, SPEED_1000);
424 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000425 default:
426 break;
427 }
428 ecmd->duplex = DUPLEX_FULL;
429 } else {
430 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
431 ecmd->duplex = DUPLEX_UNKNOWN;
432 }
433
434 return 0;
435}
436
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000437/**
438 * i40e_set_settings - Set Speed and Duplex
439 * @netdev: network interface device structure
440 * @ecmd: ethtool command
441 *
442 * Set speed/duplex per media_types advertised/forced
443 **/
444static int i40e_set_settings(struct net_device *netdev,
445 struct ethtool_cmd *ecmd)
446{
447 struct i40e_netdev_priv *np = netdev_priv(netdev);
448 struct i40e_aq_get_phy_abilities_resp abilities;
449 struct i40e_aq_set_phy_config config;
450 struct i40e_pf *pf = np->vsi->back;
451 struct i40e_vsi *vsi = np->vsi;
452 struct i40e_hw *hw = &pf->hw;
453 struct ethtool_cmd safe_ecmd;
454 i40e_status status = 0;
455 bool change = false;
456 int err = 0;
457 u8 autoneg;
458 u32 advertise;
459
460 if (vsi != pf->vsi[pf->lan_vsi])
461 return -EOPNOTSUPP;
462
463 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
464 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
465 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE)
466 return -EOPNOTSUPP;
467
468 /* get our own copy of the bits to check against */
469 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
470 i40e_get_settings(netdev, &safe_ecmd);
471
472 /* save autoneg and speed out of ecmd */
473 autoneg = ecmd->autoneg;
474 advertise = ecmd->advertising;
475
476 /* set autoneg and speed back to what they currently are */
477 ecmd->autoneg = safe_ecmd.autoneg;
478 ecmd->advertising = safe_ecmd.advertising;
479
480 ecmd->cmd = safe_ecmd.cmd;
481 /* If ecmd and safe_ecmd are not the same now, then they are
482 * trying to set something that we do not support
483 */
484 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
485 return -EOPNOTSUPP;
486
487 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
488 usleep_range(1000, 2000);
489
490 /* Get the current phy config */
491 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
492 NULL);
493 if (status)
494 return -EAGAIN;
495
496 /* Copy link_speed and abilities to config in case they are not
497 * set below
498 */
499 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
500 config.link_speed = abilities.link_speed;
501 config.abilities = abilities.abilities;
502
503 /* Check autoneg */
504 if (autoneg == AUTONEG_ENABLE) {
505 /* If autoneg is not supported, return error */
506 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
507 netdev_info(netdev, "Autoneg not supported on this phy\n");
508 return -EINVAL;
509 }
510 /* If autoneg was not already enabled */
511 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
512 config.abilities = abilities.abilities |
513 I40E_AQ_PHY_ENABLE_AN;
514 change = true;
515 }
516 } else {
517 /* If autoneg is supported 10GBASE_T is the only phy that
518 * can disable it, so otherwise return error
519 */
520 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
521 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
522 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
523 return -EINVAL;
524 }
525 /* If autoneg is currently enabled */
526 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
527 config.abilities = abilities.abilities |
528 ~I40E_AQ_PHY_ENABLE_AN;
529 change = true;
530 }
531 }
532
533 if (advertise & ~safe_ecmd.supported)
534 return -EINVAL;
535
536 if (advertise & ADVERTISED_100baseT_Full)
537 if (!(abilities.link_speed & I40E_LINK_SPEED_100MB)) {
538 config.link_speed |= I40E_LINK_SPEED_100MB;
539 change = true;
540 }
541 if (advertise & ADVERTISED_1000baseT_Full ||
542 advertise & ADVERTISED_1000baseKX_Full)
543 if (!(abilities.link_speed & I40E_LINK_SPEED_1GB)) {
544 config.link_speed |= I40E_LINK_SPEED_1GB;
545 change = true;
546 }
547 if (advertise & ADVERTISED_10000baseT_Full ||
548 advertise & ADVERTISED_10000baseKX4_Full ||
549 advertise & ADVERTISED_10000baseKR_Full)
550 if (!(abilities.link_speed & I40E_LINK_SPEED_10GB)) {
551 config.link_speed |= I40E_LINK_SPEED_10GB;
552 change = true;
553 }
554 if (advertise & ADVERTISED_40000baseKR4_Full ||
555 advertise & ADVERTISED_40000baseCR4_Full ||
556 advertise & ADVERTISED_40000baseSR4_Full ||
557 advertise & ADVERTISED_40000baseLR4_Full)
558 if (!(abilities.link_speed & I40E_LINK_SPEED_40GB)) {
559 config.link_speed |= I40E_LINK_SPEED_40GB;
560 change = true;
561 }
562
563 if (change) {
564 /* copy over the rest of the abilities */
565 config.phy_type = abilities.phy_type;
566 config.eee_capability = abilities.eee_capability;
567 config.eeer = abilities.eeer_val;
568 config.low_power_ctrl = abilities.d3_lpan;
569
570 /* If link is up set link and an so changes take effect */
571 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
572 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
573
574 /* make the aq call */
575 status = i40e_aq_set_phy_config(hw, &config, NULL);
576 if (status) {
577 netdev_info(netdev, "Set phy config failed with error %d.\n",
578 status);
579 return -EAGAIN;
580 }
581
582 status = i40e_update_link_info(hw, true);
583 if (status)
584 netdev_info(netdev, "Updating link info failed with error %d\n",
585 status);
586
587 } else {
588 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
589 }
590
591 return err;
592}
593
Jesse Brandeburga6599722014-06-04 08:45:25 +0000594static int i40e_nway_reset(struct net_device *netdev)
595{
596 /* restart autonegotiation */
597 struct i40e_netdev_priv *np = netdev_priv(netdev);
598 struct i40e_pf *pf = np->vsi->back;
599 struct i40e_hw *hw = &pf->hw;
600 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
601 i40e_status ret = 0;
602
603 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
604 if (ret) {
605 netdev_info(netdev, "link restart failed, aq_err=%d\n",
606 pf->hw.aq.asq_last_status);
607 return -EIO;
608 }
609
610 return 0;
611}
612
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000613/**
614 * i40e_get_pauseparam - Get Flow Control status
615 * Return tx/rx-pause status
616 **/
617static void i40e_get_pauseparam(struct net_device *netdev,
618 struct ethtool_pauseparam *pause)
619{
620 struct i40e_netdev_priv *np = netdev_priv(netdev);
621 struct i40e_pf *pf = np->vsi->back;
622 struct i40e_hw *hw = &pf->hw;
623 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
624
625 pause->autoneg =
626 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
627 AUTONEG_ENABLE : AUTONEG_DISABLE);
628
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000629 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000630 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000631 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000632 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000633 } else if (hw->fc.current_mode == I40E_FC_FULL) {
634 pause->rx_pause = 1;
635 pause->tx_pause = 1;
636 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000637}
638
Catherine Sullivan2becc352014-06-04 08:45:27 +0000639/**
640 * i40e_set_pauseparam - Set Flow Control parameter
641 * @netdev: network interface device structure
642 * @pause: return tx/rx flow control status
643 **/
644static int i40e_set_pauseparam(struct net_device *netdev,
645 struct ethtool_pauseparam *pause)
646{
647 struct i40e_netdev_priv *np = netdev_priv(netdev);
648 struct i40e_pf *pf = np->vsi->back;
649 struct i40e_vsi *vsi = np->vsi;
650 struct i40e_hw *hw = &pf->hw;
651 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
652 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
653 i40e_status status;
654 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000655 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000656
657 if (vsi != pf->vsi[pf->lan_vsi])
658 return -EOPNOTSUPP;
659
660 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
661 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
662 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
663 return -EOPNOTSUPP;
664 }
665
666 /* If we have link and don't have autoneg */
667 if (!test_bit(__I40E_DOWN, &pf->state) &&
668 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
669 /* Send message that it might not necessarily work*/
670 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
671 }
672
673 if (hw->fc.current_mode == I40E_FC_PFC) {
674 netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
675 return -EOPNOTSUPP;
676 }
677
678 if (pause->rx_pause && pause->tx_pause)
679 hw->fc.requested_mode = I40E_FC_FULL;
680 else if (pause->rx_pause && !pause->tx_pause)
681 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
682 else if (!pause->rx_pause && pause->tx_pause)
683 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
684 else if (!pause->rx_pause && !pause->tx_pause)
685 hw->fc.requested_mode = I40E_FC_NONE;
686 else
687 return -EINVAL;
688
689 /* Set the fc mode and only restart an if link is up*/
690 status = i40e_set_fc(hw, &aq_failures, link_up);
691
692 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
693 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
694 status, hw->aq.asq_last_status);
695 err = -EAGAIN;
696 }
697 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
698 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
699 status, hw->aq.asq_last_status);
700 err = -EAGAIN;
701 }
702 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
703 netdev_info(netdev, "Set fc failed on the update_link_info call with error %d and status %d\n",
704 status, hw->aq.asq_last_status);
705 err = -EAGAIN;
706 }
707
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000708 if (!test_bit(__I40E_DOWN, &pf->state)) {
709 /* Give it a little more time to try to come back */
710 msleep(75);
711 if (!test_bit(__I40E_DOWN, &pf->state))
712 return i40e_nway_reset(netdev);
713 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000714
715 return err;
716}
717
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000718static u32 i40e_get_msglevel(struct net_device *netdev)
719{
720 struct i40e_netdev_priv *np = netdev_priv(netdev);
721 struct i40e_pf *pf = np->vsi->back;
722
723 return pf->msg_enable;
724}
725
726static void i40e_set_msglevel(struct net_device *netdev, u32 data)
727{
728 struct i40e_netdev_priv *np = netdev_priv(netdev);
729 struct i40e_pf *pf = np->vsi->back;
730
731 if (I40E_DEBUG_USER & data)
732 pf->hw.debug_mask = data;
733 pf->msg_enable = data;
734}
735
736static int i40e_get_regs_len(struct net_device *netdev)
737{
738 int reg_count = 0;
739 int i;
740
741 for (i = 0; i40e_reg_list[i].offset != 0; i++)
742 reg_count += i40e_reg_list[i].elements;
743
744 return reg_count * sizeof(u32);
745}
746
747static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
748 void *p)
749{
750 struct i40e_netdev_priv *np = netdev_priv(netdev);
751 struct i40e_pf *pf = np->vsi->back;
752 struct i40e_hw *hw = &pf->hw;
753 u32 *reg_buf = p;
754 int i, j, ri;
755 u32 reg;
756
757 /* Tell ethtool which driver-version-specific regs output we have.
758 *
759 * At some point, if we have ethtool doing special formatting of
760 * this data, it will rely on this version number to know how to
761 * interpret things. Hence, this needs to be updated if/when the
762 * diags register table is changed.
763 */
764 regs->version = 1;
765
766 /* loop through the diags reg table for what to print */
767 ri = 0;
768 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
769 for (j = 0; j < i40e_reg_list[i].elements; j++) {
770 reg = i40e_reg_list[i].offset
771 + (j * i40e_reg_list[i].stride);
772 reg_buf[ri++] = rd32(hw, reg);
773 }
774 }
775
776}
777
778static int i40e_get_eeprom(struct net_device *netdev,
779 struct ethtool_eeprom *eeprom, u8 *bytes)
780{
781 struct i40e_netdev_priv *np = netdev_priv(netdev);
782 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000783 struct i40e_pf *pf = np->vsi->back;
784 int ret_val = 0, len;
785 u8 *eeprom_buff;
786 u16 i, sectors;
787 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000788 u32 magic;
789
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000790#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000791 if (eeprom->len == 0)
792 return -EINVAL;
793
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000794 /* check for NVMUpdate access method */
795 magic = hw->vendor_id | (hw->device_id << 16);
796 if (eeprom->magic && eeprom->magic != magic) {
797 int errno;
798
799 /* make sure it is the right magic for NVMUpdate */
800 if ((eeprom->magic >> 16) != hw->device_id)
801 return -EINVAL;
802
803 ret_val = i40e_nvmupd_command(hw,
804 (struct i40e_nvm_access *)eeprom,
805 bytes, &errno);
806 if (ret_val)
807 dev_info(&pf->pdev->dev,
808 "NVMUpdate read failed err=%d status=0x%x\n",
809 ret_val, hw->aq.asq_last_status);
810
811 return errno;
812 }
813
814 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000815 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
816
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000817 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000818 if (!eeprom_buff)
819 return -ENOMEM;
820
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000821 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
822 if (ret_val) {
823 dev_info(&pf->pdev->dev,
824 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
825 ret_val, hw->aq.asq_last_status);
826 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000827 }
828
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000829 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
830 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
831 len = I40E_NVM_SECTOR_SIZE;
832 last = false;
833 for (i = 0; i < sectors; i++) {
834 if (i == (sectors - 1)) {
835 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
836 last = true;
837 }
838 ret_val = i40e_aq_read_nvm(hw, 0x0,
839 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
840 len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000841 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000842 last, NULL);
843 if (ret_val) {
844 dev_info(&pf->pdev->dev,
845 "read NVM failed err=%d status=0x%x\n",
846 ret_val, hw->aq.asq_last_status);
847 goto release_nvm;
848 }
849 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000850
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000851release_nvm:
852 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000853 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000854free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000855 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000856 return ret_val;
857}
858
859static int i40e_get_eeprom_len(struct net_device *netdev)
860{
861 struct i40e_netdev_priv *np = netdev_priv(netdev);
862 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000863 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000864
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000865 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
866 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
867 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
868 /* register returns value in power of 2, 64Kbyte chunks. */
869 val = (64 * 1024) * (1 << val);
870 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000871}
872
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000873static int i40e_set_eeprom(struct net_device *netdev,
874 struct ethtool_eeprom *eeprom, u8 *bytes)
875{
876 struct i40e_netdev_priv *np = netdev_priv(netdev);
877 struct i40e_hw *hw = &np->vsi->back->hw;
878 struct i40e_pf *pf = np->vsi->back;
879 int ret_val = 0;
880 int errno;
881 u32 magic;
882
883 /* normal ethtool set_eeprom is not supported */
884 magic = hw->vendor_id | (hw->device_id << 16);
885 if (eeprom->magic == magic)
886 return -EOPNOTSUPP;
887
888 /* check for NVMUpdate access method */
889 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
890 return -EINVAL;
891
892 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
893 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
894 return -EBUSY;
895
896 ret_val = i40e_nvmupd_command(hw, (struct i40e_nvm_access *)eeprom,
897 bytes, &errno);
898 if (ret_val)
899 dev_info(&pf->pdev->dev,
900 "NVMUpdate write failed err=%d status=0x%x\n",
901 ret_val, hw->aq.asq_last_status);
902
903 return errno;
904}
905
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000906static void i40e_get_drvinfo(struct net_device *netdev,
907 struct ethtool_drvinfo *drvinfo)
908{
909 struct i40e_netdev_priv *np = netdev_priv(netdev);
910 struct i40e_vsi *vsi = np->vsi;
911 struct i40e_pf *pf = vsi->back;
912
913 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
914 strlcpy(drvinfo->version, i40e_driver_version_str,
915 sizeof(drvinfo->version));
916 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
917 sizeof(drvinfo->fw_version));
918 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
919 sizeof(drvinfo->bus_info));
920}
921
922static void i40e_get_ringparam(struct net_device *netdev,
923 struct ethtool_ringparam *ring)
924{
925 struct i40e_netdev_priv *np = netdev_priv(netdev);
926 struct i40e_pf *pf = np->vsi->back;
927 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
928
929 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
930 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
931 ring->rx_mini_max_pending = 0;
932 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +0000933 ring->rx_pending = vsi->rx_rings[0]->count;
934 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000935 ring->rx_mini_pending = 0;
936 ring->rx_jumbo_pending = 0;
937}
938
939static int i40e_set_ringparam(struct net_device *netdev,
940 struct ethtool_ringparam *ring)
941{
942 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
943 struct i40e_netdev_priv *np = netdev_priv(netdev);
944 struct i40e_vsi *vsi = np->vsi;
945 struct i40e_pf *pf = vsi->back;
946 u32 new_rx_count, new_tx_count;
947 int i, err = 0;
948
949 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
950 return -EINVAL;
951
Shannon Nelson1fa18372013-11-20 10:03:08 +0000952 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
953 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
954 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
955 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
956 netdev_info(netdev,
957 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
958 ring->tx_pending, ring->rx_pending,
959 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
960 return -EINVAL;
961 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000962
Shannon Nelson1fa18372013-11-20 10:03:08 +0000963 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
964 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000965
966 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000967 if ((new_tx_count == vsi->tx_rings[0]->count) &&
968 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000969 return 0;
970
971 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
972 usleep_range(1000, 2000);
973
974 if (!netif_running(vsi->netdev)) {
975 /* simple case - set for the next time the netdev is started */
976 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000977 vsi->tx_rings[i]->count = new_tx_count;
978 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000979 }
980 goto done;
981 }
982
983 /* We can't just free everything and then setup again,
984 * because the ISRs in MSI-X mode get passed pointers
985 * to the Tx and Rx ring structs.
986 */
987
988 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000989 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000990 netdev_info(netdev,
991 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000992 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000993 tx_rings = kcalloc(vsi->alloc_queue_pairs,
994 sizeof(struct i40e_ring), GFP_KERNEL);
995 if (!tx_rings) {
996 err = -ENOMEM;
997 goto done;
998 }
999
1000 for (i = 0; i < vsi->num_queue_pairs; i++) {
1001 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001002 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001003 tx_rings[i].count = new_tx_count;
1004 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1005 if (err) {
1006 while (i) {
1007 i--;
1008 i40e_free_tx_resources(&tx_rings[i]);
1009 }
1010 kfree(tx_rings);
1011 tx_rings = NULL;
1012
1013 goto done;
1014 }
1015 }
1016 }
1017
1018 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001019 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001020 netdev_info(netdev,
1021 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001022 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001023 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1024 sizeof(struct i40e_ring), GFP_KERNEL);
1025 if (!rx_rings) {
1026 err = -ENOMEM;
1027 goto free_tx;
1028 }
1029
1030 for (i = 0; i < vsi->num_queue_pairs; i++) {
1031 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001032 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001033 rx_rings[i].count = new_rx_count;
1034 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1035 if (err) {
1036 while (i) {
1037 i--;
1038 i40e_free_rx_resources(&rx_rings[i]);
1039 }
1040 kfree(rx_rings);
1041 rx_rings = NULL;
1042
1043 goto free_tx;
1044 }
1045 }
1046 }
1047
1048 /* Bring interface down, copy in the new ring info,
1049 * then restore the interface
1050 */
1051 i40e_down(vsi);
1052
1053 if (tx_rings) {
1054 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001055 i40e_free_tx_resources(vsi->tx_rings[i]);
1056 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001057 }
1058 kfree(tx_rings);
1059 tx_rings = NULL;
1060 }
1061
1062 if (rx_rings) {
1063 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001064 i40e_free_rx_resources(vsi->rx_rings[i]);
1065 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001066 }
1067 kfree(rx_rings);
1068 rx_rings = NULL;
1069 }
1070
1071 i40e_up(vsi);
1072
1073free_tx:
1074 /* error cleanup if the Rx allocations failed after getting Tx */
1075 if (tx_rings) {
1076 for (i = 0; i < vsi->num_queue_pairs; i++)
1077 i40e_free_tx_resources(&tx_rings[i]);
1078 kfree(tx_rings);
1079 tx_rings = NULL;
1080 }
1081
1082done:
1083 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1084
1085 return err;
1086}
1087
1088static int i40e_get_sset_count(struct net_device *netdev, int sset)
1089{
1090 struct i40e_netdev_priv *np = netdev_priv(netdev);
1091 struct i40e_vsi *vsi = np->vsi;
1092 struct i40e_pf *pf = vsi->back;
1093
1094 switch (sset) {
1095 case ETH_SS_TEST:
1096 return I40E_TEST_LEN;
1097 case ETH_SS_STATS:
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001098 if (vsi == pf->vsi[pf->lan_vsi]) {
1099 int len = I40E_PF_STATS_LEN(netdev);
1100
1101 if (pf->lan_veb != I40E_NO_VEB)
1102 len += I40E_VEB_STATS_LEN;
1103 return len;
1104 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001105 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001106 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001107 default:
1108 return -EOPNOTSUPP;
1109 }
1110}
1111
1112static void i40e_get_ethtool_stats(struct net_device *netdev,
1113 struct ethtool_stats *stats, u64 *data)
1114{
1115 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001116 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001117 struct i40e_vsi *vsi = np->vsi;
1118 struct i40e_pf *pf = vsi->back;
1119 int i = 0;
1120 char *p;
1121 int j;
1122 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001123 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001124
1125 i40e_update_stats(vsi);
1126
1127 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1128 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1129 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1130 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1131 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001132 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1133 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1134 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1135 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1136 }
Vasu Dev38e00432014-08-01 13:27:03 -07001137#ifdef I40E_FCOE
1138 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1139 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1140 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1141 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1142 }
1143#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001144 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001145 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001146 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001147
1148 if (!tx_ring)
1149 continue;
1150
1151 /* process Tx ring statistics */
1152 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001153 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001154 data[i] = tx_ring->stats.packets;
1155 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001156 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001157 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001158
1159 /* Rx ring is the 2nd half of the queue pair */
1160 rx_ring = &tx_ring[1];
1161 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001162 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001163 data[i] = rx_ring->stats.packets;
1164 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001165 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001166 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001167 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001168 rcu_read_unlock();
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001169 if (vsi != pf->vsi[pf->lan_vsi])
1170 return;
1171
1172 if (pf->lan_veb != I40E_NO_VEB) {
1173 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1174 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1175 p = (char *)veb;
1176 p += i40e_gstrings_veb_stats[j].stat_offset;
1177 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1178 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001179 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001180 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001181 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1182 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1183 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1184 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1185 }
1186 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1187 data[i++] = pf->stats.priority_xon_tx[j];
1188 data[i++] = pf->stats.priority_xoff_tx[j];
1189 }
1190 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1191 data[i++] = pf->stats.priority_xon_rx[j];
1192 data[i++] = pf->stats.priority_xoff_rx[j];
1193 }
1194 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1195 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001196}
1197
1198static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1199 u8 *data)
1200{
1201 struct i40e_netdev_priv *np = netdev_priv(netdev);
1202 struct i40e_vsi *vsi = np->vsi;
1203 struct i40e_pf *pf = vsi->back;
1204 char *p = (char *)data;
1205 int i;
1206
1207 switch (stringset) {
1208 case ETH_SS_TEST:
1209 for (i = 0; i < I40E_TEST_LEN; i++) {
1210 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1211 data += ETH_GSTRING_LEN;
1212 }
1213 break;
1214 case ETH_SS_STATS:
1215 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1216 snprintf(p, ETH_GSTRING_LEN, "%s",
1217 i40e_gstrings_net_stats[i].stat_string);
1218 p += ETH_GSTRING_LEN;
1219 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001220 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1221 snprintf(p, ETH_GSTRING_LEN, "%s",
1222 i40e_gstrings_misc_stats[i].stat_string);
1223 p += ETH_GSTRING_LEN;
1224 }
Vasu Dev38e00432014-08-01 13:27:03 -07001225#ifdef I40E_FCOE
1226 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1227 snprintf(p, ETH_GSTRING_LEN, "%s",
1228 i40e_gstrings_fcoe_stats[i].stat_string);
1229 p += ETH_GSTRING_LEN;
1230 }
1231#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001232 for (i = 0; i < vsi->num_queue_pairs; i++) {
1233 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1234 p += ETH_GSTRING_LEN;
1235 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1236 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001237 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1238 p += ETH_GSTRING_LEN;
1239 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1240 p += ETH_GSTRING_LEN;
1241 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001242 if (vsi != pf->vsi[pf->lan_vsi])
1243 return;
1244
1245 if (pf->lan_veb != I40E_NO_VEB) {
1246 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1247 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1248 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001249 p += ETH_GSTRING_LEN;
1250 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001251 }
1252 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1253 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1254 i40e_gstrings_stats[i].stat_string);
1255 p += ETH_GSTRING_LEN;
1256 }
1257 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1258 snprintf(p, ETH_GSTRING_LEN,
1259 "port.tx_priority_%u_xon", i);
1260 p += ETH_GSTRING_LEN;
1261 snprintf(p, ETH_GSTRING_LEN,
1262 "port.tx_priority_%u_xoff", i);
1263 p += ETH_GSTRING_LEN;
1264 }
1265 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1266 snprintf(p, ETH_GSTRING_LEN,
1267 "port.rx_priority_%u_xon", i);
1268 p += ETH_GSTRING_LEN;
1269 snprintf(p, ETH_GSTRING_LEN,
1270 "port.rx_priority_%u_xoff", i);
1271 p += ETH_GSTRING_LEN;
1272 }
1273 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1274 snprintf(p, ETH_GSTRING_LEN,
1275 "port.rx_priority_%u_xon_2_xoff", i);
1276 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001277 }
1278 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1279 break;
1280 }
1281}
1282
1283static int i40e_get_ts_info(struct net_device *dev,
1284 struct ethtool_ts_info *info)
1285{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001286 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1287
1288 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1289 SOF_TIMESTAMPING_RX_SOFTWARE |
1290 SOF_TIMESTAMPING_SOFTWARE |
1291 SOF_TIMESTAMPING_TX_HARDWARE |
1292 SOF_TIMESTAMPING_RX_HARDWARE |
1293 SOF_TIMESTAMPING_RAW_HARDWARE;
1294
1295 if (pf->ptp_clock)
1296 info->phc_index = ptp_clock_index(pf->ptp_clock);
1297 else
1298 info->phc_index = -1;
1299
1300 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1301
1302 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1303 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1304 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1305 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1306 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1307 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1308 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1309 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1310 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1311 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1312 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1313 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1314
1315 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001316}
1317
Shannon Nelson7b086392013-11-20 10:02:59 +00001318static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001319{
Shannon Nelson7b086392013-11-20 10:02:59 +00001320 struct i40e_netdev_priv *np = netdev_priv(netdev);
1321 struct i40e_pf *pf = np->vsi->back;
1322
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001323 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001324 if (i40e_get_link_status(&pf->hw))
1325 *data = 0;
1326 else
1327 *data = 1;
1328
1329 return *data;
1330}
1331
Shannon Nelson7b086392013-11-20 10:02:59 +00001332static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001333{
Shannon Nelson7b086392013-11-20 10:02:59 +00001334 struct i40e_netdev_priv *np = netdev_priv(netdev);
1335 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001336
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001337 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001338 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001339
Shannon Nelson7b086392013-11-20 10:02:59 +00001340 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001341}
1342
Shannon Nelson7b086392013-11-20 10:02:59 +00001343static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001344{
Shannon Nelson7b086392013-11-20 10:02:59 +00001345 struct i40e_netdev_priv *np = netdev_priv(netdev);
1346 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001347
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001348 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001349 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001350
Shannon Nelson7b086392013-11-20 10:02:59 +00001351 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001352}
1353
Shannon Nelson7b086392013-11-20 10:02:59 +00001354static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001355{
Shannon Nelson7b086392013-11-20 10:02:59 +00001356 struct i40e_netdev_priv *np = netdev_priv(netdev);
1357 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001358 u16 swc_old = pf->sw_int_count;
1359
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001360 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001361 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1362 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
1363 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
1364 usleep_range(1000, 2000);
1365 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001366
1367 return *data;
1368}
1369
Shannon Nelson7b086392013-11-20 10:02:59 +00001370static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001371{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001372 struct i40e_netdev_priv *np = netdev_priv(netdev);
1373 struct i40e_pf *pf = np->vsi->back;
1374
1375 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001376 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001377
1378 return *data;
1379}
1380
1381static void i40e_diag_test(struct net_device *netdev,
1382 struct ethtool_test *eth_test, u64 *data)
1383{
1384 struct i40e_netdev_priv *np = netdev_priv(netdev);
1385 struct i40e_pf *pf = np->vsi->back;
1386
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001387 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1388 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001389 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001390
Shannon Nelsonf551b432013-11-26 10:49:12 +00001391 set_bit(__I40E_TESTING, &pf->state);
1392
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001393 /* Link test performed before hardware reset
1394 * so autoneg doesn't interfere with test result
1395 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001396 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001397 eth_test->flags |= ETH_TEST_FL_FAILED;
1398
Shannon Nelson7b086392013-11-20 10:02:59 +00001399 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001400 eth_test->flags |= ETH_TEST_FL_FAILED;
1401
Shannon Nelson7b086392013-11-20 10:02:59 +00001402 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001403 eth_test->flags |= ETH_TEST_FL_FAILED;
1404
Shannon Nelson7b086392013-11-20 10:02:59 +00001405 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001406 eth_test->flags |= ETH_TEST_FL_FAILED;
1407
Shannon Nelsonf551b432013-11-26 10:49:12 +00001408 /* run reg test last, a reset is required after it */
1409 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1410 eth_test->flags |= ETH_TEST_FL_FAILED;
1411
1412 clear_bit(__I40E_TESTING, &pf->state);
1413 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001414 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001415 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001416 netif_info(pf, drv, netdev, "online testing starting\n");
1417
Shannon Nelson7b086392013-11-20 10:02:59 +00001418 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001419 eth_test->flags |= ETH_TEST_FL_FAILED;
1420
1421 /* Offline only tests, not run in online; pass by default */
1422 data[I40E_ETH_TEST_REG] = 0;
1423 data[I40E_ETH_TEST_EEPROM] = 0;
1424 data[I40E_ETH_TEST_INTR] = 0;
1425 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001426 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001427
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001428 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001429}
1430
1431static void i40e_get_wol(struct net_device *netdev,
1432 struct ethtool_wolinfo *wol)
1433{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001434 struct i40e_netdev_priv *np = netdev_priv(netdev);
1435 struct i40e_pf *pf = np->vsi->back;
1436 struct i40e_hw *hw = &pf->hw;
1437 u16 wol_nvm_bits;
1438
1439 /* NVM bit on means WoL disabled for the port */
1440 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1441 if ((1 << hw->port) & wol_nvm_bits) {
1442 wol->supported = 0;
1443 wol->wolopts = 0;
1444 } else {
1445 wol->supported = WAKE_MAGIC;
1446 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1447 }
1448}
1449
1450static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1451{
1452 struct i40e_netdev_priv *np = netdev_priv(netdev);
1453 struct i40e_pf *pf = np->vsi->back;
1454 struct i40e_hw *hw = &pf->hw;
1455 u16 wol_nvm_bits;
1456
1457 /* NVM bit on means WoL disabled for the port */
1458 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1459 if (((1 << hw->port) & wol_nvm_bits))
1460 return -EOPNOTSUPP;
1461
1462 /* only magic packet is supported */
1463 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1464 return -EOPNOTSUPP;
1465
1466 /* is this a new value? */
1467 if (pf->wol_en != !!wol->wolopts) {
1468 pf->wol_en = !!wol->wolopts;
1469 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1470 }
1471
1472 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001473}
1474
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001475static int i40e_set_phys_id(struct net_device *netdev,
1476 enum ethtool_phys_id_state state)
1477{
1478 struct i40e_netdev_priv *np = netdev_priv(netdev);
1479 struct i40e_pf *pf = np->vsi->back;
1480 struct i40e_hw *hw = &pf->hw;
1481 int blink_freq = 2;
1482
1483 switch (state) {
1484 case ETHTOOL_ID_ACTIVE:
1485 pf->led_status = i40e_led_get(hw);
1486 return blink_freq;
1487 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001488 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001489 break;
1490 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001491 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001492 break;
1493 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001494 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001495 break;
1496 }
1497
1498 return 0;
1499}
1500
1501/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1502 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1503 * 125us (8000 interrupts per second) == ITR(62)
1504 */
1505
1506static int i40e_get_coalesce(struct net_device *netdev,
1507 struct ethtool_coalesce *ec)
1508{
1509 struct i40e_netdev_priv *np = netdev_priv(netdev);
1510 struct i40e_vsi *vsi = np->vsi;
1511
1512 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1513 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1514
1515 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001516 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001517
1518 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001519 ec->use_adaptive_tx_coalesce = 1;
1520
1521 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1522 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001523
1524 return 0;
1525}
1526
1527static int i40e_set_coalesce(struct net_device *netdev,
1528 struct ethtool_coalesce *ec)
1529{
1530 struct i40e_netdev_priv *np = netdev_priv(netdev);
1531 struct i40e_q_vector *q_vector;
1532 struct i40e_vsi *vsi = np->vsi;
1533 struct i40e_pf *pf = vsi->back;
1534 struct i40e_hw *hw = &pf->hw;
1535 u16 vector;
1536 int i;
1537
1538 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1539 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1540
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001541 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001542 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001543 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001544 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001545 } else if (ec->rx_coalesce_usecs == 0) {
1546 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1547 i40e_irq_dynamic_disable(vsi, vector);
1548 if (ec->use_adaptive_rx_coalesce)
1549 netif_info(pf, drv, netdev,
1550 "Rx-secs=0, need to disable adaptive-Rx for a complete disable\n");
1551 } else {
1552 netif_info(pf, drv, netdev,
1553 "Invalid value, Rx-usecs range is 0, 8-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001554 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001555 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001556
Mitch Williams32f5f542014-04-04 04:43:10 +00001557 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001558 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001559 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001560 } else if (ec->tx_coalesce_usecs == 0) {
1561 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1562 i40e_irq_dynamic_disable(vsi, vector);
1563 if (ec->use_adaptive_tx_coalesce)
1564 netif_info(pf, drv, netdev,
1565 "Tx-secs=0, need to disable adaptive-Tx for a complete disable\n");
1566 } else {
1567 netif_info(pf, drv, netdev,
1568 "Invalid value, Tx-usecs range is 0, 8-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001569 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001570 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001571
1572 if (ec->use_adaptive_rx_coalesce)
1573 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1574 else
1575 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1576
1577 if (ec->use_adaptive_tx_coalesce)
1578 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1579 else
1580 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001581
Alexander Duyck493fb302013-09-28 07:01:44 +00001582 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1583 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001584 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1585 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1586 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1587 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1588 i40e_flush(hw);
1589 }
1590
1591 return 0;
1592}
1593
1594/**
1595 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1596 * @pf: pointer to the physical function struct
1597 * @cmd: ethtool rxnfc command
1598 *
1599 * Returns Success if the flow is supported, else Invalid Input.
1600 **/
1601static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1602{
1603 cmd->data = 0;
1604
1605 /* Report default options for RSS on i40e */
1606 switch (cmd->flow_type) {
1607 case TCP_V4_FLOW:
1608 case UDP_V4_FLOW:
1609 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1610 /* fall through to add IP fields */
1611 case SCTP_V4_FLOW:
1612 case AH_ESP_V4_FLOW:
1613 case AH_V4_FLOW:
1614 case ESP_V4_FLOW:
1615 case IPV4_FLOW:
1616 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1617 break;
1618 case TCP_V6_FLOW:
1619 case UDP_V6_FLOW:
1620 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1621 /* fall through to add IP fields */
1622 case SCTP_V6_FLOW:
1623 case AH_ESP_V6_FLOW:
1624 case AH_V6_FLOW:
1625 case ESP_V6_FLOW:
1626 case IPV6_FLOW:
1627 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1628 break;
1629 default:
1630 return -EINVAL;
1631 }
1632
1633 return 0;
1634}
1635
1636/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001637 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1638 * @pf: Pointer to the physical function struct
1639 * @cmd: The command to get or set Rx flow classification rules
1640 * @rule_locs: Array of used rule locations
1641 *
1642 * This function populates both the total and actual rule count of
1643 * the ethtool flow classification command
1644 *
1645 * Returns 0 on success or -EMSGSIZE if entry not found
1646 **/
1647static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1648 struct ethtool_rxnfc *cmd,
1649 u32 *rule_locs)
1650{
1651 struct i40e_fdir_filter *rule;
1652 struct hlist_node *node2;
1653 int cnt = 0;
1654
1655 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001656 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001657
1658 hlist_for_each_entry_safe(rule, node2,
1659 &pf->fdir_filter_list, fdir_node) {
1660 if (cnt == cmd->rule_cnt)
1661 return -EMSGSIZE;
1662
1663 rule_locs[cnt] = rule->fd_id;
1664 cnt++;
1665 }
1666
1667 cmd->rule_cnt = cnt;
1668
1669 return 0;
1670}
1671
1672/**
1673 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1674 * @pf: Pointer to the physical function struct
1675 * @cmd: The command to get or set Rx flow classification rules
1676 *
1677 * This function looks up a filter based on the Rx flow classification
1678 * command and fills the flow spec info for it if found
1679 *
1680 * Returns 0 on success or -EINVAL if filter not found
1681 **/
1682static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1683 struct ethtool_rxnfc *cmd)
1684{
1685 struct ethtool_rx_flow_spec *fsp =
1686 (struct ethtool_rx_flow_spec *)&cmd->fs;
1687 struct i40e_fdir_filter *rule = NULL;
1688 struct hlist_node *node2;
1689
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001690 hlist_for_each_entry_safe(rule, node2,
1691 &pf->fdir_filter_list, fdir_node) {
1692 if (fsp->location <= rule->fd_id)
1693 break;
1694 }
1695
1696 if (!rule || fsp->location != rule->fd_id)
1697 return -EINVAL;
1698
1699 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001700 if (fsp->flow_type == IP_USER_FLOW) {
1701 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1702 fsp->h_u.usr_ip4_spec.proto = 0;
1703 fsp->m_u.usr_ip4_spec.proto = 0;
1704 }
1705
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001706 /* Reverse the src and dest notion, since the HW views them from
1707 * Tx perspective where as the user expects it from Rx filter view.
1708 */
1709 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1710 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1711 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1712 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001713
1714 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1715 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1716 else
1717 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001718
1719 return 0;
1720}
1721
1722/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001723 * i40e_get_rxnfc - command to get RX flow classification rules
1724 * @netdev: network interface device structure
1725 * @cmd: ethtool rxnfc command
1726 *
1727 * Returns Success if the command is supported.
1728 **/
1729static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1730 u32 *rule_locs)
1731{
1732 struct i40e_netdev_priv *np = netdev_priv(netdev);
1733 struct i40e_vsi *vsi = np->vsi;
1734 struct i40e_pf *pf = vsi->back;
1735 int ret = -EOPNOTSUPP;
1736
1737 switch (cmd->cmd) {
1738 case ETHTOOL_GRXRINGS:
1739 cmd->data = vsi->alloc_queue_pairs;
1740 ret = 0;
1741 break;
1742 case ETHTOOL_GRXFH:
1743 ret = i40e_get_rss_hash_opts(pf, cmd);
1744 break;
1745 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001746 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001747 /* report total rule count */
1748 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001749 ret = 0;
1750 break;
1751 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001752 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001753 break;
1754 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001755 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1756 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001757 default:
1758 break;
1759 }
1760
1761 return ret;
1762}
1763
1764/**
1765 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1766 * @pf: pointer to the physical function struct
1767 * @cmd: ethtool rxnfc command
1768 *
1769 * Returns Success if the flow input set is supported.
1770 **/
1771static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1772{
1773 struct i40e_hw *hw = &pf->hw;
1774 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1775 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1776
1777 /* RSS does not support anything other than hashing
1778 * to queues on src and dst IPs and ports
1779 */
1780 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1781 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1782 return -EINVAL;
1783
1784 /* We need at least the IP SRC and DEST fields for hashing */
1785 if (!(nfc->data & RXH_IP_SRC) ||
1786 !(nfc->data & RXH_IP_DST))
1787 return -EINVAL;
1788
1789 switch (nfc->flow_type) {
1790 case TCP_V4_FLOW:
1791 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1792 case 0:
1793 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1794 break;
1795 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1796 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1797 break;
1798 default:
1799 return -EINVAL;
1800 }
1801 break;
1802 case TCP_V6_FLOW:
1803 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1804 case 0:
1805 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1806 break;
1807 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1808 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1809 break;
1810 default:
1811 return -EINVAL;
1812 }
1813 break;
1814 case UDP_V4_FLOW:
1815 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1816 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001817 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1818 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001819 break;
1820 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001821 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1822 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001823 break;
1824 default:
1825 return -EINVAL;
1826 }
1827 break;
1828 case UDP_V6_FLOW:
1829 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1830 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001831 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1832 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001833 break;
1834 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001835 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1836 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001837 break;
1838 default:
1839 return -EINVAL;
1840 }
1841 break;
1842 case AH_ESP_V4_FLOW:
1843 case AH_V4_FLOW:
1844 case ESP_V4_FLOW:
1845 case SCTP_V4_FLOW:
1846 if ((nfc->data & RXH_L4_B_0_1) ||
1847 (nfc->data & RXH_L4_B_2_3))
1848 return -EINVAL;
1849 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1850 break;
1851 case AH_ESP_V6_FLOW:
1852 case AH_V6_FLOW:
1853 case ESP_V6_FLOW:
1854 case SCTP_V6_FLOW:
1855 if ((nfc->data & RXH_L4_B_0_1) ||
1856 (nfc->data & RXH_L4_B_2_3))
1857 return -EINVAL;
1858 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1859 break;
1860 case IPV4_FLOW:
1861 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1862 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1863 break;
1864 case IPV6_FLOW:
1865 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1866 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1867 break;
1868 default:
1869 return -EINVAL;
1870 }
1871
1872 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1873 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1874 i40e_flush(hw);
1875
1876 return 0;
1877}
1878
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001879/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001880 * i40e_match_fdir_input_set - Match a new filter against an existing one
1881 * @rule: The filter already added
1882 * @input: The new filter to comapre against
1883 *
1884 * Returns true if the two input set match
1885 **/
1886static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1887 struct i40e_fdir_filter *input)
1888{
1889 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1890 (rule->src_ip[0] != input->src_ip[0]) ||
1891 (rule->dst_port != input->dst_port) ||
1892 (rule->src_port != input->src_port))
1893 return false;
1894 return true;
1895}
1896
1897/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001898 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1899 * @vsi: Pointer to the targeted VSI
1900 * @input: The filter to update or NULL to indicate deletion
1901 * @sw_idx: Software index to the filter
1902 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001903 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001904 * This function updates (or deletes) a Flow Director entry from
1905 * the hlist of the corresponding PF
1906 *
1907 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001908 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001909static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1910 struct i40e_fdir_filter *input,
1911 u16 sw_idx,
1912 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001913{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001914 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001915 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001916 struct hlist_node *node2;
1917 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001918
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001919 parent = NULL;
1920 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001921
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001922 hlist_for_each_entry_safe(rule, node2,
1923 &pf->fdir_filter_list, fdir_node) {
1924 /* hash found, or no matching entry */
1925 if (rule->fd_id >= sw_idx)
1926 break;
1927 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001928 }
1929
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001930 /* if there is an old rule occupying our place remove it */
1931 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001932 if (input && !i40e_match_fdir_input_set(rule, input))
1933 err = i40e_add_del_fdir(vsi, rule, false);
1934 else if (!input)
1935 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001936 hlist_del(&rule->fdir_node);
1937 kfree(rule);
1938 pf->fdir_pf_active_filters--;
1939 }
1940
1941 /* If no input this was a delete, err should be 0 if a rule was
1942 * successfully found and removed from the list else -EINVAL
1943 */
1944 if (!input)
1945 return err;
1946
1947 /* initialize node and set software index */
1948 INIT_HLIST_NODE(&input->fdir_node);
1949
1950 /* add filter to the list */
1951 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07001952 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001953 else
1954 hlist_add_head(&input->fdir_node,
1955 &pf->fdir_filter_list);
1956
1957 /* update counts */
1958 pf->fdir_pf_active_filters++;
1959
1960 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001961}
1962
1963/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001964 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
1965 * @vsi: Pointer to the targeted VSI
1966 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001967 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001968 * The function removes a Flow Director filter entry from the
1969 * hlist of the corresponding PF
1970 *
1971 * Returns 0 on success
1972 */
1973static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
1974 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001975{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001976 struct ethtool_rx_flow_spec *fsp =
1977 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001978 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001979 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001980
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00001981 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1982 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1983 return -EBUSY;
1984
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00001985 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
1986 return -EBUSY;
1987
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001988 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001989
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001990 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001991 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001992}
1993
1994/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001995 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001996 * @vsi: pointer to the targeted VSI
1997 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001998 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001999 * Add Flow Director filters for a specific flow spec based on their
2000 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002001 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002002static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2003 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002004{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002005 struct ethtool_rx_flow_spec *fsp;
2006 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002007 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002008 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002009
2010 if (!vsi)
2011 return -EINVAL;
2012
2013 pf = vsi->back;
2014
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002015 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2016 return -EOPNOTSUPP;
2017
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002018 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002019 return -ENOSPC;
2020
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002021 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2022 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2023 return -EBUSY;
2024
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002025 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2026 return -EBUSY;
2027
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002028 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2029
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002030 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2031 pf->hw.func_caps.fd_filters_guaranteed)) {
2032 return -EINVAL;
2033 }
2034
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002035 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2036 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002037 return -EINVAL;
2038
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002039 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002040
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002041 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002042 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002043
2044 input->fd_id = fsp->location;
2045
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002046 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2047 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2048 else
2049 input->dest_ctl =
2050 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2051
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002052 input->q_index = fsp->ring_cookie;
2053 input->flex_off = 0;
2054 input->pctype = 0;
2055 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002056 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00002057 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002058 input->flow_type = fsp->flow_type;
2059 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002060
2061 /* Reverse the src and dest notion, since the HW expects them to be from
2062 * Tx perspective where as the input from user is from Rx filter view.
2063 */
2064 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2065 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2066 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2067 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002068
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002069 ret = i40e_add_del_fdir(vsi, input, true);
2070 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002071 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002072 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002073 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002074
2075 return ret;
2076}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002077
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002078/**
2079 * i40e_set_rxnfc - command to set RX flow classification rules
2080 * @netdev: network interface device structure
2081 * @cmd: ethtool rxnfc command
2082 *
2083 * Returns Success if the command is supported.
2084 **/
2085static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2086{
2087 struct i40e_netdev_priv *np = netdev_priv(netdev);
2088 struct i40e_vsi *vsi = np->vsi;
2089 struct i40e_pf *pf = vsi->back;
2090 int ret = -EOPNOTSUPP;
2091
2092 switch (cmd->cmd) {
2093 case ETHTOOL_SRXFH:
2094 ret = i40e_set_rss_hash_opt(pf, cmd);
2095 break;
2096 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002097 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002098 break;
2099 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002100 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002101 break;
2102 default:
2103 break;
2104 }
2105
2106 return ret;
2107}
2108
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002109/**
2110 * i40e_max_channels - get Max number of combined channels supported
2111 * @vsi: vsi pointer
2112 **/
2113static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2114{
2115 /* TODO: This code assumes DCB and FD is disabled for now. */
2116 return vsi->alloc_queue_pairs;
2117}
2118
2119/**
2120 * i40e_get_channels - Get the current channels enabled and max supported etc.
2121 * @netdev: network interface device structure
2122 * @ch: ethtool channels structure
2123 *
2124 * We don't support separate tx and rx queues as channels. The other count
2125 * represents how many queues are being used for control. max_combined counts
2126 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2127 * q_vectors since we support a lot more queue pairs than q_vectors.
2128 **/
2129static void i40e_get_channels(struct net_device *dev,
2130 struct ethtool_channels *ch)
2131{
2132 struct i40e_netdev_priv *np = netdev_priv(dev);
2133 struct i40e_vsi *vsi = np->vsi;
2134 struct i40e_pf *pf = vsi->back;
2135
2136 /* report maximum channels */
2137 ch->max_combined = i40e_max_channels(vsi);
2138
2139 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002140 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002141 ch->max_other = ch->other_count;
2142
2143 /* Note: This code assumes DCB is disabled for now. */
2144 ch->combined_count = vsi->num_queue_pairs;
2145}
2146
2147/**
2148 * i40e_set_channels - Set the new channels count.
2149 * @netdev: network interface device structure
2150 * @ch: ethtool channels structure
2151 *
2152 * The new channels count may not be the same as requested by the user
2153 * since it gets rounded down to a power of 2 value.
2154 **/
2155static int i40e_set_channels(struct net_device *dev,
2156 struct ethtool_channels *ch)
2157{
2158 struct i40e_netdev_priv *np = netdev_priv(dev);
2159 unsigned int count = ch->combined_count;
2160 struct i40e_vsi *vsi = np->vsi;
2161 struct i40e_pf *pf = vsi->back;
2162 int new_count;
2163
2164 /* We do not support setting channels for any other VSI at present */
2165 if (vsi->type != I40E_VSI_MAIN)
2166 return -EINVAL;
2167
2168 /* verify they are not requesting separate vectors */
2169 if (!count || ch->rx_count || ch->tx_count)
2170 return -EINVAL;
2171
2172 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002173 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002174 return -EINVAL;
2175
2176 /* verify the number of channels does not exceed hardware limits */
2177 if (count > i40e_max_channels(vsi))
2178 return -EINVAL;
2179
2180 /* update feature limits from largest to smallest supported values */
2181 /* TODO: Flow director limit, DCB etc */
2182
2183 /* cap RSS limit */
2184 if (count > pf->rss_size_max)
2185 count = pf->rss_size_max;
2186
2187 /* use rss_reconfig to rebuild with new queue count and update traffic
2188 * class queue mapping
2189 */
2190 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002191 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002192 return 0;
2193 else
2194 return -EINVAL;
2195}
2196
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002197static const struct ethtool_ops i40e_ethtool_ops = {
2198 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002199 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002200 .get_drvinfo = i40e_get_drvinfo,
2201 .get_regs_len = i40e_get_regs_len,
2202 .get_regs = i40e_get_regs,
2203 .nway_reset = i40e_nway_reset,
2204 .get_link = ethtool_op_get_link,
2205 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002206 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002207 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002208 .get_eeprom_len = i40e_get_eeprom_len,
2209 .get_eeprom = i40e_get_eeprom,
2210 .get_ringparam = i40e_get_ringparam,
2211 .set_ringparam = i40e_set_ringparam,
2212 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002213 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002214 .get_msglevel = i40e_get_msglevel,
2215 .set_msglevel = i40e_set_msglevel,
2216 .get_rxnfc = i40e_get_rxnfc,
2217 .set_rxnfc = i40e_set_rxnfc,
2218 .self_test = i40e_diag_test,
2219 .get_strings = i40e_get_strings,
2220 .set_phys_id = i40e_set_phys_id,
2221 .get_sset_count = i40e_get_sset_count,
2222 .get_ethtool_stats = i40e_get_ethtool_stats,
2223 .get_coalesce = i40e_get_coalesce,
2224 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002225 .get_channels = i40e_get_channels,
2226 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002227 .get_ts_info = i40e_get_ts_info,
2228};
2229
2230void i40e_set_ethtool_ops(struct net_device *netdev)
2231{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002232 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002233}