blob: fcd815dc7d3c4c4ae81496b843b6eed3101c2514 [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 Nelson7b086392013-11-20 10:02:59 +00001396 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001397}
1398
Shannon Nelson7b086392013-11-20 10:02:59 +00001399static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001400{
Shannon Nelson7b086392013-11-20 10:02:59 +00001401 struct i40e_netdev_priv *np = netdev_priv(netdev);
1402 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001403 u16 swc_old = pf->sw_int_count;
1404
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001405 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001406 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1407 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001408 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1409 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1410 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1411 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001412 usleep_range(1000, 2000);
1413 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001414
1415 return *data;
1416}
1417
Shannon Nelson7b086392013-11-20 10:02:59 +00001418static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001419{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001420 struct i40e_netdev_priv *np = netdev_priv(netdev);
1421 struct i40e_pf *pf = np->vsi->back;
1422
1423 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001424 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001425
1426 return *data;
1427}
1428
1429static void i40e_diag_test(struct net_device *netdev,
1430 struct ethtool_test *eth_test, u64 *data)
1431{
1432 struct i40e_netdev_priv *np = netdev_priv(netdev);
1433 struct i40e_pf *pf = np->vsi->back;
1434
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001435 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1436 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001437 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001438
Shannon Nelsonf551b432013-11-26 10:49:12 +00001439 set_bit(__I40E_TESTING, &pf->state);
1440
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001441 /* Link test performed before hardware reset
1442 * so autoneg doesn't interfere with test result
1443 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001444 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001445 eth_test->flags |= ETH_TEST_FL_FAILED;
1446
Shannon Nelson7b086392013-11-20 10:02:59 +00001447 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
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_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
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_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001454 eth_test->flags |= ETH_TEST_FL_FAILED;
1455
Shannon Nelsonf551b432013-11-26 10:49:12 +00001456 /* run reg test last, a reset is required after it */
1457 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1458 eth_test->flags |= ETH_TEST_FL_FAILED;
1459
1460 clear_bit(__I40E_TESTING, &pf->state);
1461 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001462 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001463 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001464 netif_info(pf, drv, netdev, "online testing starting\n");
1465
Shannon Nelson7b086392013-11-20 10:02:59 +00001466 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001467 eth_test->flags |= ETH_TEST_FL_FAILED;
1468
1469 /* Offline only tests, not run in online; pass by default */
1470 data[I40E_ETH_TEST_REG] = 0;
1471 data[I40E_ETH_TEST_EEPROM] = 0;
1472 data[I40E_ETH_TEST_INTR] = 0;
1473 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001474 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001475
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001476 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001477}
1478
1479static void i40e_get_wol(struct net_device *netdev,
1480 struct ethtool_wolinfo *wol)
1481{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001482 struct i40e_netdev_priv *np = netdev_priv(netdev);
1483 struct i40e_pf *pf = np->vsi->back;
1484 struct i40e_hw *hw = &pf->hw;
1485 u16 wol_nvm_bits;
1486
1487 /* NVM bit on means WoL disabled for the port */
1488 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1489 if ((1 << hw->port) & wol_nvm_bits) {
1490 wol->supported = 0;
1491 wol->wolopts = 0;
1492 } else {
1493 wol->supported = WAKE_MAGIC;
1494 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1495 }
1496}
1497
1498static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1499{
1500 struct i40e_netdev_priv *np = netdev_priv(netdev);
1501 struct i40e_pf *pf = np->vsi->back;
1502 struct i40e_hw *hw = &pf->hw;
1503 u16 wol_nvm_bits;
1504
1505 /* NVM bit on means WoL disabled for the port */
1506 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1507 if (((1 << hw->port) & wol_nvm_bits))
1508 return -EOPNOTSUPP;
1509
1510 /* only magic packet is supported */
1511 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1512 return -EOPNOTSUPP;
1513
1514 /* is this a new value? */
1515 if (pf->wol_en != !!wol->wolopts) {
1516 pf->wol_en = !!wol->wolopts;
1517 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1518 }
1519
1520 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001521}
1522
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001523static int i40e_set_phys_id(struct net_device *netdev,
1524 enum ethtool_phys_id_state state)
1525{
1526 struct i40e_netdev_priv *np = netdev_priv(netdev);
1527 struct i40e_pf *pf = np->vsi->back;
1528 struct i40e_hw *hw = &pf->hw;
1529 int blink_freq = 2;
1530
1531 switch (state) {
1532 case ETHTOOL_ID_ACTIVE:
1533 pf->led_status = i40e_led_get(hw);
1534 return blink_freq;
1535 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001536 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001537 break;
1538 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001539 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001540 break;
1541 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001542 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001543 break;
1544 }
1545
1546 return 0;
1547}
1548
1549/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1550 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1551 * 125us (8000 interrupts per second) == ITR(62)
1552 */
1553
1554static int i40e_get_coalesce(struct net_device *netdev,
1555 struct ethtool_coalesce *ec)
1556{
1557 struct i40e_netdev_priv *np = netdev_priv(netdev);
1558 struct i40e_vsi *vsi = np->vsi;
1559
1560 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1561 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1562
1563 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001564 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001565
1566 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001567 ec->use_adaptive_tx_coalesce = 1;
1568
1569 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1570 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001571
1572 return 0;
1573}
1574
1575static int i40e_set_coalesce(struct net_device *netdev,
1576 struct ethtool_coalesce *ec)
1577{
1578 struct i40e_netdev_priv *np = netdev_priv(netdev);
1579 struct i40e_q_vector *q_vector;
1580 struct i40e_vsi *vsi = np->vsi;
1581 struct i40e_pf *pf = vsi->back;
1582 struct i40e_hw *hw = &pf->hw;
1583 u16 vector;
1584 int i;
1585
1586 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1587 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1588
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001589 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001590 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001591 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001592 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001593 } else if (ec->rx_coalesce_usecs == 0) {
1594 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001595 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001596 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 +00001597 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001598 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001599 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001600 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001601
Mitch Williams32f5f542014-04-04 04:43:10 +00001602 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001603 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001604 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001605 } else if (ec->tx_coalesce_usecs == 0) {
1606 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001607 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001608 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 +00001609 } else {
1610 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001611 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001612 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001613 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001614
1615 if (ec->use_adaptive_rx_coalesce)
1616 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1617 else
1618 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1619
1620 if (ec->use_adaptive_tx_coalesce)
1621 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1622 else
1623 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001624
Alexander Duyck493fb302013-09-28 07:01:44 +00001625 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1626 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001627 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1628 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1629 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1630 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1631 i40e_flush(hw);
1632 }
1633
1634 return 0;
1635}
1636
1637/**
1638 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1639 * @pf: pointer to the physical function struct
1640 * @cmd: ethtool rxnfc command
1641 *
1642 * Returns Success if the flow is supported, else Invalid Input.
1643 **/
1644static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1645{
1646 cmd->data = 0;
1647
1648 /* Report default options for RSS on i40e */
1649 switch (cmd->flow_type) {
1650 case TCP_V4_FLOW:
1651 case UDP_V4_FLOW:
1652 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1653 /* fall through to add IP fields */
1654 case SCTP_V4_FLOW:
1655 case AH_ESP_V4_FLOW:
1656 case AH_V4_FLOW:
1657 case ESP_V4_FLOW:
1658 case IPV4_FLOW:
1659 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1660 break;
1661 case TCP_V6_FLOW:
1662 case UDP_V6_FLOW:
1663 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1664 /* fall through to add IP fields */
1665 case SCTP_V6_FLOW:
1666 case AH_ESP_V6_FLOW:
1667 case AH_V6_FLOW:
1668 case ESP_V6_FLOW:
1669 case IPV6_FLOW:
1670 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1671 break;
1672 default:
1673 return -EINVAL;
1674 }
1675
1676 return 0;
1677}
1678
1679/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001680 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1681 * @pf: Pointer to the physical function struct
1682 * @cmd: The command to get or set Rx flow classification rules
1683 * @rule_locs: Array of used rule locations
1684 *
1685 * This function populates both the total and actual rule count of
1686 * the ethtool flow classification command
1687 *
1688 * Returns 0 on success or -EMSGSIZE if entry not found
1689 **/
1690static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1691 struct ethtool_rxnfc *cmd,
1692 u32 *rule_locs)
1693{
1694 struct i40e_fdir_filter *rule;
1695 struct hlist_node *node2;
1696 int cnt = 0;
1697
1698 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001699 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001700
1701 hlist_for_each_entry_safe(rule, node2,
1702 &pf->fdir_filter_list, fdir_node) {
1703 if (cnt == cmd->rule_cnt)
1704 return -EMSGSIZE;
1705
1706 rule_locs[cnt] = rule->fd_id;
1707 cnt++;
1708 }
1709
1710 cmd->rule_cnt = cnt;
1711
1712 return 0;
1713}
1714
1715/**
1716 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1717 * @pf: Pointer to the physical function struct
1718 * @cmd: The command to get or set Rx flow classification rules
1719 *
1720 * This function looks up a filter based on the Rx flow classification
1721 * command and fills the flow spec info for it if found
1722 *
1723 * Returns 0 on success or -EINVAL if filter not found
1724 **/
1725static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1726 struct ethtool_rxnfc *cmd)
1727{
1728 struct ethtool_rx_flow_spec *fsp =
1729 (struct ethtool_rx_flow_spec *)&cmd->fs;
1730 struct i40e_fdir_filter *rule = NULL;
1731 struct hlist_node *node2;
1732
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001733 hlist_for_each_entry_safe(rule, node2,
1734 &pf->fdir_filter_list, fdir_node) {
1735 if (fsp->location <= rule->fd_id)
1736 break;
1737 }
1738
1739 if (!rule || fsp->location != rule->fd_id)
1740 return -EINVAL;
1741
1742 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001743 if (fsp->flow_type == IP_USER_FLOW) {
1744 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1745 fsp->h_u.usr_ip4_spec.proto = 0;
1746 fsp->m_u.usr_ip4_spec.proto = 0;
1747 }
1748
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001749 /* Reverse the src and dest notion, since the HW views them from
1750 * Tx perspective where as the user expects it from Rx filter view.
1751 */
1752 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1753 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1754 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1755 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001756
1757 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1758 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1759 else
1760 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001761
1762 return 0;
1763}
1764
1765/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001766 * i40e_get_rxnfc - command to get RX flow classification rules
1767 * @netdev: network interface device structure
1768 * @cmd: ethtool rxnfc command
1769 *
1770 * Returns Success if the command is supported.
1771 **/
1772static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1773 u32 *rule_locs)
1774{
1775 struct i40e_netdev_priv *np = netdev_priv(netdev);
1776 struct i40e_vsi *vsi = np->vsi;
1777 struct i40e_pf *pf = vsi->back;
1778 int ret = -EOPNOTSUPP;
1779
1780 switch (cmd->cmd) {
1781 case ETHTOOL_GRXRINGS:
1782 cmd->data = vsi->alloc_queue_pairs;
1783 ret = 0;
1784 break;
1785 case ETHTOOL_GRXFH:
1786 ret = i40e_get_rss_hash_opts(pf, cmd);
1787 break;
1788 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001789 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001790 /* report total rule count */
1791 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001792 ret = 0;
1793 break;
1794 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001795 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001796 break;
1797 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001798 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1799 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001800 default:
1801 break;
1802 }
1803
1804 return ret;
1805}
1806
1807/**
1808 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1809 * @pf: pointer to the physical function struct
1810 * @cmd: ethtool rxnfc command
1811 *
1812 * Returns Success if the flow input set is supported.
1813 **/
1814static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1815{
1816 struct i40e_hw *hw = &pf->hw;
1817 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1818 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1819
1820 /* RSS does not support anything other than hashing
1821 * to queues on src and dst IPs and ports
1822 */
1823 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1824 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1825 return -EINVAL;
1826
1827 /* We need at least the IP SRC and DEST fields for hashing */
1828 if (!(nfc->data & RXH_IP_SRC) ||
1829 !(nfc->data & RXH_IP_DST))
1830 return -EINVAL;
1831
1832 switch (nfc->flow_type) {
1833 case TCP_V4_FLOW:
1834 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1835 case 0:
1836 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1837 break;
1838 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1839 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1840 break;
1841 default:
1842 return -EINVAL;
1843 }
1844 break;
1845 case TCP_V6_FLOW:
1846 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1847 case 0:
1848 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1849 break;
1850 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1851 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1852 break;
1853 default:
1854 return -EINVAL;
1855 }
1856 break;
1857 case UDP_V4_FLOW:
1858 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1859 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001860 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1861 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001862 break;
1863 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001864 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1865 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001866 break;
1867 default:
1868 return -EINVAL;
1869 }
1870 break;
1871 case UDP_V6_FLOW:
1872 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1873 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001874 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1875 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001876 break;
1877 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001878 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1879 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001880 break;
1881 default:
1882 return -EINVAL;
1883 }
1884 break;
1885 case AH_ESP_V4_FLOW:
1886 case AH_V4_FLOW:
1887 case ESP_V4_FLOW:
1888 case SCTP_V4_FLOW:
1889 if ((nfc->data & RXH_L4_B_0_1) ||
1890 (nfc->data & RXH_L4_B_2_3))
1891 return -EINVAL;
1892 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1893 break;
1894 case AH_ESP_V6_FLOW:
1895 case AH_V6_FLOW:
1896 case ESP_V6_FLOW:
1897 case SCTP_V6_FLOW:
1898 if ((nfc->data & RXH_L4_B_0_1) ||
1899 (nfc->data & RXH_L4_B_2_3))
1900 return -EINVAL;
1901 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1902 break;
1903 case IPV4_FLOW:
1904 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1905 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1906 break;
1907 case IPV6_FLOW:
1908 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1909 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1910 break;
1911 default:
1912 return -EINVAL;
1913 }
1914
1915 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1916 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1917 i40e_flush(hw);
1918
1919 return 0;
1920}
1921
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001922/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001923 * i40e_match_fdir_input_set - Match a new filter against an existing one
1924 * @rule: The filter already added
1925 * @input: The new filter to comapre against
1926 *
1927 * Returns true if the two input set match
1928 **/
1929static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1930 struct i40e_fdir_filter *input)
1931{
1932 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1933 (rule->src_ip[0] != input->src_ip[0]) ||
1934 (rule->dst_port != input->dst_port) ||
1935 (rule->src_port != input->src_port))
1936 return false;
1937 return true;
1938}
1939
1940/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001941 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1942 * @vsi: Pointer to the targeted VSI
1943 * @input: The filter to update or NULL to indicate deletion
1944 * @sw_idx: Software index to the filter
1945 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001946 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001947 * This function updates (or deletes) a Flow Director entry from
1948 * the hlist of the corresponding PF
1949 *
1950 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001951 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001952static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1953 struct i40e_fdir_filter *input,
1954 u16 sw_idx,
1955 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001956{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001957 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001958 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001959 struct hlist_node *node2;
1960 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001961
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001962 parent = NULL;
1963 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001964
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001965 hlist_for_each_entry_safe(rule, node2,
1966 &pf->fdir_filter_list, fdir_node) {
1967 /* hash found, or no matching entry */
1968 if (rule->fd_id >= sw_idx)
1969 break;
1970 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001971 }
1972
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001973 /* if there is an old rule occupying our place remove it */
1974 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001975 if (input && !i40e_match_fdir_input_set(rule, input))
1976 err = i40e_add_del_fdir(vsi, rule, false);
1977 else if (!input)
1978 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001979 hlist_del(&rule->fdir_node);
1980 kfree(rule);
1981 pf->fdir_pf_active_filters--;
1982 }
1983
1984 /* If no input this was a delete, err should be 0 if a rule was
1985 * successfully found and removed from the list else -EINVAL
1986 */
1987 if (!input)
1988 return err;
1989
1990 /* initialize node and set software index */
1991 INIT_HLIST_NODE(&input->fdir_node);
1992
1993 /* add filter to the list */
1994 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07001995 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001996 else
1997 hlist_add_head(&input->fdir_node,
1998 &pf->fdir_filter_list);
1999
2000 /* update counts */
2001 pf->fdir_pf_active_filters++;
2002
2003 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002004}
2005
2006/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002007 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2008 * @vsi: Pointer to the targeted VSI
2009 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002010 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002011 * The function removes a Flow Director filter entry from the
2012 * hlist of the corresponding PF
2013 *
2014 * Returns 0 on success
2015 */
2016static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2017 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002018{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002019 struct ethtool_rx_flow_spec *fsp =
2020 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002021 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002022 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002023
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002024 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2025 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2026 return -EBUSY;
2027
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002028 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2029 return -EBUSY;
2030
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002031 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002032
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002033 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002034 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002035}
2036
2037/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002038 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002039 * @vsi: pointer to the targeted VSI
2040 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002041 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002042 * Add Flow Director filters for a specific flow spec based on their
2043 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002044 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002045static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2046 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002047{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002048 struct ethtool_rx_flow_spec *fsp;
2049 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002050 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002051 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002052
2053 if (!vsi)
2054 return -EINVAL;
2055
2056 pf = vsi->back;
2057
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002058 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2059 return -EOPNOTSUPP;
2060
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002061 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002062 return -ENOSPC;
2063
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002064 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2065 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2066 return -EBUSY;
2067
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002068 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2069 return -EBUSY;
2070
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002071 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2072
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002073 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2074 pf->hw.func_caps.fd_filters_guaranteed)) {
2075 return -EINVAL;
2076 }
2077
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002078 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2079 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002080 return -EINVAL;
2081
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002082 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002083
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002084 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002085 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002086
2087 input->fd_id = fsp->location;
2088
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002089 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2090 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2091 else
2092 input->dest_ctl =
2093 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2094
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002095 input->q_index = fsp->ring_cookie;
2096 input->flex_off = 0;
2097 input->pctype = 0;
2098 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002099 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00002100 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002101 input->flow_type = fsp->flow_type;
2102 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002103
2104 /* Reverse the src and dest notion, since the HW expects them to be from
2105 * Tx perspective where as the input from user is from Rx filter view.
2106 */
2107 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2108 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2109 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2110 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002111
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002112 ret = i40e_add_del_fdir(vsi, input, true);
2113 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002114 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002115 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002116 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002117
2118 return ret;
2119}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002120
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002121/**
2122 * i40e_set_rxnfc - command to set RX flow classification rules
2123 * @netdev: network interface device structure
2124 * @cmd: ethtool rxnfc command
2125 *
2126 * Returns Success if the command is supported.
2127 **/
2128static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2129{
2130 struct i40e_netdev_priv *np = netdev_priv(netdev);
2131 struct i40e_vsi *vsi = np->vsi;
2132 struct i40e_pf *pf = vsi->back;
2133 int ret = -EOPNOTSUPP;
2134
2135 switch (cmd->cmd) {
2136 case ETHTOOL_SRXFH:
2137 ret = i40e_set_rss_hash_opt(pf, cmd);
2138 break;
2139 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002140 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002141 break;
2142 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002143 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002144 break;
2145 default:
2146 break;
2147 }
2148
2149 return ret;
2150}
2151
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002152/**
2153 * i40e_max_channels - get Max number of combined channels supported
2154 * @vsi: vsi pointer
2155 **/
2156static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2157{
2158 /* TODO: This code assumes DCB and FD is disabled for now. */
2159 return vsi->alloc_queue_pairs;
2160}
2161
2162/**
2163 * i40e_get_channels - Get the current channels enabled and max supported etc.
2164 * @netdev: network interface device structure
2165 * @ch: ethtool channels structure
2166 *
2167 * We don't support separate tx and rx queues as channels. The other count
2168 * represents how many queues are being used for control. max_combined counts
2169 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2170 * q_vectors since we support a lot more queue pairs than q_vectors.
2171 **/
2172static void i40e_get_channels(struct net_device *dev,
2173 struct ethtool_channels *ch)
2174{
2175 struct i40e_netdev_priv *np = netdev_priv(dev);
2176 struct i40e_vsi *vsi = np->vsi;
2177 struct i40e_pf *pf = vsi->back;
2178
2179 /* report maximum channels */
2180 ch->max_combined = i40e_max_channels(vsi);
2181
2182 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002183 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002184 ch->max_other = ch->other_count;
2185
2186 /* Note: This code assumes DCB is disabled for now. */
2187 ch->combined_count = vsi->num_queue_pairs;
2188}
2189
2190/**
2191 * i40e_set_channels - Set the new channels count.
2192 * @netdev: network interface device structure
2193 * @ch: ethtool channels structure
2194 *
2195 * The new channels count may not be the same as requested by the user
2196 * since it gets rounded down to a power of 2 value.
2197 **/
2198static int i40e_set_channels(struct net_device *dev,
2199 struct ethtool_channels *ch)
2200{
2201 struct i40e_netdev_priv *np = netdev_priv(dev);
2202 unsigned int count = ch->combined_count;
2203 struct i40e_vsi *vsi = np->vsi;
2204 struct i40e_pf *pf = vsi->back;
2205 int new_count;
2206
2207 /* We do not support setting channels for any other VSI at present */
2208 if (vsi->type != I40E_VSI_MAIN)
2209 return -EINVAL;
2210
2211 /* verify they are not requesting separate vectors */
2212 if (!count || ch->rx_count || ch->tx_count)
2213 return -EINVAL;
2214
2215 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002216 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002217 return -EINVAL;
2218
2219 /* verify the number of channels does not exceed hardware limits */
2220 if (count > i40e_max_channels(vsi))
2221 return -EINVAL;
2222
2223 /* update feature limits from largest to smallest supported values */
2224 /* TODO: Flow director limit, DCB etc */
2225
2226 /* cap RSS limit */
2227 if (count > pf->rss_size_max)
2228 count = pf->rss_size_max;
2229
2230 /* use rss_reconfig to rebuild with new queue count and update traffic
2231 * class queue mapping
2232 */
2233 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002234 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002235 return 0;
2236 else
2237 return -EINVAL;
2238}
2239
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002240static const struct ethtool_ops i40e_ethtool_ops = {
2241 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002242 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002243 .get_drvinfo = i40e_get_drvinfo,
2244 .get_regs_len = i40e_get_regs_len,
2245 .get_regs = i40e_get_regs,
2246 .nway_reset = i40e_nway_reset,
2247 .get_link = ethtool_op_get_link,
2248 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002249 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002250 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002251 .get_eeprom_len = i40e_get_eeprom_len,
2252 .get_eeprom = i40e_get_eeprom,
2253 .get_ringparam = i40e_get_ringparam,
2254 .set_ringparam = i40e_set_ringparam,
2255 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002256 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002257 .get_msglevel = i40e_get_msglevel,
2258 .set_msglevel = i40e_set_msglevel,
2259 .get_rxnfc = i40e_get_rxnfc,
2260 .set_rxnfc = i40e_set_rxnfc,
2261 .self_test = i40e_diag_test,
2262 .get_strings = i40e_get_strings,
2263 .set_phys_id = i40e_set_phys_id,
2264 .get_sset_count = i40e_get_sset_count,
2265 .get_ethtool_stats = i40e_get_ethtool_stats,
2266 .get_coalesce = i40e_get_coalesce,
2267 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002268 .get_channels = i40e_get_channels,
2269 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002270 .get_ts_info = i40e_get_ts_info,
2271};
2272
2273void i40e_set_ethtool_ops(struct net_device *netdev)
2274{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002275 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002276}