blob: 25242f505161fd0101cbfc45ad852e2e5ef27151 [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),
116 I40E_PF_STAT("tx_dropped", stats.eth.tx_discards),
117 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
118 I40E_PF_STAT("crc_errors", stats.crc_errors),
119 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
120 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
121 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000122 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000123 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000124 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
125 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
126 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
127 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
128 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
129 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
130 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
131 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
132 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
133 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
134 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
135 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
136 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
137 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
138 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
139 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
140 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
141 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
142 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
143 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
144 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
145 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
146 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
147 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000148 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000149 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000150 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
151 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
152
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000153 /* LPI stats */
154 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
155 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
156 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
157 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000158};
159
Vasu Dev38e00432014-08-01 13:27:03 -0700160#ifdef I40E_FCOE
161static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
162 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
163 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
164 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
165 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
166 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
167 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
168 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
169 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
170};
171
172#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000173#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000174 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
175 * 2 /* Tx and Rx together */ \
176 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000177#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
178#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000179#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700180#ifdef I40E_FCOE
181#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
182#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
183 I40E_FCOE_STATS_LEN + \
184 I40E_MISC_STATS_LEN + \
185 I40E_QUEUE_STATS_LEN((n)))
186#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000187#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000188 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000189 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700190#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000191#define I40E_PFC_STATS_LEN ( \
192 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
193 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
194 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
196 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
197 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000198#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000199#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
200 I40E_PFC_STATS_LEN + \
201 I40E_VSI_STATS_LEN((n)))
202
203enum i40e_ethtool_test_id {
204 I40E_ETH_TEST_REG = 0,
205 I40E_ETH_TEST_EEPROM,
206 I40E_ETH_TEST_INTR,
207 I40E_ETH_TEST_LOOPBACK,
208 I40E_ETH_TEST_LINK,
209};
210
211static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
212 "Register test (offline)",
213 "Eeprom test (offline)",
214 "Interrupt test (offline)",
215 "Loopback test (offline)",
216 "Link test (on/offline)"
217};
218
219#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
220
221/**
222 * i40e_get_settings - Get Link Speed and Duplex settings
223 * @netdev: network interface device structure
224 * @ecmd: ethtool command
225 *
226 * Reports speed/duplex settings based on media_type
227 **/
228static int i40e_get_settings(struct net_device *netdev,
229 struct ethtool_cmd *ecmd)
230{
231 struct i40e_netdev_priv *np = netdev_priv(netdev);
232 struct i40e_pf *pf = np->vsi->back;
233 struct i40e_hw *hw = &pf->hw;
234 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
235 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
236 u32 link_speed = hw_link_info->link_speed;
237
238 /* hardware is either in 40G mode or 10G mode
239 * NOTE: this section initializes supported and advertising
240 */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000241 if (!link_up) {
242 /* link is down and the driver needs to fall back on
243 * device ID to determine what kinds of info to display,
244 * it's mostly a guess that may change when link is up
245 */
246 switch (hw->device_id) {
247 case I40E_DEV_ID_QSFP_A:
248 case I40E_DEV_ID_QSFP_B:
249 case I40E_DEV_ID_QSFP_C:
250 /* pluggable QSFP */
251 ecmd->supported = SUPPORTED_40000baseSR4_Full |
252 SUPPORTED_40000baseCR4_Full |
253 SUPPORTED_40000baseLR4_Full;
254 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
255 ADVERTISED_40000baseCR4_Full |
256 ADVERTISED_40000baseLR4_Full;
257 break;
258 case I40E_DEV_ID_KX_B:
259 /* backplane 40G */
260 ecmd->supported = SUPPORTED_40000baseKR4_Full;
261 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
262 break;
263 case I40E_DEV_ID_KX_C:
264 /* backplane 10G */
265 ecmd->supported = SUPPORTED_10000baseKR_Full;
266 ecmd->advertising = ADVERTISED_10000baseKR_Full;
267 break;
Mitch Williams5960d332014-09-13 07:40:47 +0000268 case I40E_DEV_ID_10G_BASE_T:
269 ecmd->supported = SUPPORTED_10000baseT_Full |
270 SUPPORTED_1000baseT_Full |
271 SUPPORTED_100baseT_Full;
272 ecmd->advertising = ADVERTISED_10000baseT_Full |
273 ADVERTISED_1000baseT_Full |
274 ADVERTISED_100baseT_Full;
275 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000276 default:
277 /* all the rest are 10G/1G */
278 ecmd->supported = SUPPORTED_10000baseT_Full |
279 SUPPORTED_1000baseT_Full;
280 ecmd->advertising = ADVERTISED_10000baseT_Full |
281 ADVERTISED_1000baseT_Full;
282 break;
283 }
284
285 /* skip phy_type use as it is zero when link is down */
286 goto no_valid_phy_type;
287 }
288
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000289 switch (hw_link_info->phy_type) {
290 case I40E_PHY_TYPE_40GBASE_CR4:
291 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000292 ecmd->supported = SUPPORTED_Autoneg |
293 SUPPORTED_40000baseCR4_Full;
294 ecmd->advertising = ADVERTISED_Autoneg |
295 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000296 break;
297 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000298 ecmd->supported = SUPPORTED_Autoneg |
299 SUPPORTED_40000baseKR4_Full;
300 ecmd->advertising = ADVERTISED_Autoneg |
301 ADVERTISED_40000baseKR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000302 break;
303 case I40E_PHY_TYPE_40GBASE_SR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000304 case I40E_PHY_TYPE_XLPPI:
305 case I40E_PHY_TYPE_XLAUI:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000306 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000307 break;
308 case I40E_PHY_TYPE_40GBASE_LR4:
309 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000310 break;
311 case I40E_PHY_TYPE_10GBASE_KX4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000312 ecmd->supported = SUPPORTED_Autoneg |
313 SUPPORTED_10000baseKX4_Full;
314 ecmd->advertising = ADVERTISED_Autoneg |
315 ADVERTISED_10000baseKX4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000316 break;
317 case I40E_PHY_TYPE_10GBASE_KR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000318 ecmd->supported = SUPPORTED_Autoneg |
319 SUPPORTED_10000baseKR_Full;
320 ecmd->advertising = ADVERTISED_Autoneg |
321 ADVERTISED_10000baseKR_Full;
322 break;
323 case I40E_PHY_TYPE_10GBASE_SR:
324 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000325 case I40E_PHY_TYPE_1000BASE_SX:
326 case I40E_PHY_TYPE_1000BASE_LX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000327 ecmd->supported = SUPPORTED_10000baseT_Full;
Catherine Sullivan124ed152014-07-12 07:28:12 +0000328 ecmd->supported |= SUPPORTED_1000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000329 break;
330 case I40E_PHY_TYPE_10GBASE_CR1_CU:
331 case I40E_PHY_TYPE_10GBASE_CR1:
332 case I40E_PHY_TYPE_10GBASE_T:
333 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000334 SUPPORTED_10000baseT_Full |
335 SUPPORTED_1000baseT_Full |
336 SUPPORTED_100baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000337 ecmd->advertising = ADVERTISED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000338 ADVERTISED_10000baseT_Full |
339 ADVERTISED_1000baseT_Full |
340 ADVERTISED_100baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000341 break;
342 case I40E_PHY_TYPE_XAUI:
343 case I40E_PHY_TYPE_XFI:
344 case I40E_PHY_TYPE_SFI:
345 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
346 ecmd->supported = SUPPORTED_10000baseT_Full;
347 break;
348 case I40E_PHY_TYPE_1000BASE_KX:
349 case I40E_PHY_TYPE_1000BASE_T:
350 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000351 SUPPORTED_10000baseT_Full |
352 SUPPORTED_1000baseT_Full |
353 SUPPORTED_100baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000354 ecmd->advertising = ADVERTISED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000355 ADVERTISED_10000baseT_Full |
356 ADVERTISED_1000baseT_Full |
357 ADVERTISED_100baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000358 break;
359 case I40E_PHY_TYPE_100BASE_TX:
360 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000361 SUPPORTED_10000baseT_Full |
362 SUPPORTED_1000baseT_Full |
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000363 SUPPORTED_100baseT_Full;
364 ecmd->advertising = ADVERTISED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000365 ADVERTISED_10000baseT_Full |
366 ADVERTISED_1000baseT_Full |
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000367 ADVERTISED_100baseT_Full;
368 break;
369 case I40E_PHY_TYPE_SGMII:
370 ecmd->supported = SUPPORTED_Autoneg |
371 SUPPORTED_1000baseT_Full |
372 SUPPORTED_100baseT_Full;
373 ecmd->advertising = ADVERTISED_Autoneg |
374 ADVERTISED_1000baseT_Full |
375 ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000376 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000377 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000378 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000379 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
380 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000381 }
382
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000383no_valid_phy_type:
384 /* this is if autoneg is enabled or disabled */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000385 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
386 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000387
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000388 switch (hw->phy.media_type) {
389 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000390 ecmd->supported |= SUPPORTED_Autoneg |
391 SUPPORTED_Backplane;
392 ecmd->advertising |= ADVERTISED_Autoneg |
393 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000394 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000395 break;
396 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000397 ecmd->supported |= SUPPORTED_TP;
398 ecmd->advertising |= ADVERTISED_TP;
399 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000400 break;
401 case I40E_MEDIA_TYPE_DA:
402 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000403 ecmd->supported |= SUPPORTED_FIBRE;
404 ecmd->advertising |= ADVERTISED_FIBRE;
405 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000406 break;
407 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000408 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000409 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000410 break;
411 case I40E_MEDIA_TYPE_UNKNOWN:
412 default:
413 ecmd->port = PORT_OTHER;
414 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000415 }
416
417 ecmd->transceiver = XCVR_EXTERNAL;
418
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000419 ecmd->supported |= SUPPORTED_Pause;
420
421 switch (hw->fc.current_mode) {
422 case I40E_FC_FULL:
423 ecmd->advertising |= ADVERTISED_Pause;
424 break;
425 case I40E_FC_TX_PAUSE:
426 ecmd->advertising |= ADVERTISED_Asym_Pause;
427 break;
428 case I40E_FC_RX_PAUSE:
429 ecmd->advertising |= (ADVERTISED_Pause |
430 ADVERTISED_Asym_Pause);
431 break;
432 default:
433 ecmd->advertising &= ~(ADVERTISED_Pause |
434 ADVERTISED_Asym_Pause);
435 break;
436 }
437
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000438 if (link_up) {
439 switch (link_speed) {
440 case I40E_LINK_SPEED_40GB:
441 /* need a SPEED_40000 in ethtool.h */
442 ethtool_cmd_speed_set(ecmd, 40000);
443 break;
444 case I40E_LINK_SPEED_10GB:
445 ethtool_cmd_speed_set(ecmd, SPEED_10000);
446 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000447 case I40E_LINK_SPEED_1GB:
448 ethtool_cmd_speed_set(ecmd, SPEED_1000);
449 break;
Mitch Williams5960d332014-09-13 07:40:47 +0000450 case I40E_LINK_SPEED_100MB:
451 ethtool_cmd_speed_set(ecmd, SPEED_100);
452 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000453 default:
454 break;
455 }
456 ecmd->duplex = DUPLEX_FULL;
457 } else {
458 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
459 ecmd->duplex = DUPLEX_UNKNOWN;
460 }
461
462 return 0;
463}
464
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000465/**
466 * i40e_set_settings - Set Speed and Duplex
467 * @netdev: network interface device structure
468 * @ecmd: ethtool command
469 *
470 * Set speed/duplex per media_types advertised/forced
471 **/
472static int i40e_set_settings(struct net_device *netdev,
473 struct ethtool_cmd *ecmd)
474{
475 struct i40e_netdev_priv *np = netdev_priv(netdev);
476 struct i40e_aq_get_phy_abilities_resp abilities;
477 struct i40e_aq_set_phy_config config;
478 struct i40e_pf *pf = np->vsi->back;
479 struct i40e_vsi *vsi = np->vsi;
480 struct i40e_hw *hw = &pf->hw;
481 struct ethtool_cmd safe_ecmd;
482 i40e_status status = 0;
483 bool change = false;
484 int err = 0;
485 u8 autoneg;
486 u32 advertise;
487
488 if (vsi != pf->vsi[pf->lan_vsi])
489 return -EOPNOTSUPP;
490
491 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
492 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000493 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
494 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000495 return -EOPNOTSUPP;
496
497 /* get our own copy of the bits to check against */
498 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
499 i40e_get_settings(netdev, &safe_ecmd);
500
501 /* save autoneg and speed out of ecmd */
502 autoneg = ecmd->autoneg;
503 advertise = ecmd->advertising;
504
505 /* set autoneg and speed back to what they currently are */
506 ecmd->autoneg = safe_ecmd.autoneg;
507 ecmd->advertising = safe_ecmd.advertising;
508
509 ecmd->cmd = safe_ecmd.cmd;
510 /* If ecmd and safe_ecmd are not the same now, then they are
511 * trying to set something that we do not support
512 */
513 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
514 return -EOPNOTSUPP;
515
516 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
517 usleep_range(1000, 2000);
518
519 /* Get the current phy config */
520 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
521 NULL);
522 if (status)
523 return -EAGAIN;
524
Catherine Sullivan124ed152014-07-12 07:28:12 +0000525 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000526 * set below
527 */
528 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000529 config.abilities = abilities.abilities;
530
531 /* Check autoneg */
532 if (autoneg == AUTONEG_ENABLE) {
533 /* If autoneg is not supported, return error */
534 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
535 netdev_info(netdev, "Autoneg not supported on this phy\n");
536 return -EINVAL;
537 }
538 /* If autoneg was not already enabled */
539 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
540 config.abilities = abilities.abilities |
541 I40E_AQ_PHY_ENABLE_AN;
542 change = true;
543 }
544 } else {
545 /* If autoneg is supported 10GBASE_T is the only phy that
546 * can disable it, so otherwise return error
547 */
548 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
549 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
550 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
551 return -EINVAL;
552 }
553 /* If autoneg is currently enabled */
554 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000555 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000556 ~I40E_AQ_PHY_ENABLE_AN;
557 change = true;
558 }
559 }
560
561 if (advertise & ~safe_ecmd.supported)
562 return -EINVAL;
563
564 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000565 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000566 if (advertise & ADVERTISED_1000baseT_Full ||
567 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000568 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000569 if (advertise & ADVERTISED_10000baseT_Full ||
570 advertise & ADVERTISED_10000baseKX4_Full ||
571 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000572 config.link_speed |= I40E_LINK_SPEED_10GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000573 if (advertise & ADVERTISED_40000baseKR4_Full ||
574 advertise & ADVERTISED_40000baseCR4_Full ||
575 advertise & ADVERTISED_40000baseSR4_Full ||
576 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000577 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000578
Catherine Sullivan124ed152014-07-12 07:28:12 +0000579 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000580 /* copy over the rest of the abilities */
581 config.phy_type = abilities.phy_type;
582 config.eee_capability = abilities.eee_capability;
583 config.eeer = abilities.eeer_val;
584 config.low_power_ctrl = abilities.d3_lpan;
585
Catherine Sullivan94128512014-07-12 07:28:16 +0000586 /* set link and auto negotiation so changes take effect */
587 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
588 /* If link is up put link down */
589 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
590 /* Tell the OS link is going down, the link will go
591 * back up when fw says it is ready asynchronously
592 */
593 netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
594 netif_carrier_off(netdev);
595 netif_tx_stop_all_queues(netdev);
596 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000597
598 /* make the aq call */
599 status = i40e_aq_set_phy_config(hw, &config, NULL);
600 if (status) {
601 netdev_info(netdev, "Set phy config failed with error %d.\n",
602 status);
603 return -EAGAIN;
604 }
605
606 status = i40e_update_link_info(hw, true);
607 if (status)
608 netdev_info(netdev, "Updating link info failed with error %d\n",
609 status);
610
611 } else {
612 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
613 }
614
615 return err;
616}
617
Jesse Brandeburga6599722014-06-04 08:45:25 +0000618static int i40e_nway_reset(struct net_device *netdev)
619{
620 /* restart autonegotiation */
621 struct i40e_netdev_priv *np = netdev_priv(netdev);
622 struct i40e_pf *pf = np->vsi->back;
623 struct i40e_hw *hw = &pf->hw;
624 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
625 i40e_status ret = 0;
626
627 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
628 if (ret) {
629 netdev_info(netdev, "link restart failed, aq_err=%d\n",
630 pf->hw.aq.asq_last_status);
631 return -EIO;
632 }
633
634 return 0;
635}
636
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000637/**
638 * i40e_get_pauseparam - Get Flow Control status
639 * Return tx/rx-pause status
640 **/
641static void i40e_get_pauseparam(struct net_device *netdev,
642 struct ethtool_pauseparam *pause)
643{
644 struct i40e_netdev_priv *np = netdev_priv(netdev);
645 struct i40e_pf *pf = np->vsi->back;
646 struct i40e_hw *hw = &pf->hw;
647 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000648 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000649
650 pause->autoneg =
651 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
652 AUTONEG_ENABLE : AUTONEG_DISABLE);
653
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000654 /* PFC enabled so report LFC as off */
655 if (dcbx_cfg->pfc.pfcenable) {
656 pause->rx_pause = 0;
657 pause->tx_pause = 0;
658 return;
659 }
660
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000661 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000662 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000663 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000664 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000665 } else if (hw->fc.current_mode == I40E_FC_FULL) {
666 pause->rx_pause = 1;
667 pause->tx_pause = 1;
668 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000669}
670
Catherine Sullivan2becc352014-06-04 08:45:27 +0000671/**
672 * i40e_set_pauseparam - Set Flow Control parameter
673 * @netdev: network interface device structure
674 * @pause: return tx/rx flow control status
675 **/
676static int i40e_set_pauseparam(struct net_device *netdev,
677 struct ethtool_pauseparam *pause)
678{
679 struct i40e_netdev_priv *np = netdev_priv(netdev);
680 struct i40e_pf *pf = np->vsi->back;
681 struct i40e_vsi *vsi = np->vsi;
682 struct i40e_hw *hw = &pf->hw;
683 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000684 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000685 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
686 i40e_status status;
687 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000688 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000689
690 if (vsi != pf->vsi[pf->lan_vsi])
691 return -EOPNOTSUPP;
692
693 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
694 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
695 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
696 return -EOPNOTSUPP;
697 }
698
699 /* If we have link and don't have autoneg */
700 if (!test_bit(__I40E_DOWN, &pf->state) &&
701 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
702 /* Send message that it might not necessarily work*/
703 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
704 }
705
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000706 if (dcbx_cfg->pfc.pfcenable) {
707 netdev_info(netdev,
708 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000709 return -EOPNOTSUPP;
710 }
711
712 if (pause->rx_pause && pause->tx_pause)
713 hw->fc.requested_mode = I40E_FC_FULL;
714 else if (pause->rx_pause && !pause->tx_pause)
715 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
716 else if (!pause->rx_pause && pause->tx_pause)
717 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
718 else if (!pause->rx_pause && !pause->tx_pause)
719 hw->fc.requested_mode = I40E_FC_NONE;
720 else
721 return -EINVAL;
722
Catherine Sullivan94128512014-07-12 07:28:16 +0000723 /* Tell the OS link is going down, the link will go back up when fw
724 * says it is ready asynchronously
725 */
726 netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
727 netif_carrier_off(netdev);
728 netif_tx_stop_all_queues(netdev);
729
Catherine Sullivan2becc352014-06-04 08:45:27 +0000730 /* Set the fc mode and only restart an if link is up*/
731 status = i40e_set_fc(hw, &aq_failures, link_up);
732
733 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
734 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
735 status, hw->aq.asq_last_status);
736 err = -EAGAIN;
737 }
738 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
739 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
740 status, hw->aq.asq_last_status);
741 err = -EAGAIN;
742 }
743 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
744 netdev_info(netdev, "Set fc failed on the update_link_info call with error %d and status %d\n",
745 status, hw->aq.asq_last_status);
746 err = -EAGAIN;
747 }
748
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000749 if (!test_bit(__I40E_DOWN, &pf->state)) {
750 /* Give it a little more time to try to come back */
751 msleep(75);
752 if (!test_bit(__I40E_DOWN, &pf->state))
753 return i40e_nway_reset(netdev);
754 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000755
756 return err;
757}
758
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000759static u32 i40e_get_msglevel(struct net_device *netdev)
760{
761 struct i40e_netdev_priv *np = netdev_priv(netdev);
762 struct i40e_pf *pf = np->vsi->back;
763
764 return pf->msg_enable;
765}
766
767static void i40e_set_msglevel(struct net_device *netdev, u32 data)
768{
769 struct i40e_netdev_priv *np = netdev_priv(netdev);
770 struct i40e_pf *pf = np->vsi->back;
771
772 if (I40E_DEBUG_USER & data)
773 pf->hw.debug_mask = data;
774 pf->msg_enable = data;
775}
776
777static int i40e_get_regs_len(struct net_device *netdev)
778{
779 int reg_count = 0;
780 int i;
781
782 for (i = 0; i40e_reg_list[i].offset != 0; i++)
783 reg_count += i40e_reg_list[i].elements;
784
785 return reg_count * sizeof(u32);
786}
787
788static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
789 void *p)
790{
791 struct i40e_netdev_priv *np = netdev_priv(netdev);
792 struct i40e_pf *pf = np->vsi->back;
793 struct i40e_hw *hw = &pf->hw;
794 u32 *reg_buf = p;
795 int i, j, ri;
796 u32 reg;
797
798 /* Tell ethtool which driver-version-specific regs output we have.
799 *
800 * At some point, if we have ethtool doing special formatting of
801 * this data, it will rely on this version number to know how to
802 * interpret things. Hence, this needs to be updated if/when the
803 * diags register table is changed.
804 */
805 regs->version = 1;
806
807 /* loop through the diags reg table for what to print */
808 ri = 0;
809 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
810 for (j = 0; j < i40e_reg_list[i].elements; j++) {
811 reg = i40e_reg_list[i].offset
812 + (j * i40e_reg_list[i].stride);
813 reg_buf[ri++] = rd32(hw, reg);
814 }
815 }
816
817}
818
819static int i40e_get_eeprom(struct net_device *netdev,
820 struct ethtool_eeprom *eeprom, u8 *bytes)
821{
822 struct i40e_netdev_priv *np = netdev_priv(netdev);
823 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000824 struct i40e_pf *pf = np->vsi->back;
825 int ret_val = 0, len;
826 u8 *eeprom_buff;
827 u16 i, sectors;
828 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000829 u32 magic;
830
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000831#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000832 if (eeprom->len == 0)
833 return -EINVAL;
834
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000835 /* check for NVMUpdate access method */
836 magic = hw->vendor_id | (hw->device_id << 16);
837 if (eeprom->magic && eeprom->magic != magic) {
838 int errno;
839
840 /* make sure it is the right magic for NVMUpdate */
841 if ((eeprom->magic >> 16) != hw->device_id)
842 return -EINVAL;
843
844 ret_val = i40e_nvmupd_command(hw,
845 (struct i40e_nvm_access *)eeprom,
846 bytes, &errno);
847 if (ret_val)
848 dev_info(&pf->pdev->dev,
849 "NVMUpdate read failed err=%d status=0x%x\n",
850 ret_val, hw->aq.asq_last_status);
851
852 return errno;
853 }
854
855 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000856 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
857
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000858 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000859 if (!eeprom_buff)
860 return -ENOMEM;
861
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000862 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
863 if (ret_val) {
864 dev_info(&pf->pdev->dev,
865 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
866 ret_val, hw->aq.asq_last_status);
867 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000868 }
869
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000870 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
871 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
872 len = I40E_NVM_SECTOR_SIZE;
873 last = false;
874 for (i = 0; i < sectors; i++) {
875 if (i == (sectors - 1)) {
876 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
877 last = true;
878 }
879 ret_val = i40e_aq_read_nvm(hw, 0x0,
880 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
881 len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000882 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000883 last, NULL);
884 if (ret_val) {
885 dev_info(&pf->pdev->dev,
886 "read NVM failed err=%d status=0x%x\n",
887 ret_val, hw->aq.asq_last_status);
888 goto release_nvm;
889 }
890 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000891
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000892release_nvm:
893 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000894 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000895free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000896 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000897 return ret_val;
898}
899
900static int i40e_get_eeprom_len(struct net_device *netdev)
901{
902 struct i40e_netdev_priv *np = netdev_priv(netdev);
903 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000904 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000905
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000906 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
907 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
908 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
909 /* register returns value in power of 2, 64Kbyte chunks. */
910 val = (64 * 1024) * (1 << val);
911 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000912}
913
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000914static int i40e_set_eeprom(struct net_device *netdev,
915 struct ethtool_eeprom *eeprom, u8 *bytes)
916{
917 struct i40e_netdev_priv *np = netdev_priv(netdev);
918 struct i40e_hw *hw = &np->vsi->back->hw;
919 struct i40e_pf *pf = np->vsi->back;
920 int ret_val = 0;
921 int errno;
922 u32 magic;
923
924 /* normal ethtool set_eeprom is not supported */
925 magic = hw->vendor_id | (hw->device_id << 16);
926 if (eeprom->magic == magic)
927 return -EOPNOTSUPP;
928
929 /* check for NVMUpdate access method */
930 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
931 return -EINVAL;
932
933 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
934 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
935 return -EBUSY;
936
937 ret_val = i40e_nvmupd_command(hw, (struct i40e_nvm_access *)eeprom,
938 bytes, &errno);
939 if (ret_val)
940 dev_info(&pf->pdev->dev,
941 "NVMUpdate write failed err=%d status=0x%x\n",
942 ret_val, hw->aq.asq_last_status);
943
944 return errno;
945}
946
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000947static void i40e_get_drvinfo(struct net_device *netdev,
948 struct ethtool_drvinfo *drvinfo)
949{
950 struct i40e_netdev_priv *np = netdev_priv(netdev);
951 struct i40e_vsi *vsi = np->vsi;
952 struct i40e_pf *pf = vsi->back;
953
954 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
955 strlcpy(drvinfo->version, i40e_driver_version_str,
956 sizeof(drvinfo->version));
957 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
958 sizeof(drvinfo->fw_version));
959 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
960 sizeof(drvinfo->bus_info));
961}
962
963static void i40e_get_ringparam(struct net_device *netdev,
964 struct ethtool_ringparam *ring)
965{
966 struct i40e_netdev_priv *np = netdev_priv(netdev);
967 struct i40e_pf *pf = np->vsi->back;
968 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
969
970 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
971 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
972 ring->rx_mini_max_pending = 0;
973 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +0000974 ring->rx_pending = vsi->rx_rings[0]->count;
975 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000976 ring->rx_mini_pending = 0;
977 ring->rx_jumbo_pending = 0;
978}
979
980static int i40e_set_ringparam(struct net_device *netdev,
981 struct ethtool_ringparam *ring)
982{
983 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
984 struct i40e_netdev_priv *np = netdev_priv(netdev);
985 struct i40e_vsi *vsi = np->vsi;
986 struct i40e_pf *pf = vsi->back;
987 u32 new_rx_count, new_tx_count;
988 int i, err = 0;
989
990 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
991 return -EINVAL;
992
Shannon Nelson1fa18372013-11-20 10:03:08 +0000993 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
994 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
995 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
996 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
997 netdev_info(netdev,
998 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
999 ring->tx_pending, ring->rx_pending,
1000 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1001 return -EINVAL;
1002 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001003
Shannon Nelson1fa18372013-11-20 10:03:08 +00001004 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1005 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001006
1007 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001008 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1009 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001010 return 0;
1011
1012 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1013 usleep_range(1000, 2000);
1014
1015 if (!netif_running(vsi->netdev)) {
1016 /* simple case - set for the next time the netdev is started */
1017 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001018 vsi->tx_rings[i]->count = new_tx_count;
1019 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001020 }
1021 goto done;
1022 }
1023
1024 /* We can't just free everything and then setup again,
1025 * because the ISRs in MSI-X mode get passed pointers
1026 * to the Tx and Rx ring structs.
1027 */
1028
1029 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001030 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001031 netdev_info(netdev,
1032 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001033 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001034 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1035 sizeof(struct i40e_ring), GFP_KERNEL);
1036 if (!tx_rings) {
1037 err = -ENOMEM;
1038 goto done;
1039 }
1040
1041 for (i = 0; i < vsi->num_queue_pairs; i++) {
1042 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001043 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001044 tx_rings[i].count = new_tx_count;
1045 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1046 if (err) {
1047 while (i) {
1048 i--;
1049 i40e_free_tx_resources(&tx_rings[i]);
1050 }
1051 kfree(tx_rings);
1052 tx_rings = NULL;
1053
1054 goto done;
1055 }
1056 }
1057 }
1058
1059 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001060 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001061 netdev_info(netdev,
1062 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001063 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001064 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1065 sizeof(struct i40e_ring), GFP_KERNEL);
1066 if (!rx_rings) {
1067 err = -ENOMEM;
1068 goto free_tx;
1069 }
1070
1071 for (i = 0; i < vsi->num_queue_pairs; i++) {
1072 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001073 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001074 rx_rings[i].count = new_rx_count;
1075 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1076 if (err) {
1077 while (i) {
1078 i--;
1079 i40e_free_rx_resources(&rx_rings[i]);
1080 }
1081 kfree(rx_rings);
1082 rx_rings = NULL;
1083
1084 goto free_tx;
1085 }
1086 }
1087 }
1088
1089 /* Bring interface down, copy in the new ring info,
1090 * then restore the interface
1091 */
1092 i40e_down(vsi);
1093
1094 if (tx_rings) {
1095 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001096 i40e_free_tx_resources(vsi->tx_rings[i]);
1097 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001098 }
1099 kfree(tx_rings);
1100 tx_rings = NULL;
1101 }
1102
1103 if (rx_rings) {
1104 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001105 i40e_free_rx_resources(vsi->rx_rings[i]);
1106 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001107 }
1108 kfree(rx_rings);
1109 rx_rings = NULL;
1110 }
1111
1112 i40e_up(vsi);
1113
1114free_tx:
1115 /* error cleanup if the Rx allocations failed after getting Tx */
1116 if (tx_rings) {
1117 for (i = 0; i < vsi->num_queue_pairs; i++)
1118 i40e_free_tx_resources(&tx_rings[i]);
1119 kfree(tx_rings);
1120 tx_rings = NULL;
1121 }
1122
1123done:
1124 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1125
1126 return err;
1127}
1128
1129static int i40e_get_sset_count(struct net_device *netdev, int sset)
1130{
1131 struct i40e_netdev_priv *np = netdev_priv(netdev);
1132 struct i40e_vsi *vsi = np->vsi;
1133 struct i40e_pf *pf = vsi->back;
1134
1135 switch (sset) {
1136 case ETH_SS_TEST:
1137 return I40E_TEST_LEN;
1138 case ETH_SS_STATS:
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001139 if (vsi == pf->vsi[pf->lan_vsi]) {
1140 int len = I40E_PF_STATS_LEN(netdev);
1141
1142 if (pf->lan_veb != I40E_NO_VEB)
1143 len += I40E_VEB_STATS_LEN;
1144 return len;
1145 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001146 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001147 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001148 default:
1149 return -EOPNOTSUPP;
1150 }
1151}
1152
1153static void i40e_get_ethtool_stats(struct net_device *netdev,
1154 struct ethtool_stats *stats, u64 *data)
1155{
1156 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001157 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001158 struct i40e_vsi *vsi = np->vsi;
1159 struct i40e_pf *pf = vsi->back;
1160 int i = 0;
1161 char *p;
1162 int j;
1163 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001164 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001165
1166 i40e_update_stats(vsi);
1167
1168 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1169 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1170 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1171 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1172 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001173 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1174 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1175 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1176 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1177 }
Vasu Dev38e00432014-08-01 13:27:03 -07001178#ifdef I40E_FCOE
1179 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1180 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1181 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1182 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1183 }
1184#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001185 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001186 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001187 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001188
1189 if (!tx_ring)
1190 continue;
1191
1192 /* process Tx ring statistics */
1193 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001194 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001195 data[i] = tx_ring->stats.packets;
1196 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001197 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001198 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001199
1200 /* Rx ring is the 2nd half of the queue pair */
1201 rx_ring = &tx_ring[1];
1202 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001203 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001204 data[i] = rx_ring->stats.packets;
1205 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001206 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001207 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001208 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001209 rcu_read_unlock();
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001210 if (vsi != pf->vsi[pf->lan_vsi])
1211 return;
1212
1213 if (pf->lan_veb != I40E_NO_VEB) {
1214 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1215 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1216 p = (char *)veb;
1217 p += i40e_gstrings_veb_stats[j].stat_offset;
1218 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1219 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001220 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001221 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001222 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1223 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1224 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1225 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1226 }
1227 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1228 data[i++] = pf->stats.priority_xon_tx[j];
1229 data[i++] = pf->stats.priority_xoff_tx[j];
1230 }
1231 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1232 data[i++] = pf->stats.priority_xon_rx[j];
1233 data[i++] = pf->stats.priority_xoff_rx[j];
1234 }
1235 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1236 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001237}
1238
1239static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1240 u8 *data)
1241{
1242 struct i40e_netdev_priv *np = netdev_priv(netdev);
1243 struct i40e_vsi *vsi = np->vsi;
1244 struct i40e_pf *pf = vsi->back;
1245 char *p = (char *)data;
1246 int i;
1247
1248 switch (stringset) {
1249 case ETH_SS_TEST:
1250 for (i = 0; i < I40E_TEST_LEN; i++) {
1251 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1252 data += ETH_GSTRING_LEN;
1253 }
1254 break;
1255 case ETH_SS_STATS:
1256 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1257 snprintf(p, ETH_GSTRING_LEN, "%s",
1258 i40e_gstrings_net_stats[i].stat_string);
1259 p += ETH_GSTRING_LEN;
1260 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001261 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1262 snprintf(p, ETH_GSTRING_LEN, "%s",
1263 i40e_gstrings_misc_stats[i].stat_string);
1264 p += ETH_GSTRING_LEN;
1265 }
Vasu Dev38e00432014-08-01 13:27:03 -07001266#ifdef I40E_FCOE
1267 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1268 snprintf(p, ETH_GSTRING_LEN, "%s",
1269 i40e_gstrings_fcoe_stats[i].stat_string);
1270 p += ETH_GSTRING_LEN;
1271 }
1272#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001273 for (i = 0; i < vsi->num_queue_pairs; i++) {
1274 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1275 p += ETH_GSTRING_LEN;
1276 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1277 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001278 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1279 p += ETH_GSTRING_LEN;
1280 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1281 p += ETH_GSTRING_LEN;
1282 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001283 if (vsi != pf->vsi[pf->lan_vsi])
1284 return;
1285
1286 if (pf->lan_veb != I40E_NO_VEB) {
1287 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1288 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1289 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001290 p += ETH_GSTRING_LEN;
1291 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001292 }
1293 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1294 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1295 i40e_gstrings_stats[i].stat_string);
1296 p += ETH_GSTRING_LEN;
1297 }
1298 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1299 snprintf(p, ETH_GSTRING_LEN,
1300 "port.tx_priority_%u_xon", i);
1301 p += ETH_GSTRING_LEN;
1302 snprintf(p, ETH_GSTRING_LEN,
1303 "port.tx_priority_%u_xoff", i);
1304 p += ETH_GSTRING_LEN;
1305 }
1306 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1307 snprintf(p, ETH_GSTRING_LEN,
1308 "port.rx_priority_%u_xon", i);
1309 p += ETH_GSTRING_LEN;
1310 snprintf(p, ETH_GSTRING_LEN,
1311 "port.rx_priority_%u_xoff", i);
1312 p += ETH_GSTRING_LEN;
1313 }
1314 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1315 snprintf(p, ETH_GSTRING_LEN,
1316 "port.rx_priority_%u_xon_2_xoff", i);
1317 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001318 }
1319 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1320 break;
1321 }
1322}
1323
1324static int i40e_get_ts_info(struct net_device *dev,
1325 struct ethtool_ts_info *info)
1326{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001327 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1328
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001329 /* only report HW timestamping if PTP is enabled */
1330 if (!(pf->flags & I40E_FLAG_PTP))
1331 return ethtool_op_get_ts_info(dev, info);
1332
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001333 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1334 SOF_TIMESTAMPING_RX_SOFTWARE |
1335 SOF_TIMESTAMPING_SOFTWARE |
1336 SOF_TIMESTAMPING_TX_HARDWARE |
1337 SOF_TIMESTAMPING_RX_HARDWARE |
1338 SOF_TIMESTAMPING_RAW_HARDWARE;
1339
1340 if (pf->ptp_clock)
1341 info->phc_index = ptp_clock_index(pf->ptp_clock);
1342 else
1343 info->phc_index = -1;
1344
1345 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1346
1347 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1348 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1349 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1350 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1351 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1352 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1353 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1354 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1355 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1356 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1357 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1358 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1359
1360 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001361}
1362
Shannon Nelson7b086392013-11-20 10:02:59 +00001363static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001364{
Shannon Nelson7b086392013-11-20 10:02:59 +00001365 struct i40e_netdev_priv *np = netdev_priv(netdev);
1366 struct i40e_pf *pf = np->vsi->back;
1367
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001368 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001369 if (i40e_get_link_status(&pf->hw))
1370 *data = 0;
1371 else
1372 *data = 1;
1373
1374 return *data;
1375}
1376
Shannon Nelson7b086392013-11-20 10:02:59 +00001377static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001378{
Shannon Nelson7b086392013-11-20 10:02:59 +00001379 struct i40e_netdev_priv *np = netdev_priv(netdev);
1380 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001381
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001382 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001383 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001384
Shannon Nelson7b086392013-11-20 10:02:59 +00001385 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001386}
1387
Shannon Nelson7b086392013-11-20 10:02:59 +00001388static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001389{
Shannon Nelson7b086392013-11-20 10:02:59 +00001390 struct i40e_netdev_priv *np = netdev_priv(netdev);
1391 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001392
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001393 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001394 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001395
Shannon Nelson4443ec92014-11-13 08:23:12 +00001396 /* forcebly clear the NVM Update state machine */
1397 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1398
Shannon Nelson7b086392013-11-20 10:02:59 +00001399 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001400}
1401
Shannon Nelson7b086392013-11-20 10:02:59 +00001402static int i40e_intr_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;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001406 u16 swc_old = pf->sw_int_count;
1407
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001408 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001409 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1410 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001411 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1412 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1413 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1414 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001415 usleep_range(1000, 2000);
1416 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001417
1418 return *data;
1419}
1420
Shannon Nelson7b086392013-11-20 10:02:59 +00001421static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001422{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001423 struct i40e_netdev_priv *np = netdev_priv(netdev);
1424 struct i40e_pf *pf = np->vsi->back;
1425
1426 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001427 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001428
1429 return *data;
1430}
1431
1432static void i40e_diag_test(struct net_device *netdev,
1433 struct ethtool_test *eth_test, u64 *data)
1434{
1435 struct i40e_netdev_priv *np = netdev_priv(netdev);
1436 struct i40e_pf *pf = np->vsi->back;
1437
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001438 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1439 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001440 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001441
Shannon Nelsonf551b432013-11-26 10:49:12 +00001442 set_bit(__I40E_TESTING, &pf->state);
1443
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001444 /* Link test performed before hardware reset
1445 * so autoneg doesn't interfere with test result
1446 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001447 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001448 eth_test->flags |= ETH_TEST_FL_FAILED;
1449
Shannon Nelson7b086392013-11-20 10:02:59 +00001450 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001451 eth_test->flags |= ETH_TEST_FL_FAILED;
1452
Shannon Nelson7b086392013-11-20 10:02:59 +00001453 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001454 eth_test->flags |= ETH_TEST_FL_FAILED;
1455
Shannon Nelson7b086392013-11-20 10:02:59 +00001456 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001457 eth_test->flags |= ETH_TEST_FL_FAILED;
1458
Shannon Nelsonf551b432013-11-26 10:49:12 +00001459 /* run reg test last, a reset is required after it */
1460 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1461 eth_test->flags |= ETH_TEST_FL_FAILED;
1462
1463 clear_bit(__I40E_TESTING, &pf->state);
1464 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001465 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001466 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001467 netif_info(pf, drv, netdev, "online testing starting\n");
1468
Shannon Nelson7b086392013-11-20 10:02:59 +00001469 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001470 eth_test->flags |= ETH_TEST_FL_FAILED;
1471
1472 /* Offline only tests, not run in online; pass by default */
1473 data[I40E_ETH_TEST_REG] = 0;
1474 data[I40E_ETH_TEST_EEPROM] = 0;
1475 data[I40E_ETH_TEST_INTR] = 0;
1476 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001477 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001478
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001479 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001480}
1481
1482static void i40e_get_wol(struct net_device *netdev,
1483 struct ethtool_wolinfo *wol)
1484{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001485 struct i40e_netdev_priv *np = netdev_priv(netdev);
1486 struct i40e_pf *pf = np->vsi->back;
1487 struct i40e_hw *hw = &pf->hw;
1488 u16 wol_nvm_bits;
1489
1490 /* NVM bit on means WoL disabled for the port */
1491 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1492 if ((1 << hw->port) & wol_nvm_bits) {
1493 wol->supported = 0;
1494 wol->wolopts = 0;
1495 } else {
1496 wol->supported = WAKE_MAGIC;
1497 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1498 }
1499}
1500
1501static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1502{
1503 struct i40e_netdev_priv *np = netdev_priv(netdev);
1504 struct i40e_pf *pf = np->vsi->back;
1505 struct i40e_hw *hw = &pf->hw;
1506 u16 wol_nvm_bits;
1507
1508 /* NVM bit on means WoL disabled for the port */
1509 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1510 if (((1 << hw->port) & wol_nvm_bits))
1511 return -EOPNOTSUPP;
1512
1513 /* only magic packet is supported */
1514 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1515 return -EOPNOTSUPP;
1516
1517 /* is this a new value? */
1518 if (pf->wol_en != !!wol->wolopts) {
1519 pf->wol_en = !!wol->wolopts;
1520 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1521 }
1522
1523 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001524}
1525
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001526static int i40e_set_phys_id(struct net_device *netdev,
1527 enum ethtool_phys_id_state state)
1528{
1529 struct i40e_netdev_priv *np = netdev_priv(netdev);
1530 struct i40e_pf *pf = np->vsi->back;
1531 struct i40e_hw *hw = &pf->hw;
1532 int blink_freq = 2;
1533
1534 switch (state) {
1535 case ETHTOOL_ID_ACTIVE:
1536 pf->led_status = i40e_led_get(hw);
1537 return blink_freq;
1538 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001539 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001540 break;
1541 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001542 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001543 break;
1544 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001545 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001546 break;
1547 }
1548
1549 return 0;
1550}
1551
1552/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1553 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1554 * 125us (8000 interrupts per second) == ITR(62)
1555 */
1556
1557static int i40e_get_coalesce(struct net_device *netdev,
1558 struct ethtool_coalesce *ec)
1559{
1560 struct i40e_netdev_priv *np = netdev_priv(netdev);
1561 struct i40e_vsi *vsi = np->vsi;
1562
1563 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1564 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1565
1566 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001567 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001568
1569 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001570 ec->use_adaptive_tx_coalesce = 1;
1571
1572 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1573 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001574
1575 return 0;
1576}
1577
1578static int i40e_set_coalesce(struct net_device *netdev,
1579 struct ethtool_coalesce *ec)
1580{
1581 struct i40e_netdev_priv *np = netdev_priv(netdev);
1582 struct i40e_q_vector *q_vector;
1583 struct i40e_vsi *vsi = np->vsi;
1584 struct i40e_pf *pf = vsi->back;
1585 struct i40e_hw *hw = &pf->hw;
1586 u16 vector;
1587 int i;
1588
1589 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1590 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1591
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001592 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001593 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001594 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001595 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001596 } else if (ec->rx_coalesce_usecs == 0) {
1597 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001598 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001599 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 +00001600 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001601 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001602 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001603 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001604
Mitch Williams32f5f542014-04-04 04:43:10 +00001605 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001606 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001607 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001608 } else if (ec->tx_coalesce_usecs == 0) {
1609 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001610 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001611 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 +00001612 } else {
1613 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001614 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001615 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001616 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001617
1618 if (ec->use_adaptive_rx_coalesce)
1619 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1620 else
1621 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1622
1623 if (ec->use_adaptive_tx_coalesce)
1624 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1625 else
1626 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001627
Alexander Duyck493fb302013-09-28 07:01:44 +00001628 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1629 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001630 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1631 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1632 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1633 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1634 i40e_flush(hw);
1635 }
1636
1637 return 0;
1638}
1639
1640/**
1641 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1642 * @pf: pointer to the physical function struct
1643 * @cmd: ethtool rxnfc command
1644 *
1645 * Returns Success if the flow is supported, else Invalid Input.
1646 **/
1647static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1648{
1649 cmd->data = 0;
1650
1651 /* Report default options for RSS on i40e */
1652 switch (cmd->flow_type) {
1653 case TCP_V4_FLOW:
1654 case UDP_V4_FLOW:
1655 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1656 /* fall through to add IP fields */
1657 case SCTP_V4_FLOW:
1658 case AH_ESP_V4_FLOW:
1659 case AH_V4_FLOW:
1660 case ESP_V4_FLOW:
1661 case IPV4_FLOW:
1662 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1663 break;
1664 case TCP_V6_FLOW:
1665 case UDP_V6_FLOW:
1666 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1667 /* fall through to add IP fields */
1668 case SCTP_V6_FLOW:
1669 case AH_ESP_V6_FLOW:
1670 case AH_V6_FLOW:
1671 case ESP_V6_FLOW:
1672 case IPV6_FLOW:
1673 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1674 break;
1675 default:
1676 return -EINVAL;
1677 }
1678
1679 return 0;
1680}
1681
1682/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001683 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1684 * @pf: Pointer to the physical function struct
1685 * @cmd: The command to get or set Rx flow classification rules
1686 * @rule_locs: Array of used rule locations
1687 *
1688 * This function populates both the total and actual rule count of
1689 * the ethtool flow classification command
1690 *
1691 * Returns 0 on success or -EMSGSIZE if entry not found
1692 **/
1693static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1694 struct ethtool_rxnfc *cmd,
1695 u32 *rule_locs)
1696{
1697 struct i40e_fdir_filter *rule;
1698 struct hlist_node *node2;
1699 int cnt = 0;
1700
1701 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001702 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001703
1704 hlist_for_each_entry_safe(rule, node2,
1705 &pf->fdir_filter_list, fdir_node) {
1706 if (cnt == cmd->rule_cnt)
1707 return -EMSGSIZE;
1708
1709 rule_locs[cnt] = rule->fd_id;
1710 cnt++;
1711 }
1712
1713 cmd->rule_cnt = cnt;
1714
1715 return 0;
1716}
1717
1718/**
1719 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1720 * @pf: Pointer to the physical function struct
1721 * @cmd: The command to get or set Rx flow classification rules
1722 *
1723 * This function looks up a filter based on the Rx flow classification
1724 * command and fills the flow spec info for it if found
1725 *
1726 * Returns 0 on success or -EINVAL if filter not found
1727 **/
1728static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1729 struct ethtool_rxnfc *cmd)
1730{
1731 struct ethtool_rx_flow_spec *fsp =
1732 (struct ethtool_rx_flow_spec *)&cmd->fs;
1733 struct i40e_fdir_filter *rule = NULL;
1734 struct hlist_node *node2;
1735
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001736 hlist_for_each_entry_safe(rule, node2,
1737 &pf->fdir_filter_list, fdir_node) {
1738 if (fsp->location <= rule->fd_id)
1739 break;
1740 }
1741
1742 if (!rule || fsp->location != rule->fd_id)
1743 return -EINVAL;
1744
1745 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001746 if (fsp->flow_type == IP_USER_FLOW) {
1747 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1748 fsp->h_u.usr_ip4_spec.proto = 0;
1749 fsp->m_u.usr_ip4_spec.proto = 0;
1750 }
1751
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001752 /* Reverse the src and dest notion, since the HW views them from
1753 * Tx perspective where as the user expects it from Rx filter view.
1754 */
1755 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1756 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1757 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1758 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001759
1760 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1761 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1762 else
1763 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001764
1765 return 0;
1766}
1767
1768/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001769 * i40e_get_rxnfc - command to get RX flow classification rules
1770 * @netdev: network interface device structure
1771 * @cmd: ethtool rxnfc command
1772 *
1773 * Returns Success if the command is supported.
1774 **/
1775static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1776 u32 *rule_locs)
1777{
1778 struct i40e_netdev_priv *np = netdev_priv(netdev);
1779 struct i40e_vsi *vsi = np->vsi;
1780 struct i40e_pf *pf = vsi->back;
1781 int ret = -EOPNOTSUPP;
1782
1783 switch (cmd->cmd) {
1784 case ETHTOOL_GRXRINGS:
1785 cmd->data = vsi->alloc_queue_pairs;
1786 ret = 0;
1787 break;
1788 case ETHTOOL_GRXFH:
1789 ret = i40e_get_rss_hash_opts(pf, cmd);
1790 break;
1791 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001792 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001793 /* report total rule count */
1794 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001795 ret = 0;
1796 break;
1797 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001798 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001799 break;
1800 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001801 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1802 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001803 default:
1804 break;
1805 }
1806
1807 return ret;
1808}
1809
1810/**
1811 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1812 * @pf: pointer to the physical function struct
1813 * @cmd: ethtool rxnfc command
1814 *
1815 * Returns Success if the flow input set is supported.
1816 **/
1817static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1818{
1819 struct i40e_hw *hw = &pf->hw;
1820 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1821 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1822
1823 /* RSS does not support anything other than hashing
1824 * to queues on src and dst IPs and ports
1825 */
1826 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1827 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1828 return -EINVAL;
1829
1830 /* We need at least the IP SRC and DEST fields for hashing */
1831 if (!(nfc->data & RXH_IP_SRC) ||
1832 !(nfc->data & RXH_IP_DST))
1833 return -EINVAL;
1834
1835 switch (nfc->flow_type) {
1836 case TCP_V4_FLOW:
1837 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1838 case 0:
1839 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1840 break;
1841 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1842 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1843 break;
1844 default:
1845 return -EINVAL;
1846 }
1847 break;
1848 case TCP_V6_FLOW:
1849 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1850 case 0:
1851 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1852 break;
1853 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1854 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1855 break;
1856 default:
1857 return -EINVAL;
1858 }
1859 break;
1860 case UDP_V4_FLOW:
1861 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1862 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001863 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1864 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001865 break;
1866 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001867 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1868 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001869 break;
1870 default:
1871 return -EINVAL;
1872 }
1873 break;
1874 case UDP_V6_FLOW:
1875 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1876 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001877 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1878 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001879 break;
1880 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001881 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1882 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001883 break;
1884 default:
1885 return -EINVAL;
1886 }
1887 break;
1888 case AH_ESP_V4_FLOW:
1889 case AH_V4_FLOW:
1890 case ESP_V4_FLOW:
1891 case SCTP_V4_FLOW:
1892 if ((nfc->data & RXH_L4_B_0_1) ||
1893 (nfc->data & RXH_L4_B_2_3))
1894 return -EINVAL;
1895 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1896 break;
1897 case AH_ESP_V6_FLOW:
1898 case AH_V6_FLOW:
1899 case ESP_V6_FLOW:
1900 case SCTP_V6_FLOW:
1901 if ((nfc->data & RXH_L4_B_0_1) ||
1902 (nfc->data & RXH_L4_B_2_3))
1903 return -EINVAL;
1904 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1905 break;
1906 case IPV4_FLOW:
1907 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1908 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1909 break;
1910 case IPV6_FLOW:
1911 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1912 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1913 break;
1914 default:
1915 return -EINVAL;
1916 }
1917
1918 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1919 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1920 i40e_flush(hw);
1921
1922 return 0;
1923}
1924
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001925/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001926 * i40e_match_fdir_input_set - Match a new filter against an existing one
1927 * @rule: The filter already added
1928 * @input: The new filter to comapre against
1929 *
1930 * Returns true if the two input set match
1931 **/
1932static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1933 struct i40e_fdir_filter *input)
1934{
1935 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1936 (rule->src_ip[0] != input->src_ip[0]) ||
1937 (rule->dst_port != input->dst_port) ||
1938 (rule->src_port != input->src_port))
1939 return false;
1940 return true;
1941}
1942
1943/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001944 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1945 * @vsi: Pointer to the targeted VSI
1946 * @input: The filter to update or NULL to indicate deletion
1947 * @sw_idx: Software index to the filter
1948 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001949 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001950 * This function updates (or deletes) a Flow Director entry from
1951 * the hlist of the corresponding PF
1952 *
1953 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001954 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001955static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1956 struct i40e_fdir_filter *input,
1957 u16 sw_idx,
1958 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001959{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001960 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001961 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001962 struct hlist_node *node2;
1963 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001964
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001965 parent = NULL;
1966 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001967
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001968 hlist_for_each_entry_safe(rule, node2,
1969 &pf->fdir_filter_list, fdir_node) {
1970 /* hash found, or no matching entry */
1971 if (rule->fd_id >= sw_idx)
1972 break;
1973 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001974 }
1975
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001976 /* if there is an old rule occupying our place remove it */
1977 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001978 if (input && !i40e_match_fdir_input_set(rule, input))
1979 err = i40e_add_del_fdir(vsi, rule, false);
1980 else if (!input)
1981 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001982 hlist_del(&rule->fdir_node);
1983 kfree(rule);
1984 pf->fdir_pf_active_filters--;
1985 }
1986
1987 /* If no input this was a delete, err should be 0 if a rule was
1988 * successfully found and removed from the list else -EINVAL
1989 */
1990 if (!input)
1991 return err;
1992
1993 /* initialize node and set software index */
1994 INIT_HLIST_NODE(&input->fdir_node);
1995
1996 /* add filter to the list */
1997 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07001998 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001999 else
2000 hlist_add_head(&input->fdir_node,
2001 &pf->fdir_filter_list);
2002
2003 /* update counts */
2004 pf->fdir_pf_active_filters++;
2005
2006 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002007}
2008
2009/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002010 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2011 * @vsi: Pointer to the targeted VSI
2012 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002013 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002014 * The function removes a Flow Director filter entry from the
2015 * hlist of the corresponding PF
2016 *
2017 * Returns 0 on success
2018 */
2019static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2020 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002021{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002022 struct ethtool_rx_flow_spec *fsp =
2023 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002024 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002025 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002026
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002027 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2028 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2029 return -EBUSY;
2030
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002031 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2032 return -EBUSY;
2033
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002034 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002035
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002036 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002037 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002038}
2039
2040/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002041 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002042 * @vsi: pointer to the targeted VSI
2043 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002044 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002045 * Add Flow Director filters for a specific flow spec based on their
2046 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002047 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002048static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2049 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002050{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002051 struct ethtool_rx_flow_spec *fsp;
2052 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002053 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002054 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002055
2056 if (!vsi)
2057 return -EINVAL;
2058
2059 pf = vsi->back;
2060
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002061 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2062 return -EOPNOTSUPP;
2063
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002064 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002065 return -ENOSPC;
2066
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002067 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2068 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2069 return -EBUSY;
2070
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002071 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2072 return -EBUSY;
2073
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002074 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2075
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002076 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2077 pf->hw.func_caps.fd_filters_guaranteed)) {
2078 return -EINVAL;
2079 }
2080
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002081 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2082 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002083 return -EINVAL;
2084
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002085 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002086
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002087 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002088 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002089
2090 input->fd_id = fsp->location;
2091
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002092 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2093 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2094 else
2095 input->dest_ctl =
2096 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2097
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002098 input->q_index = fsp->ring_cookie;
2099 input->flex_off = 0;
2100 input->pctype = 0;
2101 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002102 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00002103 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002104 input->flow_type = fsp->flow_type;
2105 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002106
2107 /* Reverse the src and dest notion, since the HW expects them to be from
2108 * Tx perspective where as the input from user is from Rx filter view.
2109 */
2110 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2111 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2112 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2113 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002114
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002115 ret = i40e_add_del_fdir(vsi, input, true);
2116 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002117 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002118 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002119 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002120
2121 return ret;
2122}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002123
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002124/**
2125 * i40e_set_rxnfc - command to set RX flow classification rules
2126 * @netdev: network interface device structure
2127 * @cmd: ethtool rxnfc command
2128 *
2129 * Returns Success if the command is supported.
2130 **/
2131static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2132{
2133 struct i40e_netdev_priv *np = netdev_priv(netdev);
2134 struct i40e_vsi *vsi = np->vsi;
2135 struct i40e_pf *pf = vsi->back;
2136 int ret = -EOPNOTSUPP;
2137
2138 switch (cmd->cmd) {
2139 case ETHTOOL_SRXFH:
2140 ret = i40e_set_rss_hash_opt(pf, cmd);
2141 break;
2142 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002143 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002144 break;
2145 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002146 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002147 break;
2148 default:
2149 break;
2150 }
2151
2152 return ret;
2153}
2154
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002155/**
2156 * i40e_max_channels - get Max number of combined channels supported
2157 * @vsi: vsi pointer
2158 **/
2159static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2160{
2161 /* TODO: This code assumes DCB and FD is disabled for now. */
2162 return vsi->alloc_queue_pairs;
2163}
2164
2165/**
2166 * i40e_get_channels - Get the current channels enabled and max supported etc.
2167 * @netdev: network interface device structure
2168 * @ch: ethtool channels structure
2169 *
2170 * We don't support separate tx and rx queues as channels. The other count
2171 * represents how many queues are being used for control. max_combined counts
2172 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2173 * q_vectors since we support a lot more queue pairs than q_vectors.
2174 **/
2175static void i40e_get_channels(struct net_device *dev,
2176 struct ethtool_channels *ch)
2177{
2178 struct i40e_netdev_priv *np = netdev_priv(dev);
2179 struct i40e_vsi *vsi = np->vsi;
2180 struct i40e_pf *pf = vsi->back;
2181
2182 /* report maximum channels */
2183 ch->max_combined = i40e_max_channels(vsi);
2184
2185 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002186 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002187 ch->max_other = ch->other_count;
2188
2189 /* Note: This code assumes DCB is disabled for now. */
2190 ch->combined_count = vsi->num_queue_pairs;
2191}
2192
2193/**
2194 * i40e_set_channels - Set the new channels count.
2195 * @netdev: network interface device structure
2196 * @ch: ethtool channels structure
2197 *
2198 * The new channels count may not be the same as requested by the user
2199 * since it gets rounded down to a power of 2 value.
2200 **/
2201static int i40e_set_channels(struct net_device *dev,
2202 struct ethtool_channels *ch)
2203{
2204 struct i40e_netdev_priv *np = netdev_priv(dev);
2205 unsigned int count = ch->combined_count;
2206 struct i40e_vsi *vsi = np->vsi;
2207 struct i40e_pf *pf = vsi->back;
2208 int new_count;
2209
2210 /* We do not support setting channels for any other VSI at present */
2211 if (vsi->type != I40E_VSI_MAIN)
2212 return -EINVAL;
2213
2214 /* verify they are not requesting separate vectors */
2215 if (!count || ch->rx_count || ch->tx_count)
2216 return -EINVAL;
2217
2218 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002219 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002220 return -EINVAL;
2221
2222 /* verify the number of channels does not exceed hardware limits */
2223 if (count > i40e_max_channels(vsi))
2224 return -EINVAL;
2225
2226 /* update feature limits from largest to smallest supported values */
2227 /* TODO: Flow director limit, DCB etc */
2228
2229 /* cap RSS limit */
2230 if (count > pf->rss_size_max)
2231 count = pf->rss_size_max;
2232
2233 /* use rss_reconfig to rebuild with new queue count and update traffic
2234 * class queue mapping
2235 */
2236 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002237 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002238 return 0;
2239 else
2240 return -EINVAL;
2241}
2242
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002243static const struct ethtool_ops i40e_ethtool_ops = {
2244 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002245 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002246 .get_drvinfo = i40e_get_drvinfo,
2247 .get_regs_len = i40e_get_regs_len,
2248 .get_regs = i40e_get_regs,
2249 .nway_reset = i40e_nway_reset,
2250 .get_link = ethtool_op_get_link,
2251 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002252 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002253 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002254 .get_eeprom_len = i40e_get_eeprom_len,
2255 .get_eeprom = i40e_get_eeprom,
2256 .get_ringparam = i40e_get_ringparam,
2257 .set_ringparam = i40e_set_ringparam,
2258 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002259 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002260 .get_msglevel = i40e_get_msglevel,
2261 .set_msglevel = i40e_set_msglevel,
2262 .get_rxnfc = i40e_get_rxnfc,
2263 .set_rxnfc = i40e_set_rxnfc,
2264 .self_test = i40e_diag_test,
2265 .get_strings = i40e_get_strings,
2266 .set_phys_id = i40e_set_phys_id,
2267 .get_sset_count = i40e_get_sset_count,
2268 .get_ethtool_stats = i40e_get_ethtool_stats,
2269 .get_coalesce = i40e_get_coalesce,
2270 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002271 .get_channels = i40e_get_channels,
2272 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002273 .get_ts_info = i40e_get_ts_info,
2274};
2275
2276void i40e_set_ethtool_ops(struct net_device *netdev)
2277{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002278 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002279}