blob: de4ce0e022a4c602b3f39d5c290484e9cbe42bf9 [file] [log] [blame]
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Greg Rosedc641b72013-12-18 13:45:51 +00004 * Copyright(c) 2013 - 2014 Intel Corporation.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27/* ethtool support for i40e */
28
29#include "i40e.h"
30#include "i40e_diag.h"
31
32struct i40e_stats {
33 char stat_string[ETH_GSTRING_LEN];
34 int sizeof_stat;
35 int stat_offset;
36};
37
38#define I40E_STAT(_type, _name, _stat) { \
39 .stat_string = _name, \
40 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
41 .stat_offset = offsetof(_type, _stat) \
42}
43#define I40E_NETDEV_STAT(_net_stat) \
44 I40E_STAT(struct net_device_stats, #_net_stat, _net_stat)
45#define I40E_PF_STAT(_name, _stat) \
46 I40E_STAT(struct i40e_pf, _name, _stat)
47#define I40E_VSI_STAT(_name, _stat) \
48 I40E_STAT(struct i40e_vsi, _name, _stat)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000049#define I40E_VEB_STAT(_name, _stat) \
50 I40E_STAT(struct i40e_veb, _name, _stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000051
52static const struct i40e_stats i40e_gstrings_net_stats[] = {
53 I40E_NETDEV_STAT(rx_packets),
54 I40E_NETDEV_STAT(tx_packets),
55 I40E_NETDEV_STAT(rx_bytes),
56 I40E_NETDEV_STAT(tx_bytes),
57 I40E_NETDEV_STAT(rx_errors),
58 I40E_NETDEV_STAT(tx_errors),
59 I40E_NETDEV_STAT(rx_dropped),
60 I40E_NETDEV_STAT(tx_dropped),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000061 I40E_NETDEV_STAT(collisions),
62 I40E_NETDEV_STAT(rx_length_errors),
63 I40E_NETDEV_STAT(rx_crc_errors),
64};
65
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000066static const struct i40e_stats i40e_gstrings_veb_stats[] = {
67 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
68 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
69 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
70 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
71 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
72 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
73 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
74 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
75 I40E_VEB_STAT("rx_discards", stats.rx_discards),
76 I40E_VEB_STAT("tx_discards", stats.tx_discards),
77 I40E_VEB_STAT("tx_errors", stats.tx_errors),
78 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
79};
80
Shannon Nelson41a9e552014-04-23 04:50:20 +000081static const struct i40e_stats i40e_gstrings_misc_stats[] = {
Shannon Nelson418631d2014-04-23 04:50:07 +000082 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
83 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
84 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
85 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
Shannon Nelson41a9e552014-04-23 04:50:20 +000086 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
87 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
Shannon Nelson418631d2014-04-23 04:50:07 +000088 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
Shannon Nelson41a9e552014-04-23 04:50:20 +000089};
90
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +000091static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
92 struct ethtool_rxnfc *cmd);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +000093
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000094/* These PF_STATs might look like duplicates of some NETDEV_STATs,
95 * but they are separate. This device supports Virtualization, and
96 * as such might have several netdevs supporting VMDq and FCoE going
97 * through a single port. The NETDEV_STATs are for individual netdevs
98 * seen at the top of the stack, and the PF_STATs are for the physical
99 * function at the bottom of the stack hosting those netdevs.
100 *
101 * The PF_STATs are appended to the netdev stats only when ethtool -S
102 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
103 */
104static struct i40e_stats i40e_gstrings_stats[] = {
105 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
106 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000107 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
108 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
109 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
110 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
111 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
112 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000113 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
114 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
115 I40E_PF_STAT("tx_dropped", stats.eth.tx_discards),
116 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
117 I40E_PF_STAT("crc_errors", stats.crc_errors),
118 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
119 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
120 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000121 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000122 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000123 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
124 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
125 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
126 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
127 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
128 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
129 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
130 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
131 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
132 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
133 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
134 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
135 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
136 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
137 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
138 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
139 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
140 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
141 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
142 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
143 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
144 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
145 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
146 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000147 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000148 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000149 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
150 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
151
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000152 /* LPI stats */
153 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
154 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
155 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
156 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000157};
158
Vasu Dev38e00432014-08-01 13:27:03 -0700159#ifdef I40E_FCOE
160static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
161 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
162 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
163 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
164 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
165 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
166 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
167 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
168 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
169};
170
171#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000172#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000173 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
174 * 2 /* Tx and Rx together */ \
175 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000176#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
177#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000178#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700179#ifdef I40E_FCOE
180#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
181#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
182 I40E_FCOE_STATS_LEN + \
183 I40E_MISC_STATS_LEN + \
184 I40E_QUEUE_STATS_LEN((n)))
185#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000186#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000187 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000188 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700189#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000190#define I40E_PFC_STATS_LEN ( \
191 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
192 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
193 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
194 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
196 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000197#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000198#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
199 I40E_PFC_STATS_LEN + \
200 I40E_VSI_STATS_LEN((n)))
201
202enum i40e_ethtool_test_id {
203 I40E_ETH_TEST_REG = 0,
204 I40E_ETH_TEST_EEPROM,
205 I40E_ETH_TEST_INTR,
206 I40E_ETH_TEST_LOOPBACK,
207 I40E_ETH_TEST_LINK,
208};
209
210static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
211 "Register test (offline)",
212 "Eeprom test (offline)",
213 "Interrupt test (offline)",
214 "Loopback test (offline)",
215 "Link test (on/offline)"
216};
217
218#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
219
220/**
221 * i40e_get_settings - Get Link Speed and Duplex settings
222 * @netdev: network interface device structure
223 * @ecmd: ethtool command
224 *
225 * Reports speed/duplex settings based on media_type
226 **/
227static int i40e_get_settings(struct net_device *netdev,
228 struct ethtool_cmd *ecmd)
229{
230 struct i40e_netdev_priv *np = netdev_priv(netdev);
231 struct i40e_pf *pf = np->vsi->back;
232 struct i40e_hw *hw = &pf->hw;
233 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
234 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
235 u32 link_speed = hw_link_info->link_speed;
236
237 /* hardware is either in 40G mode or 10G mode
238 * NOTE: this section initializes supported and advertising
239 */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000240 if (!link_up) {
241 /* link is down and the driver needs to fall back on
242 * device ID to determine what kinds of info to display,
243 * it's mostly a guess that may change when link is up
244 */
245 switch (hw->device_id) {
246 case I40E_DEV_ID_QSFP_A:
247 case I40E_DEV_ID_QSFP_B:
248 case I40E_DEV_ID_QSFP_C:
249 /* pluggable QSFP */
250 ecmd->supported = SUPPORTED_40000baseSR4_Full |
251 SUPPORTED_40000baseCR4_Full |
252 SUPPORTED_40000baseLR4_Full;
253 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
254 ADVERTISED_40000baseCR4_Full |
255 ADVERTISED_40000baseLR4_Full;
256 break;
257 case I40E_DEV_ID_KX_B:
258 /* backplane 40G */
259 ecmd->supported = SUPPORTED_40000baseKR4_Full;
260 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
261 break;
262 case I40E_DEV_ID_KX_C:
263 /* backplane 10G */
264 ecmd->supported = SUPPORTED_10000baseKR_Full;
265 ecmd->advertising = ADVERTISED_10000baseKR_Full;
266 break;
267 default:
268 /* all the rest are 10G/1G */
269 ecmd->supported = SUPPORTED_10000baseT_Full |
270 SUPPORTED_1000baseT_Full;
271 ecmd->advertising = ADVERTISED_10000baseT_Full |
272 ADVERTISED_1000baseT_Full;
273 break;
274 }
275
276 /* skip phy_type use as it is zero when link is down */
277 goto no_valid_phy_type;
278 }
279
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000280 switch (hw_link_info->phy_type) {
281 case I40E_PHY_TYPE_40GBASE_CR4:
282 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000283 ecmd->supported = SUPPORTED_Autoneg |
284 SUPPORTED_40000baseCR4_Full;
285 ecmd->advertising = ADVERTISED_Autoneg |
286 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000287 break;
288 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000289 ecmd->supported = SUPPORTED_Autoneg |
290 SUPPORTED_40000baseKR4_Full;
291 ecmd->advertising = ADVERTISED_Autoneg |
292 ADVERTISED_40000baseKR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000293 break;
294 case I40E_PHY_TYPE_40GBASE_SR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000295 case I40E_PHY_TYPE_XLPPI:
296 case I40E_PHY_TYPE_XLAUI:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000297 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000298 break;
299 case I40E_PHY_TYPE_40GBASE_LR4:
300 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000301 break;
302 case I40E_PHY_TYPE_10GBASE_KX4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000303 ecmd->supported = SUPPORTED_Autoneg |
304 SUPPORTED_10000baseKX4_Full;
305 ecmd->advertising = ADVERTISED_Autoneg |
306 ADVERTISED_10000baseKX4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000307 break;
308 case I40E_PHY_TYPE_10GBASE_KR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000309 ecmd->supported = SUPPORTED_Autoneg |
310 SUPPORTED_10000baseKR_Full;
311 ecmd->advertising = ADVERTISED_Autoneg |
312 ADVERTISED_10000baseKR_Full;
313 break;
314 case I40E_PHY_TYPE_10GBASE_SR:
315 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000316 case I40E_PHY_TYPE_1000BASE_SX:
317 case I40E_PHY_TYPE_1000BASE_LX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000318 ecmd->supported = SUPPORTED_10000baseT_Full;
Catherine Sullivan124ed152014-07-12 07:28:12 +0000319 ecmd->supported |= SUPPORTED_1000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000320 break;
321 case I40E_PHY_TYPE_10GBASE_CR1_CU:
322 case I40E_PHY_TYPE_10GBASE_CR1:
323 case I40E_PHY_TYPE_10GBASE_T:
324 ecmd->supported = SUPPORTED_Autoneg |
325 SUPPORTED_10000baseT_Full;
326 ecmd->advertising = ADVERTISED_Autoneg |
327 ADVERTISED_10000baseT_Full;
328 break;
329 case I40E_PHY_TYPE_XAUI:
330 case I40E_PHY_TYPE_XFI:
331 case I40E_PHY_TYPE_SFI:
332 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
333 ecmd->supported = SUPPORTED_10000baseT_Full;
334 break;
335 case I40E_PHY_TYPE_1000BASE_KX:
336 case I40E_PHY_TYPE_1000BASE_T:
337 ecmd->supported = SUPPORTED_Autoneg |
338 SUPPORTED_1000baseT_Full;
339 ecmd->advertising = ADVERTISED_Autoneg |
340 ADVERTISED_1000baseT_Full;
341 break;
342 case I40E_PHY_TYPE_100BASE_TX:
343 ecmd->supported = SUPPORTED_Autoneg |
344 SUPPORTED_100baseT_Full;
345 ecmd->advertising = ADVERTISED_Autoneg |
346 ADVERTISED_100baseT_Full;
347 break;
348 case I40E_PHY_TYPE_SGMII:
349 ecmd->supported = SUPPORTED_Autoneg |
350 SUPPORTED_1000baseT_Full |
351 SUPPORTED_100baseT_Full;
352 ecmd->advertising = ADVERTISED_Autoneg |
353 ADVERTISED_1000baseT_Full |
354 ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000355 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000356 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000357 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000358 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
359 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000360 }
361
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000362no_valid_phy_type:
363 /* this is if autoneg is enabled or disabled */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000364 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
365 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000366
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000367 switch (hw->phy.media_type) {
368 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000369 ecmd->supported |= SUPPORTED_Autoneg |
370 SUPPORTED_Backplane;
371 ecmd->advertising |= ADVERTISED_Autoneg |
372 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000373 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000374 break;
375 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000376 ecmd->supported |= SUPPORTED_TP;
377 ecmd->advertising |= ADVERTISED_TP;
378 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000379 break;
380 case I40E_MEDIA_TYPE_DA:
381 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000382 ecmd->supported |= SUPPORTED_FIBRE;
383 ecmd->advertising |= ADVERTISED_FIBRE;
384 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000385 break;
386 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000387 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000388 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000389 break;
390 case I40E_MEDIA_TYPE_UNKNOWN:
391 default:
392 ecmd->port = PORT_OTHER;
393 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000394 }
395
396 ecmd->transceiver = XCVR_EXTERNAL;
397
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000398 ecmd->supported |= SUPPORTED_Pause;
399
400 switch (hw->fc.current_mode) {
401 case I40E_FC_FULL:
402 ecmd->advertising |= ADVERTISED_Pause;
403 break;
404 case I40E_FC_TX_PAUSE:
405 ecmd->advertising |= ADVERTISED_Asym_Pause;
406 break;
407 case I40E_FC_RX_PAUSE:
408 ecmd->advertising |= (ADVERTISED_Pause |
409 ADVERTISED_Asym_Pause);
410 break;
411 default:
412 ecmd->advertising &= ~(ADVERTISED_Pause |
413 ADVERTISED_Asym_Pause);
414 break;
415 }
416
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000417 if (link_up) {
418 switch (link_speed) {
419 case I40E_LINK_SPEED_40GB:
420 /* need a SPEED_40000 in ethtool.h */
421 ethtool_cmd_speed_set(ecmd, 40000);
422 break;
423 case I40E_LINK_SPEED_10GB:
424 ethtool_cmd_speed_set(ecmd, SPEED_10000);
425 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000426 case I40E_LINK_SPEED_1GB:
427 ethtool_cmd_speed_set(ecmd, SPEED_1000);
428 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000429 default:
430 break;
431 }
432 ecmd->duplex = DUPLEX_FULL;
433 } else {
434 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
435 ecmd->duplex = DUPLEX_UNKNOWN;
436 }
437
438 return 0;
439}
440
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000441/**
442 * i40e_set_settings - Set Speed and Duplex
443 * @netdev: network interface device structure
444 * @ecmd: ethtool command
445 *
446 * Set speed/duplex per media_types advertised/forced
447 **/
448static int i40e_set_settings(struct net_device *netdev,
449 struct ethtool_cmd *ecmd)
450{
451 struct i40e_netdev_priv *np = netdev_priv(netdev);
452 struct i40e_aq_get_phy_abilities_resp abilities;
453 struct i40e_aq_set_phy_config config;
454 struct i40e_pf *pf = np->vsi->back;
455 struct i40e_vsi *vsi = np->vsi;
456 struct i40e_hw *hw = &pf->hw;
457 struct ethtool_cmd safe_ecmd;
458 i40e_status status = 0;
459 bool change = false;
460 int err = 0;
461 u8 autoneg;
462 u32 advertise;
463
464 if (vsi != pf->vsi[pf->lan_vsi])
465 return -EOPNOTSUPP;
466
467 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
468 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000469 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
470 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000471 return -EOPNOTSUPP;
472
473 /* get our own copy of the bits to check against */
474 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
475 i40e_get_settings(netdev, &safe_ecmd);
476
477 /* save autoneg and speed out of ecmd */
478 autoneg = ecmd->autoneg;
479 advertise = ecmd->advertising;
480
481 /* set autoneg and speed back to what they currently are */
482 ecmd->autoneg = safe_ecmd.autoneg;
483 ecmd->advertising = safe_ecmd.advertising;
484
485 ecmd->cmd = safe_ecmd.cmd;
486 /* If ecmd and safe_ecmd are not the same now, then they are
487 * trying to set something that we do not support
488 */
489 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
490 return -EOPNOTSUPP;
491
492 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
493 usleep_range(1000, 2000);
494
495 /* Get the current phy config */
496 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
497 NULL);
498 if (status)
499 return -EAGAIN;
500
Catherine Sullivan124ed152014-07-12 07:28:12 +0000501 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000502 * set below
503 */
504 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000505 config.abilities = abilities.abilities;
506
507 /* Check autoneg */
508 if (autoneg == AUTONEG_ENABLE) {
509 /* If autoneg is not supported, return error */
510 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
511 netdev_info(netdev, "Autoneg not supported on this phy\n");
512 return -EINVAL;
513 }
514 /* If autoneg was not already enabled */
515 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
516 config.abilities = abilities.abilities |
517 I40E_AQ_PHY_ENABLE_AN;
518 change = true;
519 }
520 } else {
521 /* If autoneg is supported 10GBASE_T is the only phy that
522 * can disable it, so otherwise return error
523 */
524 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
525 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
526 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
527 return -EINVAL;
528 }
529 /* If autoneg is currently enabled */
530 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
531 config.abilities = abilities.abilities |
532 ~I40E_AQ_PHY_ENABLE_AN;
533 change = true;
534 }
535 }
536
537 if (advertise & ~safe_ecmd.supported)
538 return -EINVAL;
539
540 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000541 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000542 if (advertise & ADVERTISED_1000baseT_Full ||
543 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000544 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000545 if (advertise & ADVERTISED_10000baseT_Full ||
546 advertise & ADVERTISED_10000baseKX4_Full ||
547 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000548 config.link_speed |= I40E_LINK_SPEED_10GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000549 if (advertise & ADVERTISED_40000baseKR4_Full ||
550 advertise & ADVERTISED_40000baseCR4_Full ||
551 advertise & ADVERTISED_40000baseSR4_Full ||
552 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000553 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000554
Catherine Sullivan124ed152014-07-12 07:28:12 +0000555 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000556 /* copy over the rest of the abilities */
557 config.phy_type = abilities.phy_type;
558 config.eee_capability = abilities.eee_capability;
559 config.eeer = abilities.eeer_val;
560 config.low_power_ctrl = abilities.d3_lpan;
561
562 /* If link is up set link and an so changes take effect */
563 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
564 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
565
566 /* make the aq call */
567 status = i40e_aq_set_phy_config(hw, &config, NULL);
568 if (status) {
569 netdev_info(netdev, "Set phy config failed with error %d.\n",
570 status);
571 return -EAGAIN;
572 }
573
574 status = i40e_update_link_info(hw, true);
575 if (status)
576 netdev_info(netdev, "Updating link info failed with error %d\n",
577 status);
578
579 } else {
580 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
581 }
582
583 return err;
584}
585
Jesse Brandeburga6599722014-06-04 08:45:25 +0000586static int i40e_nway_reset(struct net_device *netdev)
587{
588 /* restart autonegotiation */
589 struct i40e_netdev_priv *np = netdev_priv(netdev);
590 struct i40e_pf *pf = np->vsi->back;
591 struct i40e_hw *hw = &pf->hw;
592 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
593 i40e_status ret = 0;
594
595 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
596 if (ret) {
597 netdev_info(netdev, "link restart failed, aq_err=%d\n",
598 pf->hw.aq.asq_last_status);
599 return -EIO;
600 }
601
602 return 0;
603}
604
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000605/**
606 * i40e_get_pauseparam - Get Flow Control status
607 * Return tx/rx-pause status
608 **/
609static void i40e_get_pauseparam(struct net_device *netdev,
610 struct ethtool_pauseparam *pause)
611{
612 struct i40e_netdev_priv *np = netdev_priv(netdev);
613 struct i40e_pf *pf = np->vsi->back;
614 struct i40e_hw *hw = &pf->hw;
615 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
616
617 pause->autoneg =
618 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
619 AUTONEG_ENABLE : AUTONEG_DISABLE);
620
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000621 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000622 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000623 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000624 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000625 } else if (hw->fc.current_mode == I40E_FC_FULL) {
626 pause->rx_pause = 1;
627 pause->tx_pause = 1;
628 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000629}
630
Catherine Sullivan2becc352014-06-04 08:45:27 +0000631/**
632 * i40e_set_pauseparam - Set Flow Control parameter
633 * @netdev: network interface device structure
634 * @pause: return tx/rx flow control status
635 **/
636static int i40e_set_pauseparam(struct net_device *netdev,
637 struct ethtool_pauseparam *pause)
638{
639 struct i40e_netdev_priv *np = netdev_priv(netdev);
640 struct i40e_pf *pf = np->vsi->back;
641 struct i40e_vsi *vsi = np->vsi;
642 struct i40e_hw *hw = &pf->hw;
643 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
644 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
645 i40e_status status;
646 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000647 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000648
649 if (vsi != pf->vsi[pf->lan_vsi])
650 return -EOPNOTSUPP;
651
652 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
653 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
654 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
655 return -EOPNOTSUPP;
656 }
657
658 /* If we have link and don't have autoneg */
659 if (!test_bit(__I40E_DOWN, &pf->state) &&
660 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
661 /* Send message that it might not necessarily work*/
662 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
663 }
664
665 if (hw->fc.current_mode == I40E_FC_PFC) {
666 netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
667 return -EOPNOTSUPP;
668 }
669
670 if (pause->rx_pause && pause->tx_pause)
671 hw->fc.requested_mode = I40E_FC_FULL;
672 else if (pause->rx_pause && !pause->tx_pause)
673 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
674 else if (!pause->rx_pause && pause->tx_pause)
675 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
676 else if (!pause->rx_pause && !pause->tx_pause)
677 hw->fc.requested_mode = I40E_FC_NONE;
678 else
679 return -EINVAL;
680
681 /* Set the fc mode and only restart an if link is up*/
682 status = i40e_set_fc(hw, &aq_failures, link_up);
683
684 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
685 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
686 status, hw->aq.asq_last_status);
687 err = -EAGAIN;
688 }
689 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
690 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
691 status, hw->aq.asq_last_status);
692 err = -EAGAIN;
693 }
694 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
695 netdev_info(netdev, "Set fc failed on the update_link_info call with error %d and status %d\n",
696 status, hw->aq.asq_last_status);
697 err = -EAGAIN;
698 }
699
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000700 if (!test_bit(__I40E_DOWN, &pf->state)) {
701 /* Give it a little more time to try to come back */
702 msleep(75);
703 if (!test_bit(__I40E_DOWN, &pf->state))
704 return i40e_nway_reset(netdev);
705 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000706
707 return err;
708}
709
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000710static u32 i40e_get_msglevel(struct net_device *netdev)
711{
712 struct i40e_netdev_priv *np = netdev_priv(netdev);
713 struct i40e_pf *pf = np->vsi->back;
714
715 return pf->msg_enable;
716}
717
718static void i40e_set_msglevel(struct net_device *netdev, u32 data)
719{
720 struct i40e_netdev_priv *np = netdev_priv(netdev);
721 struct i40e_pf *pf = np->vsi->back;
722
723 if (I40E_DEBUG_USER & data)
724 pf->hw.debug_mask = data;
725 pf->msg_enable = data;
726}
727
728static int i40e_get_regs_len(struct net_device *netdev)
729{
730 int reg_count = 0;
731 int i;
732
733 for (i = 0; i40e_reg_list[i].offset != 0; i++)
734 reg_count += i40e_reg_list[i].elements;
735
736 return reg_count * sizeof(u32);
737}
738
739static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
740 void *p)
741{
742 struct i40e_netdev_priv *np = netdev_priv(netdev);
743 struct i40e_pf *pf = np->vsi->back;
744 struct i40e_hw *hw = &pf->hw;
745 u32 *reg_buf = p;
746 int i, j, ri;
747 u32 reg;
748
749 /* Tell ethtool which driver-version-specific regs output we have.
750 *
751 * At some point, if we have ethtool doing special formatting of
752 * this data, it will rely on this version number to know how to
753 * interpret things. Hence, this needs to be updated if/when the
754 * diags register table is changed.
755 */
756 regs->version = 1;
757
758 /* loop through the diags reg table for what to print */
759 ri = 0;
760 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
761 for (j = 0; j < i40e_reg_list[i].elements; j++) {
762 reg = i40e_reg_list[i].offset
763 + (j * i40e_reg_list[i].stride);
764 reg_buf[ri++] = rd32(hw, reg);
765 }
766 }
767
768}
769
770static int i40e_get_eeprom(struct net_device *netdev,
771 struct ethtool_eeprom *eeprom, u8 *bytes)
772{
773 struct i40e_netdev_priv *np = netdev_priv(netdev);
774 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000775 struct i40e_pf *pf = np->vsi->back;
776 int ret_val = 0, len;
777 u8 *eeprom_buff;
778 u16 i, sectors;
779 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000780 u32 magic;
781
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000782#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000783 if (eeprom->len == 0)
784 return -EINVAL;
785
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000786 /* check for NVMUpdate access method */
787 magic = hw->vendor_id | (hw->device_id << 16);
788 if (eeprom->magic && eeprom->magic != magic) {
789 int errno;
790
791 /* make sure it is the right magic for NVMUpdate */
792 if ((eeprom->magic >> 16) != hw->device_id)
793 return -EINVAL;
794
795 ret_val = i40e_nvmupd_command(hw,
796 (struct i40e_nvm_access *)eeprom,
797 bytes, &errno);
798 if (ret_val)
799 dev_info(&pf->pdev->dev,
800 "NVMUpdate read failed err=%d status=0x%x\n",
801 ret_val, hw->aq.asq_last_status);
802
803 return errno;
804 }
805
806 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000807 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
808
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000809 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000810 if (!eeprom_buff)
811 return -ENOMEM;
812
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000813 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
814 if (ret_val) {
815 dev_info(&pf->pdev->dev,
816 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
817 ret_val, hw->aq.asq_last_status);
818 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000819 }
820
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000821 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
822 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
823 len = I40E_NVM_SECTOR_SIZE;
824 last = false;
825 for (i = 0; i < sectors; i++) {
826 if (i == (sectors - 1)) {
827 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
828 last = true;
829 }
830 ret_val = i40e_aq_read_nvm(hw, 0x0,
831 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
832 len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000833 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000834 last, NULL);
835 if (ret_val) {
836 dev_info(&pf->pdev->dev,
837 "read NVM failed err=%d status=0x%x\n",
838 ret_val, hw->aq.asq_last_status);
839 goto release_nvm;
840 }
841 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000842
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000843release_nvm:
844 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000845 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000846free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000847 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000848 return ret_val;
849}
850
851static int i40e_get_eeprom_len(struct net_device *netdev)
852{
853 struct i40e_netdev_priv *np = netdev_priv(netdev);
854 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000855 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000856
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000857 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
858 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
859 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
860 /* register returns value in power of 2, 64Kbyte chunks. */
861 val = (64 * 1024) * (1 << val);
862 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000863}
864
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000865static int i40e_set_eeprom(struct net_device *netdev,
866 struct ethtool_eeprom *eeprom, u8 *bytes)
867{
868 struct i40e_netdev_priv *np = netdev_priv(netdev);
869 struct i40e_hw *hw = &np->vsi->back->hw;
870 struct i40e_pf *pf = np->vsi->back;
871 int ret_val = 0;
872 int errno;
873 u32 magic;
874
875 /* normal ethtool set_eeprom is not supported */
876 magic = hw->vendor_id | (hw->device_id << 16);
877 if (eeprom->magic == magic)
878 return -EOPNOTSUPP;
879
880 /* check for NVMUpdate access method */
881 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
882 return -EINVAL;
883
884 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
885 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
886 return -EBUSY;
887
888 ret_val = i40e_nvmupd_command(hw, (struct i40e_nvm_access *)eeprom,
889 bytes, &errno);
890 if (ret_val)
891 dev_info(&pf->pdev->dev,
892 "NVMUpdate write failed err=%d status=0x%x\n",
893 ret_val, hw->aq.asq_last_status);
894
895 return errno;
896}
897
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000898static void i40e_get_drvinfo(struct net_device *netdev,
899 struct ethtool_drvinfo *drvinfo)
900{
901 struct i40e_netdev_priv *np = netdev_priv(netdev);
902 struct i40e_vsi *vsi = np->vsi;
903 struct i40e_pf *pf = vsi->back;
904
905 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
906 strlcpy(drvinfo->version, i40e_driver_version_str,
907 sizeof(drvinfo->version));
908 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
909 sizeof(drvinfo->fw_version));
910 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
911 sizeof(drvinfo->bus_info));
912}
913
914static void i40e_get_ringparam(struct net_device *netdev,
915 struct ethtool_ringparam *ring)
916{
917 struct i40e_netdev_priv *np = netdev_priv(netdev);
918 struct i40e_pf *pf = np->vsi->back;
919 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
920
921 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
922 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
923 ring->rx_mini_max_pending = 0;
924 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +0000925 ring->rx_pending = vsi->rx_rings[0]->count;
926 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000927 ring->rx_mini_pending = 0;
928 ring->rx_jumbo_pending = 0;
929}
930
931static int i40e_set_ringparam(struct net_device *netdev,
932 struct ethtool_ringparam *ring)
933{
934 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
935 struct i40e_netdev_priv *np = netdev_priv(netdev);
936 struct i40e_vsi *vsi = np->vsi;
937 struct i40e_pf *pf = vsi->back;
938 u32 new_rx_count, new_tx_count;
939 int i, err = 0;
940
941 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
942 return -EINVAL;
943
Shannon Nelson1fa18372013-11-20 10:03:08 +0000944 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
945 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
946 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
947 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
948 netdev_info(netdev,
949 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
950 ring->tx_pending, ring->rx_pending,
951 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
952 return -EINVAL;
953 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000954
Shannon Nelson1fa18372013-11-20 10:03:08 +0000955 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
956 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000957
958 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000959 if ((new_tx_count == vsi->tx_rings[0]->count) &&
960 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000961 return 0;
962
963 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
964 usleep_range(1000, 2000);
965
966 if (!netif_running(vsi->netdev)) {
967 /* simple case - set for the next time the netdev is started */
968 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000969 vsi->tx_rings[i]->count = new_tx_count;
970 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000971 }
972 goto done;
973 }
974
975 /* We can't just free everything and then setup again,
976 * because the ISRs in MSI-X mode get passed pointers
977 * to the Tx and Rx ring structs.
978 */
979
980 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000981 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000982 netdev_info(netdev,
983 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000984 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000985 tx_rings = kcalloc(vsi->alloc_queue_pairs,
986 sizeof(struct i40e_ring), GFP_KERNEL);
987 if (!tx_rings) {
988 err = -ENOMEM;
989 goto done;
990 }
991
992 for (i = 0; i < vsi->num_queue_pairs; i++) {
993 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000994 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000995 tx_rings[i].count = new_tx_count;
996 err = i40e_setup_tx_descriptors(&tx_rings[i]);
997 if (err) {
998 while (i) {
999 i--;
1000 i40e_free_tx_resources(&tx_rings[i]);
1001 }
1002 kfree(tx_rings);
1003 tx_rings = NULL;
1004
1005 goto done;
1006 }
1007 }
1008 }
1009
1010 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001011 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001012 netdev_info(netdev,
1013 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001014 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001015 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1016 sizeof(struct i40e_ring), GFP_KERNEL);
1017 if (!rx_rings) {
1018 err = -ENOMEM;
1019 goto free_tx;
1020 }
1021
1022 for (i = 0; i < vsi->num_queue_pairs; i++) {
1023 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001024 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001025 rx_rings[i].count = new_rx_count;
1026 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1027 if (err) {
1028 while (i) {
1029 i--;
1030 i40e_free_rx_resources(&rx_rings[i]);
1031 }
1032 kfree(rx_rings);
1033 rx_rings = NULL;
1034
1035 goto free_tx;
1036 }
1037 }
1038 }
1039
1040 /* Bring interface down, copy in the new ring info,
1041 * then restore the interface
1042 */
1043 i40e_down(vsi);
1044
1045 if (tx_rings) {
1046 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001047 i40e_free_tx_resources(vsi->tx_rings[i]);
1048 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001049 }
1050 kfree(tx_rings);
1051 tx_rings = NULL;
1052 }
1053
1054 if (rx_rings) {
1055 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001056 i40e_free_rx_resources(vsi->rx_rings[i]);
1057 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001058 }
1059 kfree(rx_rings);
1060 rx_rings = NULL;
1061 }
1062
1063 i40e_up(vsi);
1064
1065free_tx:
1066 /* error cleanup if the Rx allocations failed after getting Tx */
1067 if (tx_rings) {
1068 for (i = 0; i < vsi->num_queue_pairs; i++)
1069 i40e_free_tx_resources(&tx_rings[i]);
1070 kfree(tx_rings);
1071 tx_rings = NULL;
1072 }
1073
1074done:
1075 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1076
1077 return err;
1078}
1079
1080static int i40e_get_sset_count(struct net_device *netdev, int sset)
1081{
1082 struct i40e_netdev_priv *np = netdev_priv(netdev);
1083 struct i40e_vsi *vsi = np->vsi;
1084 struct i40e_pf *pf = vsi->back;
1085
1086 switch (sset) {
1087 case ETH_SS_TEST:
1088 return I40E_TEST_LEN;
1089 case ETH_SS_STATS:
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001090 if (vsi == pf->vsi[pf->lan_vsi]) {
1091 int len = I40E_PF_STATS_LEN(netdev);
1092
1093 if (pf->lan_veb != I40E_NO_VEB)
1094 len += I40E_VEB_STATS_LEN;
1095 return len;
1096 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001097 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001098 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001099 default:
1100 return -EOPNOTSUPP;
1101 }
1102}
1103
1104static void i40e_get_ethtool_stats(struct net_device *netdev,
1105 struct ethtool_stats *stats, u64 *data)
1106{
1107 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001108 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001109 struct i40e_vsi *vsi = np->vsi;
1110 struct i40e_pf *pf = vsi->back;
1111 int i = 0;
1112 char *p;
1113 int j;
1114 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001115 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001116
1117 i40e_update_stats(vsi);
1118
1119 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1120 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1121 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1122 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1123 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001124 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1125 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1126 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1127 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1128 }
Vasu Dev38e00432014-08-01 13:27:03 -07001129#ifdef I40E_FCOE
1130 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1131 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1132 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1133 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1134 }
1135#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001136 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001137 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001138 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001139
1140 if (!tx_ring)
1141 continue;
1142
1143 /* process Tx ring statistics */
1144 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001145 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001146 data[i] = tx_ring->stats.packets;
1147 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001148 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001149 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001150
1151 /* Rx ring is the 2nd half of the queue pair */
1152 rx_ring = &tx_ring[1];
1153 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001154 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001155 data[i] = rx_ring->stats.packets;
1156 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001157 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001158 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001159 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001160 rcu_read_unlock();
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001161 if (vsi != pf->vsi[pf->lan_vsi])
1162 return;
1163
1164 if (pf->lan_veb != I40E_NO_VEB) {
1165 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1166 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1167 p = (char *)veb;
1168 p += i40e_gstrings_veb_stats[j].stat_offset;
1169 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1170 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001171 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001172 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001173 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1174 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1175 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1176 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1177 }
1178 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1179 data[i++] = pf->stats.priority_xon_tx[j];
1180 data[i++] = pf->stats.priority_xoff_tx[j];
1181 }
1182 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1183 data[i++] = pf->stats.priority_xon_rx[j];
1184 data[i++] = pf->stats.priority_xoff_rx[j];
1185 }
1186 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1187 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001188}
1189
1190static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1191 u8 *data)
1192{
1193 struct i40e_netdev_priv *np = netdev_priv(netdev);
1194 struct i40e_vsi *vsi = np->vsi;
1195 struct i40e_pf *pf = vsi->back;
1196 char *p = (char *)data;
1197 int i;
1198
1199 switch (stringset) {
1200 case ETH_SS_TEST:
1201 for (i = 0; i < I40E_TEST_LEN; i++) {
1202 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1203 data += ETH_GSTRING_LEN;
1204 }
1205 break;
1206 case ETH_SS_STATS:
1207 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1208 snprintf(p, ETH_GSTRING_LEN, "%s",
1209 i40e_gstrings_net_stats[i].stat_string);
1210 p += ETH_GSTRING_LEN;
1211 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001212 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1213 snprintf(p, ETH_GSTRING_LEN, "%s",
1214 i40e_gstrings_misc_stats[i].stat_string);
1215 p += ETH_GSTRING_LEN;
1216 }
Vasu Dev38e00432014-08-01 13:27:03 -07001217#ifdef I40E_FCOE
1218 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1219 snprintf(p, ETH_GSTRING_LEN, "%s",
1220 i40e_gstrings_fcoe_stats[i].stat_string);
1221 p += ETH_GSTRING_LEN;
1222 }
1223#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001224 for (i = 0; i < vsi->num_queue_pairs; i++) {
1225 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1226 p += ETH_GSTRING_LEN;
1227 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1228 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001229 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1230 p += ETH_GSTRING_LEN;
1231 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1232 p += ETH_GSTRING_LEN;
1233 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001234 if (vsi != pf->vsi[pf->lan_vsi])
1235 return;
1236
1237 if (pf->lan_veb != I40E_NO_VEB) {
1238 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1239 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1240 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001241 p += ETH_GSTRING_LEN;
1242 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001243 }
1244 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1245 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1246 i40e_gstrings_stats[i].stat_string);
1247 p += ETH_GSTRING_LEN;
1248 }
1249 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1250 snprintf(p, ETH_GSTRING_LEN,
1251 "port.tx_priority_%u_xon", i);
1252 p += ETH_GSTRING_LEN;
1253 snprintf(p, ETH_GSTRING_LEN,
1254 "port.tx_priority_%u_xoff", i);
1255 p += ETH_GSTRING_LEN;
1256 }
1257 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1258 snprintf(p, ETH_GSTRING_LEN,
1259 "port.rx_priority_%u_xon", i);
1260 p += ETH_GSTRING_LEN;
1261 snprintf(p, ETH_GSTRING_LEN,
1262 "port.rx_priority_%u_xoff", i);
1263 p += ETH_GSTRING_LEN;
1264 }
1265 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1266 snprintf(p, ETH_GSTRING_LEN,
1267 "port.rx_priority_%u_xon_2_xoff", i);
1268 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001269 }
1270 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1271 break;
1272 }
1273}
1274
1275static int i40e_get_ts_info(struct net_device *dev,
1276 struct ethtool_ts_info *info)
1277{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001278 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1279
1280 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1281 SOF_TIMESTAMPING_RX_SOFTWARE |
1282 SOF_TIMESTAMPING_SOFTWARE |
1283 SOF_TIMESTAMPING_TX_HARDWARE |
1284 SOF_TIMESTAMPING_RX_HARDWARE |
1285 SOF_TIMESTAMPING_RAW_HARDWARE;
1286
1287 if (pf->ptp_clock)
1288 info->phc_index = ptp_clock_index(pf->ptp_clock);
1289 else
1290 info->phc_index = -1;
1291
1292 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1293
1294 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1295 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1296 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1297 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1298 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1299 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1300 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1301 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1302 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1303 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1304 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1305 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1306
1307 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001308}
1309
Shannon Nelson7b086392013-11-20 10:02:59 +00001310static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001311{
Shannon Nelson7b086392013-11-20 10:02:59 +00001312 struct i40e_netdev_priv *np = netdev_priv(netdev);
1313 struct i40e_pf *pf = np->vsi->back;
1314
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001315 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001316 if (i40e_get_link_status(&pf->hw))
1317 *data = 0;
1318 else
1319 *data = 1;
1320
1321 return *data;
1322}
1323
Shannon Nelson7b086392013-11-20 10:02:59 +00001324static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001325{
Shannon Nelson7b086392013-11-20 10:02:59 +00001326 struct i40e_netdev_priv *np = netdev_priv(netdev);
1327 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001328
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001329 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001330 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001331
Shannon Nelson7b086392013-11-20 10:02:59 +00001332 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001333}
1334
Shannon Nelson7b086392013-11-20 10:02:59 +00001335static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001336{
Shannon Nelson7b086392013-11-20 10:02:59 +00001337 struct i40e_netdev_priv *np = netdev_priv(netdev);
1338 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001339
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001340 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001341 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001342
Shannon Nelson7b086392013-11-20 10:02:59 +00001343 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001344}
1345
Shannon Nelson7b086392013-11-20 10:02:59 +00001346static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001347{
Shannon Nelson7b086392013-11-20 10:02:59 +00001348 struct i40e_netdev_priv *np = netdev_priv(netdev);
1349 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001350 u16 swc_old = pf->sw_int_count;
1351
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001352 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001353 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1354 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
1355 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
1356 usleep_range(1000, 2000);
1357 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001358
1359 return *data;
1360}
1361
Shannon Nelson7b086392013-11-20 10:02:59 +00001362static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001363{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001364 struct i40e_netdev_priv *np = netdev_priv(netdev);
1365 struct i40e_pf *pf = np->vsi->back;
1366
1367 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001368 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001369
1370 return *data;
1371}
1372
1373static void i40e_diag_test(struct net_device *netdev,
1374 struct ethtool_test *eth_test, u64 *data)
1375{
1376 struct i40e_netdev_priv *np = netdev_priv(netdev);
1377 struct i40e_pf *pf = np->vsi->back;
1378
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001379 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1380 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001381 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001382
Shannon Nelsonf551b432013-11-26 10:49:12 +00001383 set_bit(__I40E_TESTING, &pf->state);
1384
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001385 /* Link test performed before hardware reset
1386 * so autoneg doesn't interfere with test result
1387 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001388 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001389 eth_test->flags |= ETH_TEST_FL_FAILED;
1390
Shannon Nelson7b086392013-11-20 10:02:59 +00001391 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001392 eth_test->flags |= ETH_TEST_FL_FAILED;
1393
Shannon Nelson7b086392013-11-20 10:02:59 +00001394 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001395 eth_test->flags |= ETH_TEST_FL_FAILED;
1396
Shannon Nelson7b086392013-11-20 10:02:59 +00001397 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001398 eth_test->flags |= ETH_TEST_FL_FAILED;
1399
Shannon Nelsonf551b432013-11-26 10:49:12 +00001400 /* run reg test last, a reset is required after it */
1401 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1402 eth_test->flags |= ETH_TEST_FL_FAILED;
1403
1404 clear_bit(__I40E_TESTING, &pf->state);
1405 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001406 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001407 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001408 netif_info(pf, drv, netdev, "online testing starting\n");
1409
Shannon Nelson7b086392013-11-20 10:02:59 +00001410 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001411 eth_test->flags |= ETH_TEST_FL_FAILED;
1412
1413 /* Offline only tests, not run in online; pass by default */
1414 data[I40E_ETH_TEST_REG] = 0;
1415 data[I40E_ETH_TEST_EEPROM] = 0;
1416 data[I40E_ETH_TEST_INTR] = 0;
1417 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001418 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001419
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001420 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001421}
1422
1423static void i40e_get_wol(struct net_device *netdev,
1424 struct ethtool_wolinfo *wol)
1425{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001426 struct i40e_netdev_priv *np = netdev_priv(netdev);
1427 struct i40e_pf *pf = np->vsi->back;
1428 struct i40e_hw *hw = &pf->hw;
1429 u16 wol_nvm_bits;
1430
1431 /* NVM bit on means WoL disabled for the port */
1432 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1433 if ((1 << hw->port) & wol_nvm_bits) {
1434 wol->supported = 0;
1435 wol->wolopts = 0;
1436 } else {
1437 wol->supported = WAKE_MAGIC;
1438 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1439 }
1440}
1441
1442static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1443{
1444 struct i40e_netdev_priv *np = netdev_priv(netdev);
1445 struct i40e_pf *pf = np->vsi->back;
1446 struct i40e_hw *hw = &pf->hw;
1447 u16 wol_nvm_bits;
1448
1449 /* NVM bit on means WoL disabled for the port */
1450 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1451 if (((1 << hw->port) & wol_nvm_bits))
1452 return -EOPNOTSUPP;
1453
1454 /* only magic packet is supported */
1455 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1456 return -EOPNOTSUPP;
1457
1458 /* is this a new value? */
1459 if (pf->wol_en != !!wol->wolopts) {
1460 pf->wol_en = !!wol->wolopts;
1461 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1462 }
1463
1464 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001465}
1466
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001467static int i40e_set_phys_id(struct net_device *netdev,
1468 enum ethtool_phys_id_state state)
1469{
1470 struct i40e_netdev_priv *np = netdev_priv(netdev);
1471 struct i40e_pf *pf = np->vsi->back;
1472 struct i40e_hw *hw = &pf->hw;
1473 int blink_freq = 2;
1474
1475 switch (state) {
1476 case ETHTOOL_ID_ACTIVE:
1477 pf->led_status = i40e_led_get(hw);
1478 return blink_freq;
1479 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001480 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001481 break;
1482 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001483 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001484 break;
1485 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001486 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001487 break;
1488 }
1489
1490 return 0;
1491}
1492
1493/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1494 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1495 * 125us (8000 interrupts per second) == ITR(62)
1496 */
1497
1498static int i40e_get_coalesce(struct net_device *netdev,
1499 struct ethtool_coalesce *ec)
1500{
1501 struct i40e_netdev_priv *np = netdev_priv(netdev);
1502 struct i40e_vsi *vsi = np->vsi;
1503
1504 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1505 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1506
1507 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001508 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001509
1510 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001511 ec->use_adaptive_tx_coalesce = 1;
1512
1513 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1514 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001515
1516 return 0;
1517}
1518
1519static int i40e_set_coalesce(struct net_device *netdev,
1520 struct ethtool_coalesce *ec)
1521{
1522 struct i40e_netdev_priv *np = netdev_priv(netdev);
1523 struct i40e_q_vector *q_vector;
1524 struct i40e_vsi *vsi = np->vsi;
1525 struct i40e_pf *pf = vsi->back;
1526 struct i40e_hw *hw = &pf->hw;
1527 u16 vector;
1528 int i;
1529
1530 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1531 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1532
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001533 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001534 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001535 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001536 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001537 } else if (ec->rx_coalesce_usecs == 0) {
1538 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1539 i40e_irq_dynamic_disable(vsi, vector);
1540 if (ec->use_adaptive_rx_coalesce)
1541 netif_info(pf, drv, netdev,
1542 "Rx-secs=0, need to disable adaptive-Rx for a complete disable\n");
1543 } else {
1544 netif_info(pf, drv, netdev,
1545 "Invalid value, Rx-usecs range is 0, 8-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001546 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001547 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001548
Mitch Williams32f5f542014-04-04 04:43:10 +00001549 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001550 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001551 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001552 } else if (ec->tx_coalesce_usecs == 0) {
1553 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1554 i40e_irq_dynamic_disable(vsi, vector);
1555 if (ec->use_adaptive_tx_coalesce)
1556 netif_info(pf, drv, netdev,
1557 "Tx-secs=0, need to disable adaptive-Tx for a complete disable\n");
1558 } else {
1559 netif_info(pf, drv, netdev,
1560 "Invalid value, Tx-usecs range is 0, 8-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001561 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001562 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001563
1564 if (ec->use_adaptive_rx_coalesce)
1565 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1566 else
1567 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1568
1569 if (ec->use_adaptive_tx_coalesce)
1570 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1571 else
1572 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001573
Alexander Duyck493fb302013-09-28 07:01:44 +00001574 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1575 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001576 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1577 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1578 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1579 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1580 i40e_flush(hw);
1581 }
1582
1583 return 0;
1584}
1585
1586/**
1587 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1588 * @pf: pointer to the physical function struct
1589 * @cmd: ethtool rxnfc command
1590 *
1591 * Returns Success if the flow is supported, else Invalid Input.
1592 **/
1593static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1594{
1595 cmd->data = 0;
1596
1597 /* Report default options for RSS on i40e */
1598 switch (cmd->flow_type) {
1599 case TCP_V4_FLOW:
1600 case UDP_V4_FLOW:
1601 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1602 /* fall through to add IP fields */
1603 case SCTP_V4_FLOW:
1604 case AH_ESP_V4_FLOW:
1605 case AH_V4_FLOW:
1606 case ESP_V4_FLOW:
1607 case IPV4_FLOW:
1608 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1609 break;
1610 case TCP_V6_FLOW:
1611 case UDP_V6_FLOW:
1612 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1613 /* fall through to add IP fields */
1614 case SCTP_V6_FLOW:
1615 case AH_ESP_V6_FLOW:
1616 case AH_V6_FLOW:
1617 case ESP_V6_FLOW:
1618 case IPV6_FLOW:
1619 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1620 break;
1621 default:
1622 return -EINVAL;
1623 }
1624
1625 return 0;
1626}
1627
1628/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001629 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1630 * @pf: Pointer to the physical function struct
1631 * @cmd: The command to get or set Rx flow classification rules
1632 * @rule_locs: Array of used rule locations
1633 *
1634 * This function populates both the total and actual rule count of
1635 * the ethtool flow classification command
1636 *
1637 * Returns 0 on success or -EMSGSIZE if entry not found
1638 **/
1639static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1640 struct ethtool_rxnfc *cmd,
1641 u32 *rule_locs)
1642{
1643 struct i40e_fdir_filter *rule;
1644 struct hlist_node *node2;
1645 int cnt = 0;
1646
1647 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001648 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001649
1650 hlist_for_each_entry_safe(rule, node2,
1651 &pf->fdir_filter_list, fdir_node) {
1652 if (cnt == cmd->rule_cnt)
1653 return -EMSGSIZE;
1654
1655 rule_locs[cnt] = rule->fd_id;
1656 cnt++;
1657 }
1658
1659 cmd->rule_cnt = cnt;
1660
1661 return 0;
1662}
1663
1664/**
1665 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1666 * @pf: Pointer to the physical function struct
1667 * @cmd: The command to get or set Rx flow classification rules
1668 *
1669 * This function looks up a filter based on the Rx flow classification
1670 * command and fills the flow spec info for it if found
1671 *
1672 * Returns 0 on success or -EINVAL if filter not found
1673 **/
1674static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1675 struct ethtool_rxnfc *cmd)
1676{
1677 struct ethtool_rx_flow_spec *fsp =
1678 (struct ethtool_rx_flow_spec *)&cmd->fs;
1679 struct i40e_fdir_filter *rule = NULL;
1680 struct hlist_node *node2;
1681
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001682 hlist_for_each_entry_safe(rule, node2,
1683 &pf->fdir_filter_list, fdir_node) {
1684 if (fsp->location <= rule->fd_id)
1685 break;
1686 }
1687
1688 if (!rule || fsp->location != rule->fd_id)
1689 return -EINVAL;
1690
1691 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001692 if (fsp->flow_type == IP_USER_FLOW) {
1693 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1694 fsp->h_u.usr_ip4_spec.proto = 0;
1695 fsp->m_u.usr_ip4_spec.proto = 0;
1696 }
1697
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001698 /* Reverse the src and dest notion, since the HW views them from
1699 * Tx perspective where as the user expects it from Rx filter view.
1700 */
1701 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1702 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1703 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1704 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001705
1706 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1707 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1708 else
1709 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001710
1711 return 0;
1712}
1713
1714/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001715 * i40e_get_rxnfc - command to get RX flow classification rules
1716 * @netdev: network interface device structure
1717 * @cmd: ethtool rxnfc command
1718 *
1719 * Returns Success if the command is supported.
1720 **/
1721static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1722 u32 *rule_locs)
1723{
1724 struct i40e_netdev_priv *np = netdev_priv(netdev);
1725 struct i40e_vsi *vsi = np->vsi;
1726 struct i40e_pf *pf = vsi->back;
1727 int ret = -EOPNOTSUPP;
1728
1729 switch (cmd->cmd) {
1730 case ETHTOOL_GRXRINGS:
1731 cmd->data = vsi->alloc_queue_pairs;
1732 ret = 0;
1733 break;
1734 case ETHTOOL_GRXFH:
1735 ret = i40e_get_rss_hash_opts(pf, cmd);
1736 break;
1737 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001738 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001739 /* report total rule count */
1740 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001741 ret = 0;
1742 break;
1743 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001744 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001745 break;
1746 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001747 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1748 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001749 default:
1750 break;
1751 }
1752
1753 return ret;
1754}
1755
1756/**
1757 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1758 * @pf: pointer to the physical function struct
1759 * @cmd: ethtool rxnfc command
1760 *
1761 * Returns Success if the flow input set is supported.
1762 **/
1763static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1764{
1765 struct i40e_hw *hw = &pf->hw;
1766 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1767 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1768
1769 /* RSS does not support anything other than hashing
1770 * to queues on src and dst IPs and ports
1771 */
1772 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1773 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1774 return -EINVAL;
1775
1776 /* We need at least the IP SRC and DEST fields for hashing */
1777 if (!(nfc->data & RXH_IP_SRC) ||
1778 !(nfc->data & RXH_IP_DST))
1779 return -EINVAL;
1780
1781 switch (nfc->flow_type) {
1782 case TCP_V4_FLOW:
1783 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1784 case 0:
1785 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1786 break;
1787 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1788 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1789 break;
1790 default:
1791 return -EINVAL;
1792 }
1793 break;
1794 case TCP_V6_FLOW:
1795 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1796 case 0:
1797 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1798 break;
1799 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1800 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1801 break;
1802 default:
1803 return -EINVAL;
1804 }
1805 break;
1806 case UDP_V4_FLOW:
1807 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1808 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001809 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1810 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001811 break;
1812 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001813 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1814 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001815 break;
1816 default:
1817 return -EINVAL;
1818 }
1819 break;
1820 case UDP_V6_FLOW:
1821 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1822 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001823 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1824 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001825 break;
1826 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001827 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1828 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001829 break;
1830 default:
1831 return -EINVAL;
1832 }
1833 break;
1834 case AH_ESP_V4_FLOW:
1835 case AH_V4_FLOW:
1836 case ESP_V4_FLOW:
1837 case SCTP_V4_FLOW:
1838 if ((nfc->data & RXH_L4_B_0_1) ||
1839 (nfc->data & RXH_L4_B_2_3))
1840 return -EINVAL;
1841 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1842 break;
1843 case AH_ESP_V6_FLOW:
1844 case AH_V6_FLOW:
1845 case ESP_V6_FLOW:
1846 case SCTP_V6_FLOW:
1847 if ((nfc->data & RXH_L4_B_0_1) ||
1848 (nfc->data & RXH_L4_B_2_3))
1849 return -EINVAL;
1850 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1851 break;
1852 case IPV4_FLOW:
1853 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1854 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1855 break;
1856 case IPV6_FLOW:
1857 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1858 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1859 break;
1860 default:
1861 return -EINVAL;
1862 }
1863
1864 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1865 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1866 i40e_flush(hw);
1867
1868 return 0;
1869}
1870
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001871/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001872 * i40e_match_fdir_input_set - Match a new filter against an existing one
1873 * @rule: The filter already added
1874 * @input: The new filter to comapre against
1875 *
1876 * Returns true if the two input set match
1877 **/
1878static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1879 struct i40e_fdir_filter *input)
1880{
1881 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1882 (rule->src_ip[0] != input->src_ip[0]) ||
1883 (rule->dst_port != input->dst_port) ||
1884 (rule->src_port != input->src_port))
1885 return false;
1886 return true;
1887}
1888
1889/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001890 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1891 * @vsi: Pointer to the targeted VSI
1892 * @input: The filter to update or NULL to indicate deletion
1893 * @sw_idx: Software index to the filter
1894 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001895 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001896 * This function updates (or deletes) a Flow Director entry from
1897 * the hlist of the corresponding PF
1898 *
1899 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001900 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001901static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1902 struct i40e_fdir_filter *input,
1903 u16 sw_idx,
1904 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001905{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001906 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001907 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001908 struct hlist_node *node2;
1909 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001910
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001911 parent = NULL;
1912 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001913
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001914 hlist_for_each_entry_safe(rule, node2,
1915 &pf->fdir_filter_list, fdir_node) {
1916 /* hash found, or no matching entry */
1917 if (rule->fd_id >= sw_idx)
1918 break;
1919 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001920 }
1921
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001922 /* if there is an old rule occupying our place remove it */
1923 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001924 if (input && !i40e_match_fdir_input_set(rule, input))
1925 err = i40e_add_del_fdir(vsi, rule, false);
1926 else if (!input)
1927 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001928 hlist_del(&rule->fdir_node);
1929 kfree(rule);
1930 pf->fdir_pf_active_filters--;
1931 }
1932
1933 /* If no input this was a delete, err should be 0 if a rule was
1934 * successfully found and removed from the list else -EINVAL
1935 */
1936 if (!input)
1937 return err;
1938
1939 /* initialize node and set software index */
1940 INIT_HLIST_NODE(&input->fdir_node);
1941
1942 /* add filter to the list */
1943 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07001944 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001945 else
1946 hlist_add_head(&input->fdir_node,
1947 &pf->fdir_filter_list);
1948
1949 /* update counts */
1950 pf->fdir_pf_active_filters++;
1951
1952 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001953}
1954
1955/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001956 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
1957 * @vsi: Pointer to the targeted VSI
1958 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001959 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001960 * The function removes a Flow Director filter entry from the
1961 * hlist of the corresponding PF
1962 *
1963 * Returns 0 on success
1964 */
1965static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
1966 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001967{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001968 struct ethtool_rx_flow_spec *fsp =
1969 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001970 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001971 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001972
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00001973 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1974 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1975 return -EBUSY;
1976
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00001977 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
1978 return -EBUSY;
1979
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001980 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001981
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001982 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001983 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001984}
1985
1986/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001987 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001988 * @vsi: pointer to the targeted VSI
1989 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001990 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001991 * Add Flow Director filters for a specific flow spec based on their
1992 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001993 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001994static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
1995 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001996{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001997 struct ethtool_rx_flow_spec *fsp;
1998 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001999 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002000 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002001
2002 if (!vsi)
2003 return -EINVAL;
2004
2005 pf = vsi->back;
2006
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002007 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2008 return -EOPNOTSUPP;
2009
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002010 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002011 return -ENOSPC;
2012
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002013 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2014 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2015 return -EBUSY;
2016
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002017 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2018 return -EBUSY;
2019
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002020 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2021
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002022 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2023 pf->hw.func_caps.fd_filters_guaranteed)) {
2024 return -EINVAL;
2025 }
2026
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002027 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2028 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002029 return -EINVAL;
2030
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002031 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002032
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002033 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002034 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002035
2036 input->fd_id = fsp->location;
2037
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002038 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2039 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2040 else
2041 input->dest_ctl =
2042 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2043
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002044 input->q_index = fsp->ring_cookie;
2045 input->flex_off = 0;
2046 input->pctype = 0;
2047 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002048 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00002049 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002050 input->flow_type = fsp->flow_type;
2051 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002052
2053 /* Reverse the src and dest notion, since the HW expects them to be from
2054 * Tx perspective where as the input from user is from Rx filter view.
2055 */
2056 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2057 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2058 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2059 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002060
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002061 ret = i40e_add_del_fdir(vsi, input, true);
2062 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002063 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002064 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002065 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002066
2067 return ret;
2068}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002069
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002070/**
2071 * i40e_set_rxnfc - command to set RX flow classification rules
2072 * @netdev: network interface device structure
2073 * @cmd: ethtool rxnfc command
2074 *
2075 * Returns Success if the command is supported.
2076 **/
2077static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2078{
2079 struct i40e_netdev_priv *np = netdev_priv(netdev);
2080 struct i40e_vsi *vsi = np->vsi;
2081 struct i40e_pf *pf = vsi->back;
2082 int ret = -EOPNOTSUPP;
2083
2084 switch (cmd->cmd) {
2085 case ETHTOOL_SRXFH:
2086 ret = i40e_set_rss_hash_opt(pf, cmd);
2087 break;
2088 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002089 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002090 break;
2091 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002092 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002093 break;
2094 default:
2095 break;
2096 }
2097
2098 return ret;
2099}
2100
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002101/**
2102 * i40e_max_channels - get Max number of combined channels supported
2103 * @vsi: vsi pointer
2104 **/
2105static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2106{
2107 /* TODO: This code assumes DCB and FD is disabled for now. */
2108 return vsi->alloc_queue_pairs;
2109}
2110
2111/**
2112 * i40e_get_channels - Get the current channels enabled and max supported etc.
2113 * @netdev: network interface device structure
2114 * @ch: ethtool channels structure
2115 *
2116 * We don't support separate tx and rx queues as channels. The other count
2117 * represents how many queues are being used for control. max_combined counts
2118 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2119 * q_vectors since we support a lot more queue pairs than q_vectors.
2120 **/
2121static void i40e_get_channels(struct net_device *dev,
2122 struct ethtool_channels *ch)
2123{
2124 struct i40e_netdev_priv *np = netdev_priv(dev);
2125 struct i40e_vsi *vsi = np->vsi;
2126 struct i40e_pf *pf = vsi->back;
2127
2128 /* report maximum channels */
2129 ch->max_combined = i40e_max_channels(vsi);
2130
2131 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002132 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002133 ch->max_other = ch->other_count;
2134
2135 /* Note: This code assumes DCB is disabled for now. */
2136 ch->combined_count = vsi->num_queue_pairs;
2137}
2138
2139/**
2140 * i40e_set_channels - Set the new channels count.
2141 * @netdev: network interface device structure
2142 * @ch: ethtool channels structure
2143 *
2144 * The new channels count may not be the same as requested by the user
2145 * since it gets rounded down to a power of 2 value.
2146 **/
2147static int i40e_set_channels(struct net_device *dev,
2148 struct ethtool_channels *ch)
2149{
2150 struct i40e_netdev_priv *np = netdev_priv(dev);
2151 unsigned int count = ch->combined_count;
2152 struct i40e_vsi *vsi = np->vsi;
2153 struct i40e_pf *pf = vsi->back;
2154 int new_count;
2155
2156 /* We do not support setting channels for any other VSI at present */
2157 if (vsi->type != I40E_VSI_MAIN)
2158 return -EINVAL;
2159
2160 /* verify they are not requesting separate vectors */
2161 if (!count || ch->rx_count || ch->tx_count)
2162 return -EINVAL;
2163
2164 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002165 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002166 return -EINVAL;
2167
2168 /* verify the number of channels does not exceed hardware limits */
2169 if (count > i40e_max_channels(vsi))
2170 return -EINVAL;
2171
2172 /* update feature limits from largest to smallest supported values */
2173 /* TODO: Flow director limit, DCB etc */
2174
2175 /* cap RSS limit */
2176 if (count > pf->rss_size_max)
2177 count = pf->rss_size_max;
2178
2179 /* use rss_reconfig to rebuild with new queue count and update traffic
2180 * class queue mapping
2181 */
2182 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002183 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002184 return 0;
2185 else
2186 return -EINVAL;
2187}
2188
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002189static const struct ethtool_ops i40e_ethtool_ops = {
2190 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002191 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002192 .get_drvinfo = i40e_get_drvinfo,
2193 .get_regs_len = i40e_get_regs_len,
2194 .get_regs = i40e_get_regs,
2195 .nway_reset = i40e_nway_reset,
2196 .get_link = ethtool_op_get_link,
2197 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002198 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002199 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002200 .get_eeprom_len = i40e_get_eeprom_len,
2201 .get_eeprom = i40e_get_eeprom,
2202 .get_ringparam = i40e_get_ringparam,
2203 .set_ringparam = i40e_set_ringparam,
2204 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002205 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002206 .get_msglevel = i40e_get_msglevel,
2207 .set_msglevel = i40e_set_msglevel,
2208 .get_rxnfc = i40e_get_rxnfc,
2209 .set_rxnfc = i40e_set_rxnfc,
2210 .self_test = i40e_diag_test,
2211 .get_strings = i40e_get_strings,
2212 .set_phys_id = i40e_set_phys_id,
2213 .get_sset_count = i40e_get_sset_count,
2214 .get_ethtool_stats = i40e_get_ethtool_stats,
2215 .get_coalesce = i40e_get_coalesce,
2216 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002217 .get_channels = i40e_get_channels,
2218 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002219 .get_ts_info = i40e_get_ts_info,
2220};
2221
2222void i40e_set_ethtool_ops(struct net_device *netdev)
2223{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002224 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002225}