blob: bb1698a7b3d125a5e8bc7839d3aa4cfb3c79318c [file] [log] [blame]
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Greg Rosedc641b72013-12-18 13:45:51 +00004 * Copyright(c) 2013 - 2014 Intel Corporation.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27/* ethtool support for i40e */
28
29#include "i40e.h"
30#include "i40e_diag.h"
31
32struct i40e_stats {
33 char stat_string[ETH_GSTRING_LEN];
34 int sizeof_stat;
35 int stat_offset;
36};
37
38#define I40E_STAT(_type, _name, _stat) { \
39 .stat_string = _name, \
40 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
41 .stat_offset = offsetof(_type, _stat) \
42}
43#define I40E_NETDEV_STAT(_net_stat) \
44 I40E_STAT(struct net_device_stats, #_net_stat, _net_stat)
45#define I40E_PF_STAT(_name, _stat) \
46 I40E_STAT(struct i40e_pf, _name, _stat)
47#define I40E_VSI_STAT(_name, _stat) \
48 I40E_STAT(struct i40e_vsi, _name, _stat)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000049#define I40E_VEB_STAT(_name, _stat) \
50 I40E_STAT(struct i40e_veb, _name, _stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000051
52static const struct i40e_stats i40e_gstrings_net_stats[] = {
53 I40E_NETDEV_STAT(rx_packets),
54 I40E_NETDEV_STAT(tx_packets),
55 I40E_NETDEV_STAT(rx_bytes),
56 I40E_NETDEV_STAT(tx_bytes),
57 I40E_NETDEV_STAT(rx_errors),
58 I40E_NETDEV_STAT(tx_errors),
59 I40E_NETDEV_STAT(rx_dropped),
60 I40E_NETDEV_STAT(tx_dropped),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000061 I40E_NETDEV_STAT(collisions),
62 I40E_NETDEV_STAT(rx_length_errors),
63 I40E_NETDEV_STAT(rx_crc_errors),
64};
65
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000066static const struct i40e_stats i40e_gstrings_veb_stats[] = {
67 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
68 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
69 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
70 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
71 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
72 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
73 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
74 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
75 I40E_VEB_STAT("rx_discards", stats.rx_discards),
76 I40E_VEB_STAT("tx_discards", stats.tx_discards),
77 I40E_VEB_STAT("tx_errors", stats.tx_errors),
78 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
79};
80
Shannon Nelson41a9e552014-04-23 04:50:20 +000081static const struct i40e_stats i40e_gstrings_misc_stats[] = {
Shannon Nelson418631d2014-04-23 04:50:07 +000082 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
83 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
84 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
85 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
Shannon Nelson41a9e552014-04-23 04:50:20 +000086 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
87 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
Shannon Nelson418631d2014-04-23 04:50:07 +000088 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
Shannon Nelson41a9e552014-04-23 04:50:20 +000089};
90
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +000091static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
92 struct ethtool_rxnfc *cmd);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +000093
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000094/* These PF_STATs might look like duplicates of some NETDEV_STATs,
95 * but they are separate. This device supports Virtualization, and
96 * as such might have several netdevs supporting VMDq and FCoE going
97 * through a single port. The NETDEV_STATs are for individual netdevs
98 * seen at the top of the stack, and the PF_STATs are for the physical
99 * function at the bottom of the stack hosting those netdevs.
100 *
101 * The PF_STATs are appended to the netdev stats only when ethtool -S
102 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
103 */
104static struct i40e_stats i40e_gstrings_stats[] = {
105 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
106 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000107 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
108 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
109 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
110 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
111 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
112 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000113 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
114 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
115 I40E_PF_STAT("tx_dropped", stats.eth.tx_discards),
116 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
117 I40E_PF_STAT("crc_errors", stats.crc_errors),
118 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
119 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
120 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000121 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000122 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000123 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
124 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
125 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
126 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
127 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
128 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
129 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
130 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
131 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
132 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
133 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
134 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
135 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
136 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
137 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
138 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
139 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
140 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
141 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
142 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
143 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
144 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
145 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
146 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000147 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000148 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000149 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
150 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
151
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000152 /* LPI stats */
153 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
154 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
155 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
156 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000157};
158
Vasu Dev38e00432014-08-01 13:27:03 -0700159#ifdef I40E_FCOE
160static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
161 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
162 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
163 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
164 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
165 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
166 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
167 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
168 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
169};
170
171#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000172#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000173 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
174 * 2 /* Tx and Rx together */ \
175 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000176#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
177#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000178#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700179#ifdef I40E_FCOE
180#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
181#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
182 I40E_FCOE_STATS_LEN + \
183 I40E_MISC_STATS_LEN + \
184 I40E_QUEUE_STATS_LEN((n)))
185#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000186#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000187 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000188 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700189#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000190#define I40E_PFC_STATS_LEN ( \
191 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
192 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
193 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
194 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
196 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000197#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000198#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
199 I40E_PFC_STATS_LEN + \
200 I40E_VSI_STATS_LEN((n)))
201
202enum i40e_ethtool_test_id {
203 I40E_ETH_TEST_REG = 0,
204 I40E_ETH_TEST_EEPROM,
205 I40E_ETH_TEST_INTR,
206 I40E_ETH_TEST_LOOPBACK,
207 I40E_ETH_TEST_LINK,
208};
209
210static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
211 "Register test (offline)",
212 "Eeprom test (offline)",
213 "Interrupt test (offline)",
214 "Loopback test (offline)",
215 "Link test (on/offline)"
216};
217
218#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
219
220/**
221 * i40e_get_settings - Get Link Speed and Duplex settings
222 * @netdev: network interface device structure
223 * @ecmd: ethtool command
224 *
225 * Reports speed/duplex settings based on media_type
226 **/
227static int i40e_get_settings(struct net_device *netdev,
228 struct ethtool_cmd *ecmd)
229{
230 struct i40e_netdev_priv *np = netdev_priv(netdev);
231 struct i40e_pf *pf = np->vsi->back;
232 struct i40e_hw *hw = &pf->hw;
233 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
234 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
235 u32 link_speed = hw_link_info->link_speed;
236
237 /* hardware is either in 40G mode or 10G mode
238 * NOTE: this section initializes supported and advertising
239 */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000240 if (!link_up) {
241 /* link is down and the driver needs to fall back on
242 * device ID to determine what kinds of info to display,
243 * it's mostly a guess that may change when link is up
244 */
245 switch (hw->device_id) {
246 case I40E_DEV_ID_QSFP_A:
247 case I40E_DEV_ID_QSFP_B:
248 case I40E_DEV_ID_QSFP_C:
249 /* pluggable QSFP */
250 ecmd->supported = SUPPORTED_40000baseSR4_Full |
251 SUPPORTED_40000baseCR4_Full |
252 SUPPORTED_40000baseLR4_Full;
253 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
254 ADVERTISED_40000baseCR4_Full |
255 ADVERTISED_40000baseLR4_Full;
256 break;
257 case I40E_DEV_ID_KX_B:
258 /* backplane 40G */
259 ecmd->supported = SUPPORTED_40000baseKR4_Full;
260 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
261 break;
262 case I40E_DEV_ID_KX_C:
263 /* backplane 10G */
264 ecmd->supported = SUPPORTED_10000baseKR_Full;
265 ecmd->advertising = ADVERTISED_10000baseKR_Full;
266 break;
Mitch Williams5960d332014-09-13 07:40:47 +0000267 case I40E_DEV_ID_10G_BASE_T:
268 ecmd->supported = SUPPORTED_10000baseT_Full |
269 SUPPORTED_1000baseT_Full |
270 SUPPORTED_100baseT_Full;
271 ecmd->advertising = ADVERTISED_10000baseT_Full |
272 ADVERTISED_1000baseT_Full |
273 ADVERTISED_100baseT_Full;
274 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000275 default:
276 /* all the rest are 10G/1G */
277 ecmd->supported = SUPPORTED_10000baseT_Full |
278 SUPPORTED_1000baseT_Full;
279 ecmd->advertising = ADVERTISED_10000baseT_Full |
280 ADVERTISED_1000baseT_Full;
281 break;
282 }
283
284 /* skip phy_type use as it is zero when link is down */
285 goto no_valid_phy_type;
286 }
287
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000288 switch (hw_link_info->phy_type) {
289 case I40E_PHY_TYPE_40GBASE_CR4:
290 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000291 ecmd->supported = SUPPORTED_Autoneg |
292 SUPPORTED_40000baseCR4_Full;
293 ecmd->advertising = ADVERTISED_Autoneg |
294 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000295 break;
296 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000297 ecmd->supported = SUPPORTED_Autoneg |
298 SUPPORTED_40000baseKR4_Full;
299 ecmd->advertising = ADVERTISED_Autoneg |
300 ADVERTISED_40000baseKR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000301 break;
302 case I40E_PHY_TYPE_40GBASE_SR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000303 case I40E_PHY_TYPE_XLPPI:
304 case I40E_PHY_TYPE_XLAUI:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000305 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000306 break;
307 case I40E_PHY_TYPE_40GBASE_LR4:
308 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000309 break;
310 case I40E_PHY_TYPE_10GBASE_KX4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000311 ecmd->supported = SUPPORTED_Autoneg |
312 SUPPORTED_10000baseKX4_Full;
313 ecmd->advertising = ADVERTISED_Autoneg |
314 ADVERTISED_10000baseKX4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000315 break;
316 case I40E_PHY_TYPE_10GBASE_KR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000317 ecmd->supported = SUPPORTED_Autoneg |
318 SUPPORTED_10000baseKR_Full;
319 ecmd->advertising = ADVERTISED_Autoneg |
320 ADVERTISED_10000baseKR_Full;
321 break;
322 case I40E_PHY_TYPE_10GBASE_SR:
323 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000324 case I40E_PHY_TYPE_1000BASE_SX:
325 case I40E_PHY_TYPE_1000BASE_LX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000326 ecmd->supported = SUPPORTED_10000baseT_Full;
Catherine Sullivan124ed152014-07-12 07:28:12 +0000327 ecmd->supported |= SUPPORTED_1000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000328 break;
329 case I40E_PHY_TYPE_10GBASE_CR1_CU:
330 case I40E_PHY_TYPE_10GBASE_CR1:
331 case I40E_PHY_TYPE_10GBASE_T:
332 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000333 SUPPORTED_10000baseT_Full |
334 SUPPORTED_1000baseT_Full |
335 SUPPORTED_100baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000336 ecmd->advertising = ADVERTISED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000337 ADVERTISED_10000baseT_Full |
338 ADVERTISED_1000baseT_Full |
339 ADVERTISED_100baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000340 break;
341 case I40E_PHY_TYPE_XAUI:
342 case I40E_PHY_TYPE_XFI:
343 case I40E_PHY_TYPE_SFI:
344 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
345 ecmd->supported = SUPPORTED_10000baseT_Full;
346 break;
347 case I40E_PHY_TYPE_1000BASE_KX:
348 case I40E_PHY_TYPE_1000BASE_T:
349 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000350 SUPPORTED_10000baseT_Full |
351 SUPPORTED_1000baseT_Full |
352 SUPPORTED_100baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000353 ecmd->advertising = ADVERTISED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000354 ADVERTISED_10000baseT_Full |
355 ADVERTISED_1000baseT_Full |
356 ADVERTISED_100baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000357 break;
358 case I40E_PHY_TYPE_100BASE_TX:
359 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000360 SUPPORTED_10000baseT_Full |
361 SUPPORTED_1000baseT_Full |
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000362 SUPPORTED_100baseT_Full;
363 ecmd->advertising = ADVERTISED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000364 ADVERTISED_10000baseT_Full |
365 ADVERTISED_1000baseT_Full |
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000366 ADVERTISED_100baseT_Full;
367 break;
368 case I40E_PHY_TYPE_SGMII:
369 ecmd->supported = SUPPORTED_Autoneg |
370 SUPPORTED_1000baseT_Full |
371 SUPPORTED_100baseT_Full;
372 ecmd->advertising = ADVERTISED_Autoneg |
373 ADVERTISED_1000baseT_Full |
374 ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000375 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000376 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000377 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000378 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
379 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000380 }
381
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000382no_valid_phy_type:
383 /* this is if autoneg is enabled or disabled */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000384 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
385 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000386
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000387 switch (hw->phy.media_type) {
388 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000389 ecmd->supported |= SUPPORTED_Autoneg |
390 SUPPORTED_Backplane;
391 ecmd->advertising |= ADVERTISED_Autoneg |
392 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000393 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000394 break;
395 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000396 ecmd->supported |= SUPPORTED_TP;
397 ecmd->advertising |= ADVERTISED_TP;
398 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000399 break;
400 case I40E_MEDIA_TYPE_DA:
401 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000402 ecmd->supported |= SUPPORTED_FIBRE;
403 ecmd->advertising |= ADVERTISED_FIBRE;
404 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000405 break;
406 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000407 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000408 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000409 break;
410 case I40E_MEDIA_TYPE_UNKNOWN:
411 default:
412 ecmd->port = PORT_OTHER;
413 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000414 }
415
416 ecmd->transceiver = XCVR_EXTERNAL;
417
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000418 ecmd->supported |= SUPPORTED_Pause;
419
420 switch (hw->fc.current_mode) {
421 case I40E_FC_FULL:
422 ecmd->advertising |= ADVERTISED_Pause;
423 break;
424 case I40E_FC_TX_PAUSE:
425 ecmd->advertising |= ADVERTISED_Asym_Pause;
426 break;
427 case I40E_FC_RX_PAUSE:
428 ecmd->advertising |= (ADVERTISED_Pause |
429 ADVERTISED_Asym_Pause);
430 break;
431 default:
432 ecmd->advertising &= ~(ADVERTISED_Pause |
433 ADVERTISED_Asym_Pause);
434 break;
435 }
436
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000437 if (link_up) {
438 switch (link_speed) {
439 case I40E_LINK_SPEED_40GB:
440 /* need a SPEED_40000 in ethtool.h */
441 ethtool_cmd_speed_set(ecmd, 40000);
442 break;
443 case I40E_LINK_SPEED_10GB:
444 ethtool_cmd_speed_set(ecmd, SPEED_10000);
445 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000446 case I40E_LINK_SPEED_1GB:
447 ethtool_cmd_speed_set(ecmd, SPEED_1000);
448 break;
Mitch Williams5960d332014-09-13 07:40:47 +0000449 case I40E_LINK_SPEED_100MB:
450 ethtool_cmd_speed_set(ecmd, SPEED_100);
451 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000452 default:
453 break;
454 }
455 ecmd->duplex = DUPLEX_FULL;
456 } else {
457 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
458 ecmd->duplex = DUPLEX_UNKNOWN;
459 }
460
461 return 0;
462}
463
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000464/**
465 * i40e_set_settings - Set Speed and Duplex
466 * @netdev: network interface device structure
467 * @ecmd: ethtool command
468 *
469 * Set speed/duplex per media_types advertised/forced
470 **/
471static int i40e_set_settings(struct net_device *netdev,
472 struct ethtool_cmd *ecmd)
473{
474 struct i40e_netdev_priv *np = netdev_priv(netdev);
475 struct i40e_aq_get_phy_abilities_resp abilities;
476 struct i40e_aq_set_phy_config config;
477 struct i40e_pf *pf = np->vsi->back;
478 struct i40e_vsi *vsi = np->vsi;
479 struct i40e_hw *hw = &pf->hw;
480 struct ethtool_cmd safe_ecmd;
481 i40e_status status = 0;
482 bool change = false;
483 int err = 0;
484 u8 autoneg;
485 u32 advertise;
486
487 if (vsi != pf->vsi[pf->lan_vsi])
488 return -EOPNOTSUPP;
489
490 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
491 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000492 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
493 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000494 return -EOPNOTSUPP;
495
496 /* get our own copy of the bits to check against */
497 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
498 i40e_get_settings(netdev, &safe_ecmd);
499
500 /* save autoneg and speed out of ecmd */
501 autoneg = ecmd->autoneg;
502 advertise = ecmd->advertising;
503
504 /* set autoneg and speed back to what they currently are */
505 ecmd->autoneg = safe_ecmd.autoneg;
506 ecmd->advertising = safe_ecmd.advertising;
507
508 ecmd->cmd = safe_ecmd.cmd;
509 /* If ecmd and safe_ecmd are not the same now, then they are
510 * trying to set something that we do not support
511 */
512 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
513 return -EOPNOTSUPP;
514
515 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
516 usleep_range(1000, 2000);
517
518 /* Get the current phy config */
519 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
520 NULL);
521 if (status)
522 return -EAGAIN;
523
Catherine Sullivan124ed152014-07-12 07:28:12 +0000524 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000525 * set below
526 */
527 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000528 config.abilities = abilities.abilities;
529
530 /* Check autoneg */
531 if (autoneg == AUTONEG_ENABLE) {
532 /* If autoneg is not supported, return error */
533 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
534 netdev_info(netdev, "Autoneg not supported on this phy\n");
535 return -EINVAL;
536 }
537 /* If autoneg was not already enabled */
538 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
539 config.abilities = abilities.abilities |
540 I40E_AQ_PHY_ENABLE_AN;
541 change = true;
542 }
543 } else {
544 /* If autoneg is supported 10GBASE_T is the only phy that
545 * can disable it, so otherwise return error
546 */
547 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
548 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
549 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
550 return -EINVAL;
551 }
552 /* If autoneg is currently enabled */
553 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000554 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000555 ~I40E_AQ_PHY_ENABLE_AN;
556 change = true;
557 }
558 }
559
560 if (advertise & ~safe_ecmd.supported)
561 return -EINVAL;
562
563 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000564 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000565 if (advertise & ADVERTISED_1000baseT_Full ||
566 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000567 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000568 if (advertise & ADVERTISED_10000baseT_Full ||
569 advertise & ADVERTISED_10000baseKX4_Full ||
570 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000571 config.link_speed |= I40E_LINK_SPEED_10GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000572 if (advertise & ADVERTISED_40000baseKR4_Full ||
573 advertise & ADVERTISED_40000baseCR4_Full ||
574 advertise & ADVERTISED_40000baseSR4_Full ||
575 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000576 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000577
Catherine Sullivan124ed152014-07-12 07:28:12 +0000578 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000579 /* copy over the rest of the abilities */
580 config.phy_type = abilities.phy_type;
581 config.eee_capability = abilities.eee_capability;
582 config.eeer = abilities.eeer_val;
583 config.low_power_ctrl = abilities.d3_lpan;
584
Catherine Sullivan94128512014-07-12 07:28:16 +0000585 /* set link and auto negotiation so changes take effect */
586 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
587 /* If link is up put link down */
588 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
589 /* Tell the OS link is going down, the link will go
590 * back up when fw says it is ready asynchronously
591 */
592 netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
593 netif_carrier_off(netdev);
594 netif_tx_stop_all_queues(netdev);
595 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000596
597 /* make the aq call */
598 status = i40e_aq_set_phy_config(hw, &config, NULL);
599 if (status) {
600 netdev_info(netdev, "Set phy config failed with error %d.\n",
601 status);
602 return -EAGAIN;
603 }
604
605 status = i40e_update_link_info(hw, true);
606 if (status)
607 netdev_info(netdev, "Updating link info failed with error %d\n",
608 status);
609
610 } else {
611 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
612 }
613
614 return err;
615}
616
Jesse Brandeburga6599722014-06-04 08:45:25 +0000617static int i40e_nway_reset(struct net_device *netdev)
618{
619 /* restart autonegotiation */
620 struct i40e_netdev_priv *np = netdev_priv(netdev);
621 struct i40e_pf *pf = np->vsi->back;
622 struct i40e_hw *hw = &pf->hw;
623 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
624 i40e_status ret = 0;
625
626 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
627 if (ret) {
628 netdev_info(netdev, "link restart failed, aq_err=%d\n",
629 pf->hw.aq.asq_last_status);
630 return -EIO;
631 }
632
633 return 0;
634}
635
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000636/**
637 * i40e_get_pauseparam - Get Flow Control status
638 * Return tx/rx-pause status
639 **/
640static void i40e_get_pauseparam(struct net_device *netdev,
641 struct ethtool_pauseparam *pause)
642{
643 struct i40e_netdev_priv *np = netdev_priv(netdev);
644 struct i40e_pf *pf = np->vsi->back;
645 struct i40e_hw *hw = &pf->hw;
646 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000647 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000648
649 pause->autoneg =
650 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
651 AUTONEG_ENABLE : AUTONEG_DISABLE);
652
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000653 /* PFC enabled so report LFC as off */
654 if (dcbx_cfg->pfc.pfcenable) {
655 pause->rx_pause = 0;
656 pause->tx_pause = 0;
657 return;
658 }
659
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000660 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000661 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000662 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000663 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000664 } else if (hw->fc.current_mode == I40E_FC_FULL) {
665 pause->rx_pause = 1;
666 pause->tx_pause = 1;
667 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000668}
669
Catherine Sullivan2becc352014-06-04 08:45:27 +0000670/**
671 * i40e_set_pauseparam - Set Flow Control parameter
672 * @netdev: network interface device structure
673 * @pause: return tx/rx flow control status
674 **/
675static int i40e_set_pauseparam(struct net_device *netdev,
676 struct ethtool_pauseparam *pause)
677{
678 struct i40e_netdev_priv *np = netdev_priv(netdev);
679 struct i40e_pf *pf = np->vsi->back;
680 struct i40e_vsi *vsi = np->vsi;
681 struct i40e_hw *hw = &pf->hw;
682 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000683 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000684 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
685 i40e_status status;
686 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000687 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000688
689 if (vsi != pf->vsi[pf->lan_vsi])
690 return -EOPNOTSUPP;
691
692 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
693 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
694 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
695 return -EOPNOTSUPP;
696 }
697
698 /* If we have link and don't have autoneg */
699 if (!test_bit(__I40E_DOWN, &pf->state) &&
700 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
701 /* Send message that it might not necessarily work*/
702 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
703 }
704
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000705 if (dcbx_cfg->pfc.pfcenable) {
706 netdev_info(netdev,
707 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000708 return -EOPNOTSUPP;
709 }
710
711 if (pause->rx_pause && pause->tx_pause)
712 hw->fc.requested_mode = I40E_FC_FULL;
713 else if (pause->rx_pause && !pause->tx_pause)
714 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
715 else if (!pause->rx_pause && pause->tx_pause)
716 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
717 else if (!pause->rx_pause && !pause->tx_pause)
718 hw->fc.requested_mode = I40E_FC_NONE;
719 else
720 return -EINVAL;
721
Catherine Sullivan94128512014-07-12 07:28:16 +0000722 /* Tell the OS link is going down, the link will go back up when fw
723 * says it is ready asynchronously
724 */
725 netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
726 netif_carrier_off(netdev);
727 netif_tx_stop_all_queues(netdev);
728
Catherine Sullivan2becc352014-06-04 08:45:27 +0000729 /* Set the fc mode and only restart an if link is up*/
730 status = i40e_set_fc(hw, &aq_failures, link_up);
731
732 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
733 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
734 status, hw->aq.asq_last_status);
735 err = -EAGAIN;
736 }
737 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
738 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
739 status, hw->aq.asq_last_status);
740 err = -EAGAIN;
741 }
742 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
743 netdev_info(netdev, "Set fc failed on the update_link_info call with error %d and status %d\n",
744 status, hw->aq.asq_last_status);
745 err = -EAGAIN;
746 }
747
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000748 if (!test_bit(__I40E_DOWN, &pf->state)) {
749 /* Give it a little more time to try to come back */
750 msleep(75);
751 if (!test_bit(__I40E_DOWN, &pf->state))
752 return i40e_nway_reset(netdev);
753 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000754
755 return err;
756}
757
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000758static u32 i40e_get_msglevel(struct net_device *netdev)
759{
760 struct i40e_netdev_priv *np = netdev_priv(netdev);
761 struct i40e_pf *pf = np->vsi->back;
762
763 return pf->msg_enable;
764}
765
766static void i40e_set_msglevel(struct net_device *netdev, u32 data)
767{
768 struct i40e_netdev_priv *np = netdev_priv(netdev);
769 struct i40e_pf *pf = np->vsi->back;
770
771 if (I40E_DEBUG_USER & data)
772 pf->hw.debug_mask = data;
773 pf->msg_enable = data;
774}
775
776static int i40e_get_regs_len(struct net_device *netdev)
777{
778 int reg_count = 0;
779 int i;
780
781 for (i = 0; i40e_reg_list[i].offset != 0; i++)
782 reg_count += i40e_reg_list[i].elements;
783
784 return reg_count * sizeof(u32);
785}
786
787static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
788 void *p)
789{
790 struct i40e_netdev_priv *np = netdev_priv(netdev);
791 struct i40e_pf *pf = np->vsi->back;
792 struct i40e_hw *hw = &pf->hw;
793 u32 *reg_buf = p;
794 int i, j, ri;
795 u32 reg;
796
797 /* Tell ethtool which driver-version-specific regs output we have.
798 *
799 * At some point, if we have ethtool doing special formatting of
800 * this data, it will rely on this version number to know how to
801 * interpret things. Hence, this needs to be updated if/when the
802 * diags register table is changed.
803 */
804 regs->version = 1;
805
806 /* loop through the diags reg table for what to print */
807 ri = 0;
808 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
809 for (j = 0; j < i40e_reg_list[i].elements; j++) {
810 reg = i40e_reg_list[i].offset
811 + (j * i40e_reg_list[i].stride);
812 reg_buf[ri++] = rd32(hw, reg);
813 }
814 }
815
816}
817
818static int i40e_get_eeprom(struct net_device *netdev,
819 struct ethtool_eeprom *eeprom, u8 *bytes)
820{
821 struct i40e_netdev_priv *np = netdev_priv(netdev);
822 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000823 struct i40e_pf *pf = np->vsi->back;
824 int ret_val = 0, len;
825 u8 *eeprom_buff;
826 u16 i, sectors;
827 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000828 u32 magic;
829
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000830#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000831 if (eeprom->len == 0)
832 return -EINVAL;
833
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000834 /* check for NVMUpdate access method */
835 magic = hw->vendor_id | (hw->device_id << 16);
836 if (eeprom->magic && eeprom->magic != magic) {
837 int errno;
838
839 /* make sure it is the right magic for NVMUpdate */
840 if ((eeprom->magic >> 16) != hw->device_id)
841 return -EINVAL;
842
843 ret_val = i40e_nvmupd_command(hw,
844 (struct i40e_nvm_access *)eeprom,
845 bytes, &errno);
846 if (ret_val)
847 dev_info(&pf->pdev->dev,
848 "NVMUpdate read failed err=%d status=0x%x\n",
849 ret_val, hw->aq.asq_last_status);
850
851 return errno;
852 }
853
854 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000855 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
856
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000857 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000858 if (!eeprom_buff)
859 return -ENOMEM;
860
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000861 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
862 if (ret_val) {
863 dev_info(&pf->pdev->dev,
864 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
865 ret_val, hw->aq.asq_last_status);
866 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000867 }
868
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000869 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
870 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
871 len = I40E_NVM_SECTOR_SIZE;
872 last = false;
873 for (i = 0; i < sectors; i++) {
874 if (i == (sectors - 1)) {
875 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
876 last = true;
877 }
878 ret_val = i40e_aq_read_nvm(hw, 0x0,
879 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
880 len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000881 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000882 last, NULL);
883 if (ret_val) {
884 dev_info(&pf->pdev->dev,
885 "read NVM failed err=%d status=0x%x\n",
886 ret_val, hw->aq.asq_last_status);
887 goto release_nvm;
888 }
889 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000890
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000891release_nvm:
892 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000893 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000894free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000895 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000896 return ret_val;
897}
898
899static int i40e_get_eeprom_len(struct net_device *netdev)
900{
901 struct i40e_netdev_priv *np = netdev_priv(netdev);
902 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000903 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000904
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000905 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
906 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
907 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
908 /* register returns value in power of 2, 64Kbyte chunks. */
909 val = (64 * 1024) * (1 << val);
910 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000911}
912
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000913static int i40e_set_eeprom(struct net_device *netdev,
914 struct ethtool_eeprom *eeprom, u8 *bytes)
915{
916 struct i40e_netdev_priv *np = netdev_priv(netdev);
917 struct i40e_hw *hw = &np->vsi->back->hw;
918 struct i40e_pf *pf = np->vsi->back;
919 int ret_val = 0;
920 int errno;
921 u32 magic;
922
923 /* normal ethtool set_eeprom is not supported */
924 magic = hw->vendor_id | (hw->device_id << 16);
925 if (eeprom->magic == magic)
926 return -EOPNOTSUPP;
927
928 /* check for NVMUpdate access method */
929 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
930 return -EINVAL;
931
932 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
933 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
934 return -EBUSY;
935
936 ret_val = i40e_nvmupd_command(hw, (struct i40e_nvm_access *)eeprom,
937 bytes, &errno);
938 if (ret_val)
939 dev_info(&pf->pdev->dev,
940 "NVMUpdate write failed err=%d status=0x%x\n",
941 ret_val, hw->aq.asq_last_status);
942
943 return errno;
944}
945
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000946static void i40e_get_drvinfo(struct net_device *netdev,
947 struct ethtool_drvinfo *drvinfo)
948{
949 struct i40e_netdev_priv *np = netdev_priv(netdev);
950 struct i40e_vsi *vsi = np->vsi;
951 struct i40e_pf *pf = vsi->back;
952
953 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
954 strlcpy(drvinfo->version, i40e_driver_version_str,
955 sizeof(drvinfo->version));
956 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
957 sizeof(drvinfo->fw_version));
958 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
959 sizeof(drvinfo->bus_info));
960}
961
962static void i40e_get_ringparam(struct net_device *netdev,
963 struct ethtool_ringparam *ring)
964{
965 struct i40e_netdev_priv *np = netdev_priv(netdev);
966 struct i40e_pf *pf = np->vsi->back;
967 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
968
969 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
970 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
971 ring->rx_mini_max_pending = 0;
972 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +0000973 ring->rx_pending = vsi->rx_rings[0]->count;
974 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000975 ring->rx_mini_pending = 0;
976 ring->rx_jumbo_pending = 0;
977}
978
979static int i40e_set_ringparam(struct net_device *netdev,
980 struct ethtool_ringparam *ring)
981{
982 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
983 struct i40e_netdev_priv *np = netdev_priv(netdev);
984 struct i40e_vsi *vsi = np->vsi;
985 struct i40e_pf *pf = vsi->back;
986 u32 new_rx_count, new_tx_count;
987 int i, err = 0;
988
989 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
990 return -EINVAL;
991
Shannon Nelson1fa18372013-11-20 10:03:08 +0000992 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
993 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
994 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
995 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
996 netdev_info(netdev,
997 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
998 ring->tx_pending, ring->rx_pending,
999 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1000 return -EINVAL;
1001 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001002
Shannon Nelson1fa18372013-11-20 10:03:08 +00001003 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1004 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001005
1006 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001007 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1008 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001009 return 0;
1010
1011 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1012 usleep_range(1000, 2000);
1013
1014 if (!netif_running(vsi->netdev)) {
1015 /* simple case - set for the next time the netdev is started */
1016 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001017 vsi->tx_rings[i]->count = new_tx_count;
1018 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001019 }
1020 goto done;
1021 }
1022
1023 /* We can't just free everything and then setup again,
1024 * because the ISRs in MSI-X mode get passed pointers
1025 * to the Tx and Rx ring structs.
1026 */
1027
1028 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001029 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001030 netdev_info(netdev,
1031 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001032 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001033 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1034 sizeof(struct i40e_ring), GFP_KERNEL);
1035 if (!tx_rings) {
1036 err = -ENOMEM;
1037 goto done;
1038 }
1039
1040 for (i = 0; i < vsi->num_queue_pairs; i++) {
1041 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001042 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001043 tx_rings[i].count = new_tx_count;
1044 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1045 if (err) {
1046 while (i) {
1047 i--;
1048 i40e_free_tx_resources(&tx_rings[i]);
1049 }
1050 kfree(tx_rings);
1051 tx_rings = NULL;
1052
1053 goto done;
1054 }
1055 }
1056 }
1057
1058 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001059 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001060 netdev_info(netdev,
1061 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001062 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001063 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1064 sizeof(struct i40e_ring), GFP_KERNEL);
1065 if (!rx_rings) {
1066 err = -ENOMEM;
1067 goto free_tx;
1068 }
1069
1070 for (i = 0; i < vsi->num_queue_pairs; i++) {
1071 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001072 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001073 rx_rings[i].count = new_rx_count;
1074 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1075 if (err) {
1076 while (i) {
1077 i--;
1078 i40e_free_rx_resources(&rx_rings[i]);
1079 }
1080 kfree(rx_rings);
1081 rx_rings = NULL;
1082
1083 goto free_tx;
1084 }
1085 }
1086 }
1087
1088 /* Bring interface down, copy in the new ring info,
1089 * then restore the interface
1090 */
1091 i40e_down(vsi);
1092
1093 if (tx_rings) {
1094 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001095 i40e_free_tx_resources(vsi->tx_rings[i]);
1096 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001097 }
1098 kfree(tx_rings);
1099 tx_rings = NULL;
1100 }
1101
1102 if (rx_rings) {
1103 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001104 i40e_free_rx_resources(vsi->rx_rings[i]);
1105 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001106 }
1107 kfree(rx_rings);
1108 rx_rings = NULL;
1109 }
1110
1111 i40e_up(vsi);
1112
1113free_tx:
1114 /* error cleanup if the Rx allocations failed after getting Tx */
1115 if (tx_rings) {
1116 for (i = 0; i < vsi->num_queue_pairs; i++)
1117 i40e_free_tx_resources(&tx_rings[i]);
1118 kfree(tx_rings);
1119 tx_rings = NULL;
1120 }
1121
1122done:
1123 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1124
1125 return err;
1126}
1127
1128static int i40e_get_sset_count(struct net_device *netdev, int sset)
1129{
1130 struct i40e_netdev_priv *np = netdev_priv(netdev);
1131 struct i40e_vsi *vsi = np->vsi;
1132 struct i40e_pf *pf = vsi->back;
1133
1134 switch (sset) {
1135 case ETH_SS_TEST:
1136 return I40E_TEST_LEN;
1137 case ETH_SS_STATS:
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001138 if (vsi == pf->vsi[pf->lan_vsi]) {
1139 int len = I40E_PF_STATS_LEN(netdev);
1140
1141 if (pf->lan_veb != I40E_NO_VEB)
1142 len += I40E_VEB_STATS_LEN;
1143 return len;
1144 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001145 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001146 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001147 default:
1148 return -EOPNOTSUPP;
1149 }
1150}
1151
1152static void i40e_get_ethtool_stats(struct net_device *netdev,
1153 struct ethtool_stats *stats, u64 *data)
1154{
1155 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001156 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001157 struct i40e_vsi *vsi = np->vsi;
1158 struct i40e_pf *pf = vsi->back;
1159 int i = 0;
1160 char *p;
1161 int j;
1162 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001163 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001164
1165 i40e_update_stats(vsi);
1166
1167 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1168 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1169 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1170 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1171 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001172 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1173 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1174 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1175 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1176 }
Vasu Dev38e00432014-08-01 13:27:03 -07001177#ifdef I40E_FCOE
1178 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1179 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1180 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1181 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1182 }
1183#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001184 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001185 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001186 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001187
1188 if (!tx_ring)
1189 continue;
1190
1191 /* process Tx ring statistics */
1192 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001193 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001194 data[i] = tx_ring->stats.packets;
1195 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001196 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001197 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001198
1199 /* Rx ring is the 2nd half of the queue pair */
1200 rx_ring = &tx_ring[1];
1201 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001202 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001203 data[i] = rx_ring->stats.packets;
1204 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001205 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001206 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001207 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001208 rcu_read_unlock();
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001209 if (vsi != pf->vsi[pf->lan_vsi])
1210 return;
1211
1212 if (pf->lan_veb != I40E_NO_VEB) {
1213 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1214 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1215 p = (char *)veb;
1216 p += i40e_gstrings_veb_stats[j].stat_offset;
1217 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1218 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001219 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001220 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001221 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1222 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1223 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1224 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1225 }
1226 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1227 data[i++] = pf->stats.priority_xon_tx[j];
1228 data[i++] = pf->stats.priority_xoff_tx[j];
1229 }
1230 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1231 data[i++] = pf->stats.priority_xon_rx[j];
1232 data[i++] = pf->stats.priority_xoff_rx[j];
1233 }
1234 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1235 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001236}
1237
1238static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1239 u8 *data)
1240{
1241 struct i40e_netdev_priv *np = netdev_priv(netdev);
1242 struct i40e_vsi *vsi = np->vsi;
1243 struct i40e_pf *pf = vsi->back;
1244 char *p = (char *)data;
1245 int i;
1246
1247 switch (stringset) {
1248 case ETH_SS_TEST:
1249 for (i = 0; i < I40E_TEST_LEN; i++) {
1250 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1251 data += ETH_GSTRING_LEN;
1252 }
1253 break;
1254 case ETH_SS_STATS:
1255 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1256 snprintf(p, ETH_GSTRING_LEN, "%s",
1257 i40e_gstrings_net_stats[i].stat_string);
1258 p += ETH_GSTRING_LEN;
1259 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001260 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1261 snprintf(p, ETH_GSTRING_LEN, "%s",
1262 i40e_gstrings_misc_stats[i].stat_string);
1263 p += ETH_GSTRING_LEN;
1264 }
Vasu Dev38e00432014-08-01 13:27:03 -07001265#ifdef I40E_FCOE
1266 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1267 snprintf(p, ETH_GSTRING_LEN, "%s",
1268 i40e_gstrings_fcoe_stats[i].stat_string);
1269 p += ETH_GSTRING_LEN;
1270 }
1271#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001272 for (i = 0; i < vsi->num_queue_pairs; i++) {
1273 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1274 p += ETH_GSTRING_LEN;
1275 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1276 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001277 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1278 p += ETH_GSTRING_LEN;
1279 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1280 p += ETH_GSTRING_LEN;
1281 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001282 if (vsi != pf->vsi[pf->lan_vsi])
1283 return;
1284
1285 if (pf->lan_veb != I40E_NO_VEB) {
1286 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1287 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1288 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001289 p += ETH_GSTRING_LEN;
1290 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001291 }
1292 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1293 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1294 i40e_gstrings_stats[i].stat_string);
1295 p += ETH_GSTRING_LEN;
1296 }
1297 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1298 snprintf(p, ETH_GSTRING_LEN,
1299 "port.tx_priority_%u_xon", i);
1300 p += ETH_GSTRING_LEN;
1301 snprintf(p, ETH_GSTRING_LEN,
1302 "port.tx_priority_%u_xoff", i);
1303 p += ETH_GSTRING_LEN;
1304 }
1305 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1306 snprintf(p, ETH_GSTRING_LEN,
1307 "port.rx_priority_%u_xon", i);
1308 p += ETH_GSTRING_LEN;
1309 snprintf(p, ETH_GSTRING_LEN,
1310 "port.rx_priority_%u_xoff", i);
1311 p += ETH_GSTRING_LEN;
1312 }
1313 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1314 snprintf(p, ETH_GSTRING_LEN,
1315 "port.rx_priority_%u_xon_2_xoff", i);
1316 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001317 }
1318 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1319 break;
1320 }
1321}
1322
1323static int i40e_get_ts_info(struct net_device *dev,
1324 struct ethtool_ts_info *info)
1325{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001326 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1327
1328 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1329 SOF_TIMESTAMPING_RX_SOFTWARE |
1330 SOF_TIMESTAMPING_SOFTWARE |
1331 SOF_TIMESTAMPING_TX_HARDWARE |
1332 SOF_TIMESTAMPING_RX_HARDWARE |
1333 SOF_TIMESTAMPING_RAW_HARDWARE;
1334
1335 if (pf->ptp_clock)
1336 info->phc_index = ptp_clock_index(pf->ptp_clock);
1337 else
1338 info->phc_index = -1;
1339
1340 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1341
1342 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1343 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1344 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1345 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1346 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1347 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1348 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1349 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1350 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1351 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1352 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1353 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1354
1355 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001356}
1357
Shannon Nelson7b086392013-11-20 10:02:59 +00001358static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001359{
Shannon Nelson7b086392013-11-20 10:02:59 +00001360 struct i40e_netdev_priv *np = netdev_priv(netdev);
1361 struct i40e_pf *pf = np->vsi->back;
1362
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001363 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001364 if (i40e_get_link_status(&pf->hw))
1365 *data = 0;
1366 else
1367 *data = 1;
1368
1369 return *data;
1370}
1371
Shannon Nelson7b086392013-11-20 10:02:59 +00001372static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001373{
Shannon Nelson7b086392013-11-20 10:02:59 +00001374 struct i40e_netdev_priv *np = netdev_priv(netdev);
1375 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001376
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001377 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001378 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001379
Shannon Nelson7b086392013-11-20 10:02:59 +00001380 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001381}
1382
Shannon Nelson7b086392013-11-20 10:02:59 +00001383static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001384{
Shannon Nelson7b086392013-11-20 10:02:59 +00001385 struct i40e_netdev_priv *np = netdev_priv(netdev);
1386 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001387
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001388 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001389 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001390
Shannon Nelson7b086392013-11-20 10:02:59 +00001391 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001392}
1393
Shannon Nelson7b086392013-11-20 10:02:59 +00001394static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001395{
Shannon Nelson7b086392013-11-20 10:02:59 +00001396 struct i40e_netdev_priv *np = netdev_priv(netdev);
1397 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001398 u16 swc_old = pf->sw_int_count;
1399
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001400 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001401 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1402 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
1403 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
1404 usleep_range(1000, 2000);
1405 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001406
1407 return *data;
1408}
1409
Shannon Nelson7b086392013-11-20 10:02:59 +00001410static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001411{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001412 struct i40e_netdev_priv *np = netdev_priv(netdev);
1413 struct i40e_pf *pf = np->vsi->back;
1414
1415 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001416 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001417
1418 return *data;
1419}
1420
1421static void i40e_diag_test(struct net_device *netdev,
1422 struct ethtool_test *eth_test, u64 *data)
1423{
1424 struct i40e_netdev_priv *np = netdev_priv(netdev);
1425 struct i40e_pf *pf = np->vsi->back;
1426
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001427 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1428 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001429 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001430
Shannon Nelsonf551b432013-11-26 10:49:12 +00001431 set_bit(__I40E_TESTING, &pf->state);
1432
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001433 /* Link test performed before hardware reset
1434 * so autoneg doesn't interfere with test result
1435 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001436 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001437 eth_test->flags |= ETH_TEST_FL_FAILED;
1438
Shannon Nelson7b086392013-11-20 10:02:59 +00001439 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001440 eth_test->flags |= ETH_TEST_FL_FAILED;
1441
Shannon Nelson7b086392013-11-20 10:02:59 +00001442 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001443 eth_test->flags |= ETH_TEST_FL_FAILED;
1444
Shannon Nelson7b086392013-11-20 10:02:59 +00001445 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001446 eth_test->flags |= ETH_TEST_FL_FAILED;
1447
Shannon Nelsonf551b432013-11-26 10:49:12 +00001448 /* run reg test last, a reset is required after it */
1449 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1450 eth_test->flags |= ETH_TEST_FL_FAILED;
1451
1452 clear_bit(__I40E_TESTING, &pf->state);
1453 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001454 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001455 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001456 netif_info(pf, drv, netdev, "online testing starting\n");
1457
Shannon Nelson7b086392013-11-20 10:02:59 +00001458 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001459 eth_test->flags |= ETH_TEST_FL_FAILED;
1460
1461 /* Offline only tests, not run in online; pass by default */
1462 data[I40E_ETH_TEST_REG] = 0;
1463 data[I40E_ETH_TEST_EEPROM] = 0;
1464 data[I40E_ETH_TEST_INTR] = 0;
1465 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001466 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001467
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001468 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001469}
1470
1471static void i40e_get_wol(struct net_device *netdev,
1472 struct ethtool_wolinfo *wol)
1473{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001474 struct i40e_netdev_priv *np = netdev_priv(netdev);
1475 struct i40e_pf *pf = np->vsi->back;
1476 struct i40e_hw *hw = &pf->hw;
1477 u16 wol_nvm_bits;
1478
1479 /* NVM bit on means WoL disabled for the port */
1480 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1481 if ((1 << hw->port) & wol_nvm_bits) {
1482 wol->supported = 0;
1483 wol->wolopts = 0;
1484 } else {
1485 wol->supported = WAKE_MAGIC;
1486 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1487 }
1488}
1489
1490static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1491{
1492 struct i40e_netdev_priv *np = netdev_priv(netdev);
1493 struct i40e_pf *pf = np->vsi->back;
1494 struct i40e_hw *hw = &pf->hw;
1495 u16 wol_nvm_bits;
1496
1497 /* NVM bit on means WoL disabled for the port */
1498 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1499 if (((1 << hw->port) & wol_nvm_bits))
1500 return -EOPNOTSUPP;
1501
1502 /* only magic packet is supported */
1503 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1504 return -EOPNOTSUPP;
1505
1506 /* is this a new value? */
1507 if (pf->wol_en != !!wol->wolopts) {
1508 pf->wol_en = !!wol->wolopts;
1509 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1510 }
1511
1512 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001513}
1514
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001515static int i40e_set_phys_id(struct net_device *netdev,
1516 enum ethtool_phys_id_state state)
1517{
1518 struct i40e_netdev_priv *np = netdev_priv(netdev);
1519 struct i40e_pf *pf = np->vsi->back;
1520 struct i40e_hw *hw = &pf->hw;
1521 int blink_freq = 2;
1522
1523 switch (state) {
1524 case ETHTOOL_ID_ACTIVE:
1525 pf->led_status = i40e_led_get(hw);
1526 return blink_freq;
1527 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001528 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001529 break;
1530 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001531 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001532 break;
1533 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001534 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001535 break;
1536 }
1537
1538 return 0;
1539}
1540
1541/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1542 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1543 * 125us (8000 interrupts per second) == ITR(62)
1544 */
1545
1546static int i40e_get_coalesce(struct net_device *netdev,
1547 struct ethtool_coalesce *ec)
1548{
1549 struct i40e_netdev_priv *np = netdev_priv(netdev);
1550 struct i40e_vsi *vsi = np->vsi;
1551
1552 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1553 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1554
1555 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001556 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001557
1558 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001559 ec->use_adaptive_tx_coalesce = 1;
1560
1561 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1562 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001563
1564 return 0;
1565}
1566
1567static int i40e_set_coalesce(struct net_device *netdev,
1568 struct ethtool_coalesce *ec)
1569{
1570 struct i40e_netdev_priv *np = netdev_priv(netdev);
1571 struct i40e_q_vector *q_vector;
1572 struct i40e_vsi *vsi = np->vsi;
1573 struct i40e_pf *pf = vsi->back;
1574 struct i40e_hw *hw = &pf->hw;
1575 u16 vector;
1576 int i;
1577
1578 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1579 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1580
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001581 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001582 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001583 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001584 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001585 } else if (ec->rx_coalesce_usecs == 0) {
1586 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001587 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001588 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 +00001589 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001590 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001591 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001592 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001593
Mitch Williams32f5f542014-04-04 04:43:10 +00001594 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001595 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001596 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001597 } else if (ec->tx_coalesce_usecs == 0) {
1598 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001599 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001600 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 +00001601 } else {
1602 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001603 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001604 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001605 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001606
1607 if (ec->use_adaptive_rx_coalesce)
1608 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1609 else
1610 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1611
1612 if (ec->use_adaptive_tx_coalesce)
1613 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1614 else
1615 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001616
Alexander Duyck493fb302013-09-28 07:01:44 +00001617 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1618 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001619 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1620 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1621 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1622 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1623 i40e_flush(hw);
1624 }
1625
1626 return 0;
1627}
1628
1629/**
1630 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1631 * @pf: pointer to the physical function struct
1632 * @cmd: ethtool rxnfc command
1633 *
1634 * Returns Success if the flow is supported, else Invalid Input.
1635 **/
1636static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1637{
1638 cmd->data = 0;
1639
1640 /* Report default options for RSS on i40e */
1641 switch (cmd->flow_type) {
1642 case TCP_V4_FLOW:
1643 case UDP_V4_FLOW:
1644 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1645 /* fall through to add IP fields */
1646 case SCTP_V4_FLOW:
1647 case AH_ESP_V4_FLOW:
1648 case AH_V4_FLOW:
1649 case ESP_V4_FLOW:
1650 case IPV4_FLOW:
1651 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1652 break;
1653 case TCP_V6_FLOW:
1654 case UDP_V6_FLOW:
1655 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1656 /* fall through to add IP fields */
1657 case SCTP_V6_FLOW:
1658 case AH_ESP_V6_FLOW:
1659 case AH_V6_FLOW:
1660 case ESP_V6_FLOW:
1661 case IPV6_FLOW:
1662 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1663 break;
1664 default:
1665 return -EINVAL;
1666 }
1667
1668 return 0;
1669}
1670
1671/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001672 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1673 * @pf: Pointer to the physical function struct
1674 * @cmd: The command to get or set Rx flow classification rules
1675 * @rule_locs: Array of used rule locations
1676 *
1677 * This function populates both the total and actual rule count of
1678 * the ethtool flow classification command
1679 *
1680 * Returns 0 on success or -EMSGSIZE if entry not found
1681 **/
1682static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1683 struct ethtool_rxnfc *cmd,
1684 u32 *rule_locs)
1685{
1686 struct i40e_fdir_filter *rule;
1687 struct hlist_node *node2;
1688 int cnt = 0;
1689
1690 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001691 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001692
1693 hlist_for_each_entry_safe(rule, node2,
1694 &pf->fdir_filter_list, fdir_node) {
1695 if (cnt == cmd->rule_cnt)
1696 return -EMSGSIZE;
1697
1698 rule_locs[cnt] = rule->fd_id;
1699 cnt++;
1700 }
1701
1702 cmd->rule_cnt = cnt;
1703
1704 return 0;
1705}
1706
1707/**
1708 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1709 * @pf: Pointer to the physical function struct
1710 * @cmd: The command to get or set Rx flow classification rules
1711 *
1712 * This function looks up a filter based on the Rx flow classification
1713 * command and fills the flow spec info for it if found
1714 *
1715 * Returns 0 on success or -EINVAL if filter not found
1716 **/
1717static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1718 struct ethtool_rxnfc *cmd)
1719{
1720 struct ethtool_rx_flow_spec *fsp =
1721 (struct ethtool_rx_flow_spec *)&cmd->fs;
1722 struct i40e_fdir_filter *rule = NULL;
1723 struct hlist_node *node2;
1724
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001725 hlist_for_each_entry_safe(rule, node2,
1726 &pf->fdir_filter_list, fdir_node) {
1727 if (fsp->location <= rule->fd_id)
1728 break;
1729 }
1730
1731 if (!rule || fsp->location != rule->fd_id)
1732 return -EINVAL;
1733
1734 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001735 if (fsp->flow_type == IP_USER_FLOW) {
1736 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1737 fsp->h_u.usr_ip4_spec.proto = 0;
1738 fsp->m_u.usr_ip4_spec.proto = 0;
1739 }
1740
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001741 /* Reverse the src and dest notion, since the HW views them from
1742 * Tx perspective where as the user expects it from Rx filter view.
1743 */
1744 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1745 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1746 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1747 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001748
1749 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1750 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1751 else
1752 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001753
1754 return 0;
1755}
1756
1757/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001758 * i40e_get_rxnfc - command to get RX flow classification rules
1759 * @netdev: network interface device structure
1760 * @cmd: ethtool rxnfc command
1761 *
1762 * Returns Success if the command is supported.
1763 **/
1764static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1765 u32 *rule_locs)
1766{
1767 struct i40e_netdev_priv *np = netdev_priv(netdev);
1768 struct i40e_vsi *vsi = np->vsi;
1769 struct i40e_pf *pf = vsi->back;
1770 int ret = -EOPNOTSUPP;
1771
1772 switch (cmd->cmd) {
1773 case ETHTOOL_GRXRINGS:
1774 cmd->data = vsi->alloc_queue_pairs;
1775 ret = 0;
1776 break;
1777 case ETHTOOL_GRXFH:
1778 ret = i40e_get_rss_hash_opts(pf, cmd);
1779 break;
1780 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001781 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001782 /* report total rule count */
1783 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001784 ret = 0;
1785 break;
1786 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001787 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001788 break;
1789 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001790 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1791 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001792 default:
1793 break;
1794 }
1795
1796 return ret;
1797}
1798
1799/**
1800 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1801 * @pf: pointer to the physical function struct
1802 * @cmd: ethtool rxnfc command
1803 *
1804 * Returns Success if the flow input set is supported.
1805 **/
1806static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1807{
1808 struct i40e_hw *hw = &pf->hw;
1809 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1810 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1811
1812 /* RSS does not support anything other than hashing
1813 * to queues on src and dst IPs and ports
1814 */
1815 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1816 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1817 return -EINVAL;
1818
1819 /* We need at least the IP SRC and DEST fields for hashing */
1820 if (!(nfc->data & RXH_IP_SRC) ||
1821 !(nfc->data & RXH_IP_DST))
1822 return -EINVAL;
1823
1824 switch (nfc->flow_type) {
1825 case TCP_V4_FLOW:
1826 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1827 case 0:
1828 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1829 break;
1830 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1831 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1832 break;
1833 default:
1834 return -EINVAL;
1835 }
1836 break;
1837 case TCP_V6_FLOW:
1838 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1839 case 0:
1840 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1841 break;
1842 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1843 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1844 break;
1845 default:
1846 return -EINVAL;
1847 }
1848 break;
1849 case UDP_V4_FLOW:
1850 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1851 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001852 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1853 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001854 break;
1855 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001856 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1857 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001858 break;
1859 default:
1860 return -EINVAL;
1861 }
1862 break;
1863 case UDP_V6_FLOW:
1864 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1865 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001866 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1867 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001868 break;
1869 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001870 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1871 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001872 break;
1873 default:
1874 return -EINVAL;
1875 }
1876 break;
1877 case AH_ESP_V4_FLOW:
1878 case AH_V4_FLOW:
1879 case ESP_V4_FLOW:
1880 case SCTP_V4_FLOW:
1881 if ((nfc->data & RXH_L4_B_0_1) ||
1882 (nfc->data & RXH_L4_B_2_3))
1883 return -EINVAL;
1884 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1885 break;
1886 case AH_ESP_V6_FLOW:
1887 case AH_V6_FLOW:
1888 case ESP_V6_FLOW:
1889 case SCTP_V6_FLOW:
1890 if ((nfc->data & RXH_L4_B_0_1) ||
1891 (nfc->data & RXH_L4_B_2_3))
1892 return -EINVAL;
1893 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1894 break;
1895 case IPV4_FLOW:
1896 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1897 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1898 break;
1899 case IPV6_FLOW:
1900 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1901 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1902 break;
1903 default:
1904 return -EINVAL;
1905 }
1906
1907 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1908 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1909 i40e_flush(hw);
1910
1911 return 0;
1912}
1913
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001914/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001915 * i40e_match_fdir_input_set - Match a new filter against an existing one
1916 * @rule: The filter already added
1917 * @input: The new filter to comapre against
1918 *
1919 * Returns true if the two input set match
1920 **/
1921static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1922 struct i40e_fdir_filter *input)
1923{
1924 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1925 (rule->src_ip[0] != input->src_ip[0]) ||
1926 (rule->dst_port != input->dst_port) ||
1927 (rule->src_port != input->src_port))
1928 return false;
1929 return true;
1930}
1931
1932/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001933 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1934 * @vsi: Pointer to the targeted VSI
1935 * @input: The filter to update or NULL to indicate deletion
1936 * @sw_idx: Software index to the filter
1937 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001938 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001939 * This function updates (or deletes) a Flow Director entry from
1940 * the hlist of the corresponding PF
1941 *
1942 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001943 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001944static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1945 struct i40e_fdir_filter *input,
1946 u16 sw_idx,
1947 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001948{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001949 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001950 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001951 struct hlist_node *node2;
1952 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001953
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001954 parent = NULL;
1955 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001956
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001957 hlist_for_each_entry_safe(rule, node2,
1958 &pf->fdir_filter_list, fdir_node) {
1959 /* hash found, or no matching entry */
1960 if (rule->fd_id >= sw_idx)
1961 break;
1962 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001963 }
1964
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001965 /* if there is an old rule occupying our place remove it */
1966 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001967 if (input && !i40e_match_fdir_input_set(rule, input))
1968 err = i40e_add_del_fdir(vsi, rule, false);
1969 else if (!input)
1970 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001971 hlist_del(&rule->fdir_node);
1972 kfree(rule);
1973 pf->fdir_pf_active_filters--;
1974 }
1975
1976 /* If no input this was a delete, err should be 0 if a rule was
1977 * successfully found and removed from the list else -EINVAL
1978 */
1979 if (!input)
1980 return err;
1981
1982 /* initialize node and set software index */
1983 INIT_HLIST_NODE(&input->fdir_node);
1984
1985 /* add filter to the list */
1986 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07001987 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001988 else
1989 hlist_add_head(&input->fdir_node,
1990 &pf->fdir_filter_list);
1991
1992 /* update counts */
1993 pf->fdir_pf_active_filters++;
1994
1995 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001996}
1997
1998/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001999 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2000 * @vsi: Pointer to the targeted VSI
2001 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002002 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002003 * The function removes a Flow Director filter entry from the
2004 * hlist of the corresponding PF
2005 *
2006 * Returns 0 on success
2007 */
2008static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2009 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002010{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002011 struct ethtool_rx_flow_spec *fsp =
2012 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002013 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002014 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002015
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002016 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2017 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2018 return -EBUSY;
2019
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002020 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2021 return -EBUSY;
2022
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002023 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002024
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002025 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002026 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002027}
2028
2029/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002030 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002031 * @vsi: pointer to the targeted VSI
2032 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002033 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002034 * Add Flow Director filters for a specific flow spec based on their
2035 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002036 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002037static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2038 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002039{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002040 struct ethtool_rx_flow_spec *fsp;
2041 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002042 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002043 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002044
2045 if (!vsi)
2046 return -EINVAL;
2047
2048 pf = vsi->back;
2049
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002050 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2051 return -EOPNOTSUPP;
2052
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002053 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002054 return -ENOSPC;
2055
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002056 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2057 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2058 return -EBUSY;
2059
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002060 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2061 return -EBUSY;
2062
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002063 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2064
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002065 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2066 pf->hw.func_caps.fd_filters_guaranteed)) {
2067 return -EINVAL;
2068 }
2069
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002070 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2071 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002072 return -EINVAL;
2073
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002074 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002075
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002076 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002077 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002078
2079 input->fd_id = fsp->location;
2080
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002081 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2082 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2083 else
2084 input->dest_ctl =
2085 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2086
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002087 input->q_index = fsp->ring_cookie;
2088 input->flex_off = 0;
2089 input->pctype = 0;
2090 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002091 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00002092 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002093 input->flow_type = fsp->flow_type;
2094 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002095
2096 /* Reverse the src and dest notion, since the HW expects them to be from
2097 * Tx perspective where as the input from user is from Rx filter view.
2098 */
2099 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2100 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2101 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2102 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002103
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002104 ret = i40e_add_del_fdir(vsi, input, true);
2105 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002106 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002107 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002108 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002109
2110 return ret;
2111}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002112
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002113/**
2114 * i40e_set_rxnfc - command to set RX flow classification rules
2115 * @netdev: network interface device structure
2116 * @cmd: ethtool rxnfc command
2117 *
2118 * Returns Success if the command is supported.
2119 **/
2120static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2121{
2122 struct i40e_netdev_priv *np = netdev_priv(netdev);
2123 struct i40e_vsi *vsi = np->vsi;
2124 struct i40e_pf *pf = vsi->back;
2125 int ret = -EOPNOTSUPP;
2126
2127 switch (cmd->cmd) {
2128 case ETHTOOL_SRXFH:
2129 ret = i40e_set_rss_hash_opt(pf, cmd);
2130 break;
2131 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002132 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002133 break;
2134 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002135 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002136 break;
2137 default:
2138 break;
2139 }
2140
2141 return ret;
2142}
2143
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002144/**
2145 * i40e_max_channels - get Max number of combined channels supported
2146 * @vsi: vsi pointer
2147 **/
2148static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2149{
2150 /* TODO: This code assumes DCB and FD is disabled for now. */
2151 return vsi->alloc_queue_pairs;
2152}
2153
2154/**
2155 * i40e_get_channels - Get the current channels enabled and max supported etc.
2156 * @netdev: network interface device structure
2157 * @ch: ethtool channels structure
2158 *
2159 * We don't support separate tx and rx queues as channels. The other count
2160 * represents how many queues are being used for control. max_combined counts
2161 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2162 * q_vectors since we support a lot more queue pairs than q_vectors.
2163 **/
2164static void i40e_get_channels(struct net_device *dev,
2165 struct ethtool_channels *ch)
2166{
2167 struct i40e_netdev_priv *np = netdev_priv(dev);
2168 struct i40e_vsi *vsi = np->vsi;
2169 struct i40e_pf *pf = vsi->back;
2170
2171 /* report maximum channels */
2172 ch->max_combined = i40e_max_channels(vsi);
2173
2174 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002175 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002176 ch->max_other = ch->other_count;
2177
2178 /* Note: This code assumes DCB is disabled for now. */
2179 ch->combined_count = vsi->num_queue_pairs;
2180}
2181
2182/**
2183 * i40e_set_channels - Set the new channels count.
2184 * @netdev: network interface device structure
2185 * @ch: ethtool channels structure
2186 *
2187 * The new channels count may not be the same as requested by the user
2188 * since it gets rounded down to a power of 2 value.
2189 **/
2190static int i40e_set_channels(struct net_device *dev,
2191 struct ethtool_channels *ch)
2192{
2193 struct i40e_netdev_priv *np = netdev_priv(dev);
2194 unsigned int count = ch->combined_count;
2195 struct i40e_vsi *vsi = np->vsi;
2196 struct i40e_pf *pf = vsi->back;
2197 int new_count;
2198
2199 /* We do not support setting channels for any other VSI at present */
2200 if (vsi->type != I40E_VSI_MAIN)
2201 return -EINVAL;
2202
2203 /* verify they are not requesting separate vectors */
2204 if (!count || ch->rx_count || ch->tx_count)
2205 return -EINVAL;
2206
2207 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002208 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002209 return -EINVAL;
2210
2211 /* verify the number of channels does not exceed hardware limits */
2212 if (count > i40e_max_channels(vsi))
2213 return -EINVAL;
2214
2215 /* update feature limits from largest to smallest supported values */
2216 /* TODO: Flow director limit, DCB etc */
2217
2218 /* cap RSS limit */
2219 if (count > pf->rss_size_max)
2220 count = pf->rss_size_max;
2221
2222 /* use rss_reconfig to rebuild with new queue count and update traffic
2223 * class queue mapping
2224 */
2225 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002226 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002227 return 0;
2228 else
2229 return -EINVAL;
2230}
2231
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002232static const struct ethtool_ops i40e_ethtool_ops = {
2233 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002234 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002235 .get_drvinfo = i40e_get_drvinfo,
2236 .get_regs_len = i40e_get_regs_len,
2237 .get_regs = i40e_get_regs,
2238 .nway_reset = i40e_nway_reset,
2239 .get_link = ethtool_op_get_link,
2240 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002241 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002242 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002243 .get_eeprom_len = i40e_get_eeprom_len,
2244 .get_eeprom = i40e_get_eeprom,
2245 .get_ringparam = i40e_get_ringparam,
2246 .set_ringparam = i40e_set_ringparam,
2247 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002248 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002249 .get_msglevel = i40e_get_msglevel,
2250 .set_msglevel = i40e_set_msglevel,
2251 .get_rxnfc = i40e_get_rxnfc,
2252 .set_rxnfc = i40e_set_rxnfc,
2253 .self_test = i40e_diag_test,
2254 .get_strings = i40e_get_strings,
2255 .set_phys_id = i40e_set_phys_id,
2256 .get_sset_count = i40e_get_sset_count,
2257 .get_ethtool_stats = i40e_get_ethtool_stats,
2258 .get_coalesce = i40e_get_coalesce,
2259 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002260 .get_channels = i40e_get_channels,
2261 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002262 .get_ts_info = i40e_get_ts_info,
2263};
2264
2265void i40e_set_ethtool_ops(struct net_device *netdev)
2266{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002267 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002268}