blob: afad5aa5a12b5efc4ac392940044242215f4473a [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;
647
648 pause->autoneg =
649 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
650 AUTONEG_ENABLE : AUTONEG_DISABLE);
651
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000652 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000653 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000654 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000655 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000656 } else if (hw->fc.current_mode == I40E_FC_FULL) {
657 pause->rx_pause = 1;
658 pause->tx_pause = 1;
659 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000660}
661
Catherine Sullivan2becc352014-06-04 08:45:27 +0000662/**
663 * i40e_set_pauseparam - Set Flow Control parameter
664 * @netdev: network interface device structure
665 * @pause: return tx/rx flow control status
666 **/
667static int i40e_set_pauseparam(struct net_device *netdev,
668 struct ethtool_pauseparam *pause)
669{
670 struct i40e_netdev_priv *np = netdev_priv(netdev);
671 struct i40e_pf *pf = np->vsi->back;
672 struct i40e_vsi *vsi = np->vsi;
673 struct i40e_hw *hw = &pf->hw;
674 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
675 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
676 i40e_status status;
677 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000678 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000679
680 if (vsi != pf->vsi[pf->lan_vsi])
681 return -EOPNOTSUPP;
682
683 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
684 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
685 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
686 return -EOPNOTSUPP;
687 }
688
689 /* If we have link and don't have autoneg */
690 if (!test_bit(__I40E_DOWN, &pf->state) &&
691 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
692 /* Send message that it might not necessarily work*/
693 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
694 }
695
696 if (hw->fc.current_mode == I40E_FC_PFC) {
697 netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
698 return -EOPNOTSUPP;
699 }
700
701 if (pause->rx_pause && pause->tx_pause)
702 hw->fc.requested_mode = I40E_FC_FULL;
703 else if (pause->rx_pause && !pause->tx_pause)
704 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
705 else if (!pause->rx_pause && pause->tx_pause)
706 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
707 else if (!pause->rx_pause && !pause->tx_pause)
708 hw->fc.requested_mode = I40E_FC_NONE;
709 else
710 return -EINVAL;
711
Catherine Sullivan94128512014-07-12 07:28:16 +0000712 /* Tell the OS link is going down, the link will go back up when fw
713 * says it is ready asynchronously
714 */
715 netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
716 netif_carrier_off(netdev);
717 netif_tx_stop_all_queues(netdev);
718
Catherine Sullivan2becc352014-06-04 08:45:27 +0000719 /* Set the fc mode and only restart an if link is up*/
720 status = i40e_set_fc(hw, &aq_failures, link_up);
721
722 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
723 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
724 status, hw->aq.asq_last_status);
725 err = -EAGAIN;
726 }
727 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
728 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
729 status, hw->aq.asq_last_status);
730 err = -EAGAIN;
731 }
732 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
733 netdev_info(netdev, "Set fc failed on the update_link_info call with error %d and status %d\n",
734 status, hw->aq.asq_last_status);
735 err = -EAGAIN;
736 }
737
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000738 if (!test_bit(__I40E_DOWN, &pf->state)) {
739 /* Give it a little more time to try to come back */
740 msleep(75);
741 if (!test_bit(__I40E_DOWN, &pf->state))
742 return i40e_nway_reset(netdev);
743 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000744
745 return err;
746}
747
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000748static u32 i40e_get_msglevel(struct net_device *netdev)
749{
750 struct i40e_netdev_priv *np = netdev_priv(netdev);
751 struct i40e_pf *pf = np->vsi->back;
752
753 return pf->msg_enable;
754}
755
756static void i40e_set_msglevel(struct net_device *netdev, u32 data)
757{
758 struct i40e_netdev_priv *np = netdev_priv(netdev);
759 struct i40e_pf *pf = np->vsi->back;
760
761 if (I40E_DEBUG_USER & data)
762 pf->hw.debug_mask = data;
763 pf->msg_enable = data;
764}
765
766static int i40e_get_regs_len(struct net_device *netdev)
767{
768 int reg_count = 0;
769 int i;
770
771 for (i = 0; i40e_reg_list[i].offset != 0; i++)
772 reg_count += i40e_reg_list[i].elements;
773
774 return reg_count * sizeof(u32);
775}
776
777static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
778 void *p)
779{
780 struct i40e_netdev_priv *np = netdev_priv(netdev);
781 struct i40e_pf *pf = np->vsi->back;
782 struct i40e_hw *hw = &pf->hw;
783 u32 *reg_buf = p;
784 int i, j, ri;
785 u32 reg;
786
787 /* Tell ethtool which driver-version-specific regs output we have.
788 *
789 * At some point, if we have ethtool doing special formatting of
790 * this data, it will rely on this version number to know how to
791 * interpret things. Hence, this needs to be updated if/when the
792 * diags register table is changed.
793 */
794 regs->version = 1;
795
796 /* loop through the diags reg table for what to print */
797 ri = 0;
798 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
799 for (j = 0; j < i40e_reg_list[i].elements; j++) {
800 reg = i40e_reg_list[i].offset
801 + (j * i40e_reg_list[i].stride);
802 reg_buf[ri++] = rd32(hw, reg);
803 }
804 }
805
806}
807
808static int i40e_get_eeprom(struct net_device *netdev,
809 struct ethtool_eeprom *eeprom, u8 *bytes)
810{
811 struct i40e_netdev_priv *np = netdev_priv(netdev);
812 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000813 struct i40e_pf *pf = np->vsi->back;
814 int ret_val = 0, len;
815 u8 *eeprom_buff;
816 u16 i, sectors;
817 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000818 u32 magic;
819
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000820#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000821 if (eeprom->len == 0)
822 return -EINVAL;
823
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000824 /* check for NVMUpdate access method */
825 magic = hw->vendor_id | (hw->device_id << 16);
826 if (eeprom->magic && eeprom->magic != magic) {
827 int errno;
828
829 /* make sure it is the right magic for NVMUpdate */
830 if ((eeprom->magic >> 16) != hw->device_id)
831 return -EINVAL;
832
833 ret_val = i40e_nvmupd_command(hw,
834 (struct i40e_nvm_access *)eeprom,
835 bytes, &errno);
836 if (ret_val)
837 dev_info(&pf->pdev->dev,
838 "NVMUpdate read failed err=%d status=0x%x\n",
839 ret_val, hw->aq.asq_last_status);
840
841 return errno;
842 }
843
844 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000845 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
846
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000847 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000848 if (!eeprom_buff)
849 return -ENOMEM;
850
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000851 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
852 if (ret_val) {
853 dev_info(&pf->pdev->dev,
854 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
855 ret_val, hw->aq.asq_last_status);
856 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000857 }
858
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000859 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
860 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
861 len = I40E_NVM_SECTOR_SIZE;
862 last = false;
863 for (i = 0; i < sectors; i++) {
864 if (i == (sectors - 1)) {
865 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
866 last = true;
867 }
868 ret_val = i40e_aq_read_nvm(hw, 0x0,
869 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
870 len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000871 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000872 last, NULL);
873 if (ret_val) {
874 dev_info(&pf->pdev->dev,
875 "read NVM failed err=%d status=0x%x\n",
876 ret_val, hw->aq.asq_last_status);
877 goto release_nvm;
878 }
879 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000880
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000881release_nvm:
882 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000883 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000884free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000885 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000886 return ret_val;
887}
888
889static int i40e_get_eeprom_len(struct net_device *netdev)
890{
891 struct i40e_netdev_priv *np = netdev_priv(netdev);
892 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000893 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000894
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000895 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
896 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
897 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
898 /* register returns value in power of 2, 64Kbyte chunks. */
899 val = (64 * 1024) * (1 << val);
900 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000901}
902
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000903static int i40e_set_eeprom(struct net_device *netdev,
904 struct ethtool_eeprom *eeprom, u8 *bytes)
905{
906 struct i40e_netdev_priv *np = netdev_priv(netdev);
907 struct i40e_hw *hw = &np->vsi->back->hw;
908 struct i40e_pf *pf = np->vsi->back;
909 int ret_val = 0;
910 int errno;
911 u32 magic;
912
913 /* normal ethtool set_eeprom is not supported */
914 magic = hw->vendor_id | (hw->device_id << 16);
915 if (eeprom->magic == magic)
916 return -EOPNOTSUPP;
917
918 /* check for NVMUpdate access method */
919 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
920 return -EINVAL;
921
922 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
923 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
924 return -EBUSY;
925
926 ret_val = i40e_nvmupd_command(hw, (struct i40e_nvm_access *)eeprom,
927 bytes, &errno);
928 if (ret_val)
929 dev_info(&pf->pdev->dev,
930 "NVMUpdate write failed err=%d status=0x%x\n",
931 ret_val, hw->aq.asq_last_status);
932
933 return errno;
934}
935
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000936static void i40e_get_drvinfo(struct net_device *netdev,
937 struct ethtool_drvinfo *drvinfo)
938{
939 struct i40e_netdev_priv *np = netdev_priv(netdev);
940 struct i40e_vsi *vsi = np->vsi;
941 struct i40e_pf *pf = vsi->back;
942
943 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
944 strlcpy(drvinfo->version, i40e_driver_version_str,
945 sizeof(drvinfo->version));
946 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
947 sizeof(drvinfo->fw_version));
948 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
949 sizeof(drvinfo->bus_info));
950}
951
952static void i40e_get_ringparam(struct net_device *netdev,
953 struct ethtool_ringparam *ring)
954{
955 struct i40e_netdev_priv *np = netdev_priv(netdev);
956 struct i40e_pf *pf = np->vsi->back;
957 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
958
959 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
960 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
961 ring->rx_mini_max_pending = 0;
962 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +0000963 ring->rx_pending = vsi->rx_rings[0]->count;
964 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000965 ring->rx_mini_pending = 0;
966 ring->rx_jumbo_pending = 0;
967}
968
969static int i40e_set_ringparam(struct net_device *netdev,
970 struct ethtool_ringparam *ring)
971{
972 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
973 struct i40e_netdev_priv *np = netdev_priv(netdev);
974 struct i40e_vsi *vsi = np->vsi;
975 struct i40e_pf *pf = vsi->back;
976 u32 new_rx_count, new_tx_count;
977 int i, err = 0;
978
979 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
980 return -EINVAL;
981
Shannon Nelson1fa18372013-11-20 10:03:08 +0000982 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
983 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
984 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
985 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
986 netdev_info(netdev,
987 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
988 ring->tx_pending, ring->rx_pending,
989 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
990 return -EINVAL;
991 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000992
Shannon Nelson1fa18372013-11-20 10:03:08 +0000993 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
994 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000995
996 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000997 if ((new_tx_count == vsi->tx_rings[0]->count) &&
998 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000999 return 0;
1000
1001 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1002 usleep_range(1000, 2000);
1003
1004 if (!netif_running(vsi->netdev)) {
1005 /* simple case - set for the next time the netdev is started */
1006 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001007 vsi->tx_rings[i]->count = new_tx_count;
1008 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001009 }
1010 goto done;
1011 }
1012
1013 /* We can't just free everything and then setup again,
1014 * because the ISRs in MSI-X mode get passed pointers
1015 * to the Tx and Rx ring structs.
1016 */
1017
1018 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001019 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001020 netdev_info(netdev,
1021 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001022 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001023 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1024 sizeof(struct i40e_ring), GFP_KERNEL);
1025 if (!tx_rings) {
1026 err = -ENOMEM;
1027 goto done;
1028 }
1029
1030 for (i = 0; i < vsi->num_queue_pairs; i++) {
1031 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001032 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001033 tx_rings[i].count = new_tx_count;
1034 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1035 if (err) {
1036 while (i) {
1037 i--;
1038 i40e_free_tx_resources(&tx_rings[i]);
1039 }
1040 kfree(tx_rings);
1041 tx_rings = NULL;
1042
1043 goto done;
1044 }
1045 }
1046 }
1047
1048 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001049 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001050 netdev_info(netdev,
1051 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001052 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001053 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1054 sizeof(struct i40e_ring), GFP_KERNEL);
1055 if (!rx_rings) {
1056 err = -ENOMEM;
1057 goto free_tx;
1058 }
1059
1060 for (i = 0; i < vsi->num_queue_pairs; i++) {
1061 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001062 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001063 rx_rings[i].count = new_rx_count;
1064 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1065 if (err) {
1066 while (i) {
1067 i--;
1068 i40e_free_rx_resources(&rx_rings[i]);
1069 }
1070 kfree(rx_rings);
1071 rx_rings = NULL;
1072
1073 goto free_tx;
1074 }
1075 }
1076 }
1077
1078 /* Bring interface down, copy in the new ring info,
1079 * then restore the interface
1080 */
1081 i40e_down(vsi);
1082
1083 if (tx_rings) {
1084 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001085 i40e_free_tx_resources(vsi->tx_rings[i]);
1086 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001087 }
1088 kfree(tx_rings);
1089 tx_rings = NULL;
1090 }
1091
1092 if (rx_rings) {
1093 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001094 i40e_free_rx_resources(vsi->rx_rings[i]);
1095 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001096 }
1097 kfree(rx_rings);
1098 rx_rings = NULL;
1099 }
1100
1101 i40e_up(vsi);
1102
1103free_tx:
1104 /* error cleanup if the Rx allocations failed after getting Tx */
1105 if (tx_rings) {
1106 for (i = 0; i < vsi->num_queue_pairs; i++)
1107 i40e_free_tx_resources(&tx_rings[i]);
1108 kfree(tx_rings);
1109 tx_rings = NULL;
1110 }
1111
1112done:
1113 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1114
1115 return err;
1116}
1117
1118static int i40e_get_sset_count(struct net_device *netdev, int sset)
1119{
1120 struct i40e_netdev_priv *np = netdev_priv(netdev);
1121 struct i40e_vsi *vsi = np->vsi;
1122 struct i40e_pf *pf = vsi->back;
1123
1124 switch (sset) {
1125 case ETH_SS_TEST:
1126 return I40E_TEST_LEN;
1127 case ETH_SS_STATS:
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001128 if (vsi == pf->vsi[pf->lan_vsi]) {
1129 int len = I40E_PF_STATS_LEN(netdev);
1130
1131 if (pf->lan_veb != I40E_NO_VEB)
1132 len += I40E_VEB_STATS_LEN;
1133 return len;
1134 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001135 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001136 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001137 default:
1138 return -EOPNOTSUPP;
1139 }
1140}
1141
1142static void i40e_get_ethtool_stats(struct net_device *netdev,
1143 struct ethtool_stats *stats, u64 *data)
1144{
1145 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001146 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001147 struct i40e_vsi *vsi = np->vsi;
1148 struct i40e_pf *pf = vsi->back;
1149 int i = 0;
1150 char *p;
1151 int j;
1152 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001153 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001154
1155 i40e_update_stats(vsi);
1156
1157 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1158 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1159 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1160 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1161 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001162 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1163 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1164 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1165 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1166 }
Vasu Dev38e00432014-08-01 13:27:03 -07001167#ifdef I40E_FCOE
1168 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1169 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1170 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1171 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1172 }
1173#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001174 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001175 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001176 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001177
1178 if (!tx_ring)
1179 continue;
1180
1181 /* process Tx ring statistics */
1182 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001183 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001184 data[i] = tx_ring->stats.packets;
1185 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001186 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001187 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001188
1189 /* Rx ring is the 2nd half of the queue pair */
1190 rx_ring = &tx_ring[1];
1191 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001192 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001193 data[i] = rx_ring->stats.packets;
1194 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001195 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001196 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001197 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001198 rcu_read_unlock();
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001199 if (vsi != pf->vsi[pf->lan_vsi])
1200 return;
1201
1202 if (pf->lan_veb != I40E_NO_VEB) {
1203 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1204 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1205 p = (char *)veb;
1206 p += i40e_gstrings_veb_stats[j].stat_offset;
1207 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1208 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001209 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001210 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001211 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1212 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1213 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1214 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1215 }
1216 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1217 data[i++] = pf->stats.priority_xon_tx[j];
1218 data[i++] = pf->stats.priority_xoff_tx[j];
1219 }
1220 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1221 data[i++] = pf->stats.priority_xon_rx[j];
1222 data[i++] = pf->stats.priority_xoff_rx[j];
1223 }
1224 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1225 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001226}
1227
1228static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1229 u8 *data)
1230{
1231 struct i40e_netdev_priv *np = netdev_priv(netdev);
1232 struct i40e_vsi *vsi = np->vsi;
1233 struct i40e_pf *pf = vsi->back;
1234 char *p = (char *)data;
1235 int i;
1236
1237 switch (stringset) {
1238 case ETH_SS_TEST:
1239 for (i = 0; i < I40E_TEST_LEN; i++) {
1240 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1241 data += ETH_GSTRING_LEN;
1242 }
1243 break;
1244 case ETH_SS_STATS:
1245 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1246 snprintf(p, ETH_GSTRING_LEN, "%s",
1247 i40e_gstrings_net_stats[i].stat_string);
1248 p += ETH_GSTRING_LEN;
1249 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001250 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1251 snprintf(p, ETH_GSTRING_LEN, "%s",
1252 i40e_gstrings_misc_stats[i].stat_string);
1253 p += ETH_GSTRING_LEN;
1254 }
Vasu Dev38e00432014-08-01 13:27:03 -07001255#ifdef I40E_FCOE
1256 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1257 snprintf(p, ETH_GSTRING_LEN, "%s",
1258 i40e_gstrings_fcoe_stats[i].stat_string);
1259 p += ETH_GSTRING_LEN;
1260 }
1261#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001262 for (i = 0; i < vsi->num_queue_pairs; i++) {
1263 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1264 p += ETH_GSTRING_LEN;
1265 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1266 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001267 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1268 p += ETH_GSTRING_LEN;
1269 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1270 p += ETH_GSTRING_LEN;
1271 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001272 if (vsi != pf->vsi[pf->lan_vsi])
1273 return;
1274
1275 if (pf->lan_veb != I40E_NO_VEB) {
1276 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1277 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1278 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001279 p += ETH_GSTRING_LEN;
1280 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001281 }
1282 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1283 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1284 i40e_gstrings_stats[i].stat_string);
1285 p += ETH_GSTRING_LEN;
1286 }
1287 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1288 snprintf(p, ETH_GSTRING_LEN,
1289 "port.tx_priority_%u_xon", i);
1290 p += ETH_GSTRING_LEN;
1291 snprintf(p, ETH_GSTRING_LEN,
1292 "port.tx_priority_%u_xoff", i);
1293 p += ETH_GSTRING_LEN;
1294 }
1295 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1296 snprintf(p, ETH_GSTRING_LEN,
1297 "port.rx_priority_%u_xon", i);
1298 p += ETH_GSTRING_LEN;
1299 snprintf(p, ETH_GSTRING_LEN,
1300 "port.rx_priority_%u_xoff", i);
1301 p += ETH_GSTRING_LEN;
1302 }
1303 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1304 snprintf(p, ETH_GSTRING_LEN,
1305 "port.rx_priority_%u_xon_2_xoff", i);
1306 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001307 }
1308 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1309 break;
1310 }
1311}
1312
1313static int i40e_get_ts_info(struct net_device *dev,
1314 struct ethtool_ts_info *info)
1315{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001316 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1317
1318 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1319 SOF_TIMESTAMPING_RX_SOFTWARE |
1320 SOF_TIMESTAMPING_SOFTWARE |
1321 SOF_TIMESTAMPING_TX_HARDWARE |
1322 SOF_TIMESTAMPING_RX_HARDWARE |
1323 SOF_TIMESTAMPING_RAW_HARDWARE;
1324
1325 if (pf->ptp_clock)
1326 info->phc_index = ptp_clock_index(pf->ptp_clock);
1327 else
1328 info->phc_index = -1;
1329
1330 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1331
1332 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1333 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1334 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1335 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1336 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1337 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1338 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1339 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1340 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1341 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1342 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1343 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1344
1345 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001346}
1347
Shannon Nelson7b086392013-11-20 10:02:59 +00001348static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001349{
Shannon Nelson7b086392013-11-20 10:02:59 +00001350 struct i40e_netdev_priv *np = netdev_priv(netdev);
1351 struct i40e_pf *pf = np->vsi->back;
1352
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001353 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001354 if (i40e_get_link_status(&pf->hw))
1355 *data = 0;
1356 else
1357 *data = 1;
1358
1359 return *data;
1360}
1361
Shannon Nelson7b086392013-11-20 10:02:59 +00001362static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001363{
Shannon Nelson7b086392013-11-20 10:02:59 +00001364 struct i40e_netdev_priv *np = netdev_priv(netdev);
1365 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001366
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001367 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001368 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001369
Shannon Nelson7b086392013-11-20 10:02:59 +00001370 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001371}
1372
Shannon Nelson7b086392013-11-20 10:02:59 +00001373static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001374{
Shannon Nelson7b086392013-11-20 10:02:59 +00001375 struct i40e_netdev_priv *np = netdev_priv(netdev);
1376 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001377
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001378 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001379 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001380
Shannon Nelson7b086392013-11-20 10:02:59 +00001381 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001382}
1383
Shannon Nelson7b086392013-11-20 10:02:59 +00001384static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001385{
Shannon Nelson7b086392013-11-20 10:02:59 +00001386 struct i40e_netdev_priv *np = netdev_priv(netdev);
1387 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001388 u16 swc_old = pf->sw_int_count;
1389
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001390 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001391 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1392 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
1393 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
1394 usleep_range(1000, 2000);
1395 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001396
1397 return *data;
1398}
1399
Shannon Nelson7b086392013-11-20 10:02:59 +00001400static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001401{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001402 struct i40e_netdev_priv *np = netdev_priv(netdev);
1403 struct i40e_pf *pf = np->vsi->back;
1404
1405 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001406 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001407
1408 return *data;
1409}
1410
1411static void i40e_diag_test(struct net_device *netdev,
1412 struct ethtool_test *eth_test, u64 *data)
1413{
1414 struct i40e_netdev_priv *np = netdev_priv(netdev);
1415 struct i40e_pf *pf = np->vsi->back;
1416
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001417 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1418 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001419 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001420
Shannon Nelsonf551b432013-11-26 10:49:12 +00001421 set_bit(__I40E_TESTING, &pf->state);
1422
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001423 /* Link test performed before hardware reset
1424 * so autoneg doesn't interfere with test result
1425 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001426 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001427 eth_test->flags |= ETH_TEST_FL_FAILED;
1428
Shannon Nelson7b086392013-11-20 10:02:59 +00001429 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001430 eth_test->flags |= ETH_TEST_FL_FAILED;
1431
Shannon Nelson7b086392013-11-20 10:02:59 +00001432 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001433 eth_test->flags |= ETH_TEST_FL_FAILED;
1434
Shannon Nelson7b086392013-11-20 10:02:59 +00001435 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001436 eth_test->flags |= ETH_TEST_FL_FAILED;
1437
Shannon Nelsonf551b432013-11-26 10:49:12 +00001438 /* run reg test last, a reset is required after it */
1439 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1440 eth_test->flags |= ETH_TEST_FL_FAILED;
1441
1442 clear_bit(__I40E_TESTING, &pf->state);
1443 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001444 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001445 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001446 netif_info(pf, drv, netdev, "online testing starting\n");
1447
Shannon Nelson7b086392013-11-20 10:02:59 +00001448 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001449 eth_test->flags |= ETH_TEST_FL_FAILED;
1450
1451 /* Offline only tests, not run in online; pass by default */
1452 data[I40E_ETH_TEST_REG] = 0;
1453 data[I40E_ETH_TEST_EEPROM] = 0;
1454 data[I40E_ETH_TEST_INTR] = 0;
1455 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001456 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001457
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001458 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001459}
1460
1461static void i40e_get_wol(struct net_device *netdev,
1462 struct ethtool_wolinfo *wol)
1463{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001464 struct i40e_netdev_priv *np = netdev_priv(netdev);
1465 struct i40e_pf *pf = np->vsi->back;
1466 struct i40e_hw *hw = &pf->hw;
1467 u16 wol_nvm_bits;
1468
1469 /* NVM bit on means WoL disabled for the port */
1470 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1471 if ((1 << hw->port) & wol_nvm_bits) {
1472 wol->supported = 0;
1473 wol->wolopts = 0;
1474 } else {
1475 wol->supported = WAKE_MAGIC;
1476 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1477 }
1478}
1479
1480static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1481{
1482 struct i40e_netdev_priv *np = netdev_priv(netdev);
1483 struct i40e_pf *pf = np->vsi->back;
1484 struct i40e_hw *hw = &pf->hw;
1485 u16 wol_nvm_bits;
1486
1487 /* NVM bit on means WoL disabled for the port */
1488 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1489 if (((1 << hw->port) & wol_nvm_bits))
1490 return -EOPNOTSUPP;
1491
1492 /* only magic packet is supported */
1493 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1494 return -EOPNOTSUPP;
1495
1496 /* is this a new value? */
1497 if (pf->wol_en != !!wol->wolopts) {
1498 pf->wol_en = !!wol->wolopts;
1499 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1500 }
1501
1502 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001503}
1504
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001505static int i40e_set_phys_id(struct net_device *netdev,
1506 enum ethtool_phys_id_state state)
1507{
1508 struct i40e_netdev_priv *np = netdev_priv(netdev);
1509 struct i40e_pf *pf = np->vsi->back;
1510 struct i40e_hw *hw = &pf->hw;
1511 int blink_freq = 2;
1512
1513 switch (state) {
1514 case ETHTOOL_ID_ACTIVE:
1515 pf->led_status = i40e_led_get(hw);
1516 return blink_freq;
1517 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001518 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001519 break;
1520 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001521 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001522 break;
1523 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001524 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001525 break;
1526 }
1527
1528 return 0;
1529}
1530
1531/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1532 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1533 * 125us (8000 interrupts per second) == ITR(62)
1534 */
1535
1536static int i40e_get_coalesce(struct net_device *netdev,
1537 struct ethtool_coalesce *ec)
1538{
1539 struct i40e_netdev_priv *np = netdev_priv(netdev);
1540 struct i40e_vsi *vsi = np->vsi;
1541
1542 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1543 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1544
1545 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001546 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001547
1548 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001549 ec->use_adaptive_tx_coalesce = 1;
1550
1551 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1552 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001553
1554 return 0;
1555}
1556
1557static int i40e_set_coalesce(struct net_device *netdev,
1558 struct ethtool_coalesce *ec)
1559{
1560 struct i40e_netdev_priv *np = netdev_priv(netdev);
1561 struct i40e_q_vector *q_vector;
1562 struct i40e_vsi *vsi = np->vsi;
1563 struct i40e_pf *pf = vsi->back;
1564 struct i40e_hw *hw = &pf->hw;
1565 u16 vector;
1566 int i;
1567
1568 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1569 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1570
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001571 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001572 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001573 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001574 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001575 } else if (ec->rx_coalesce_usecs == 0) {
1576 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001577 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001578 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 +00001579 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001580 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001581 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001582 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001583
Mitch Williams32f5f542014-04-04 04:43:10 +00001584 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001585 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001586 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001587 } else if (ec->tx_coalesce_usecs == 0) {
1588 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001589 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001590 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 +00001591 } else {
1592 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001593 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001594 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001595 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001596
1597 if (ec->use_adaptive_rx_coalesce)
1598 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1599 else
1600 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1601
1602 if (ec->use_adaptive_tx_coalesce)
1603 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1604 else
1605 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001606
Alexander Duyck493fb302013-09-28 07:01:44 +00001607 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1608 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001609 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1610 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1611 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1612 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1613 i40e_flush(hw);
1614 }
1615
1616 return 0;
1617}
1618
1619/**
1620 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1621 * @pf: pointer to the physical function struct
1622 * @cmd: ethtool rxnfc command
1623 *
1624 * Returns Success if the flow is supported, else Invalid Input.
1625 **/
1626static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1627{
1628 cmd->data = 0;
1629
1630 /* Report default options for RSS on i40e */
1631 switch (cmd->flow_type) {
1632 case TCP_V4_FLOW:
1633 case UDP_V4_FLOW:
1634 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1635 /* fall through to add IP fields */
1636 case SCTP_V4_FLOW:
1637 case AH_ESP_V4_FLOW:
1638 case AH_V4_FLOW:
1639 case ESP_V4_FLOW:
1640 case IPV4_FLOW:
1641 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1642 break;
1643 case TCP_V6_FLOW:
1644 case UDP_V6_FLOW:
1645 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1646 /* fall through to add IP fields */
1647 case SCTP_V6_FLOW:
1648 case AH_ESP_V6_FLOW:
1649 case AH_V6_FLOW:
1650 case ESP_V6_FLOW:
1651 case IPV6_FLOW:
1652 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1653 break;
1654 default:
1655 return -EINVAL;
1656 }
1657
1658 return 0;
1659}
1660
1661/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001662 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1663 * @pf: Pointer to the physical function struct
1664 * @cmd: The command to get or set Rx flow classification rules
1665 * @rule_locs: Array of used rule locations
1666 *
1667 * This function populates both the total and actual rule count of
1668 * the ethtool flow classification command
1669 *
1670 * Returns 0 on success or -EMSGSIZE if entry not found
1671 **/
1672static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1673 struct ethtool_rxnfc *cmd,
1674 u32 *rule_locs)
1675{
1676 struct i40e_fdir_filter *rule;
1677 struct hlist_node *node2;
1678 int cnt = 0;
1679
1680 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001681 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001682
1683 hlist_for_each_entry_safe(rule, node2,
1684 &pf->fdir_filter_list, fdir_node) {
1685 if (cnt == cmd->rule_cnt)
1686 return -EMSGSIZE;
1687
1688 rule_locs[cnt] = rule->fd_id;
1689 cnt++;
1690 }
1691
1692 cmd->rule_cnt = cnt;
1693
1694 return 0;
1695}
1696
1697/**
1698 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1699 * @pf: Pointer to the physical function struct
1700 * @cmd: The command to get or set Rx flow classification rules
1701 *
1702 * This function looks up a filter based on the Rx flow classification
1703 * command and fills the flow spec info for it if found
1704 *
1705 * Returns 0 on success or -EINVAL if filter not found
1706 **/
1707static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1708 struct ethtool_rxnfc *cmd)
1709{
1710 struct ethtool_rx_flow_spec *fsp =
1711 (struct ethtool_rx_flow_spec *)&cmd->fs;
1712 struct i40e_fdir_filter *rule = NULL;
1713 struct hlist_node *node2;
1714
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001715 hlist_for_each_entry_safe(rule, node2,
1716 &pf->fdir_filter_list, fdir_node) {
1717 if (fsp->location <= rule->fd_id)
1718 break;
1719 }
1720
1721 if (!rule || fsp->location != rule->fd_id)
1722 return -EINVAL;
1723
1724 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001725 if (fsp->flow_type == IP_USER_FLOW) {
1726 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1727 fsp->h_u.usr_ip4_spec.proto = 0;
1728 fsp->m_u.usr_ip4_spec.proto = 0;
1729 }
1730
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001731 /* Reverse the src and dest notion, since the HW views them from
1732 * Tx perspective where as the user expects it from Rx filter view.
1733 */
1734 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1735 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1736 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1737 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001738
1739 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1740 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1741 else
1742 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001743
1744 return 0;
1745}
1746
1747/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001748 * i40e_get_rxnfc - command to get RX flow classification rules
1749 * @netdev: network interface device structure
1750 * @cmd: ethtool rxnfc command
1751 *
1752 * Returns Success if the command is supported.
1753 **/
1754static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1755 u32 *rule_locs)
1756{
1757 struct i40e_netdev_priv *np = netdev_priv(netdev);
1758 struct i40e_vsi *vsi = np->vsi;
1759 struct i40e_pf *pf = vsi->back;
1760 int ret = -EOPNOTSUPP;
1761
1762 switch (cmd->cmd) {
1763 case ETHTOOL_GRXRINGS:
1764 cmd->data = vsi->alloc_queue_pairs;
1765 ret = 0;
1766 break;
1767 case ETHTOOL_GRXFH:
1768 ret = i40e_get_rss_hash_opts(pf, cmd);
1769 break;
1770 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001771 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001772 /* report total rule count */
1773 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001774 ret = 0;
1775 break;
1776 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001777 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001778 break;
1779 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001780 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1781 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001782 default:
1783 break;
1784 }
1785
1786 return ret;
1787}
1788
1789/**
1790 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1791 * @pf: pointer to the physical function struct
1792 * @cmd: ethtool rxnfc command
1793 *
1794 * Returns Success if the flow input set is supported.
1795 **/
1796static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1797{
1798 struct i40e_hw *hw = &pf->hw;
1799 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1800 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1801
1802 /* RSS does not support anything other than hashing
1803 * to queues on src and dst IPs and ports
1804 */
1805 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1806 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1807 return -EINVAL;
1808
1809 /* We need at least the IP SRC and DEST fields for hashing */
1810 if (!(nfc->data & RXH_IP_SRC) ||
1811 !(nfc->data & RXH_IP_DST))
1812 return -EINVAL;
1813
1814 switch (nfc->flow_type) {
1815 case TCP_V4_FLOW:
1816 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1817 case 0:
1818 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1819 break;
1820 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1821 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1822 break;
1823 default:
1824 return -EINVAL;
1825 }
1826 break;
1827 case TCP_V6_FLOW:
1828 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1829 case 0:
1830 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1831 break;
1832 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1833 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1834 break;
1835 default:
1836 return -EINVAL;
1837 }
1838 break;
1839 case UDP_V4_FLOW:
1840 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1841 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001842 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1843 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001844 break;
1845 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001846 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1847 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001848 break;
1849 default:
1850 return -EINVAL;
1851 }
1852 break;
1853 case UDP_V6_FLOW:
1854 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1855 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001856 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1857 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001858 break;
1859 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001860 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1861 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001862 break;
1863 default:
1864 return -EINVAL;
1865 }
1866 break;
1867 case AH_ESP_V4_FLOW:
1868 case AH_V4_FLOW:
1869 case ESP_V4_FLOW:
1870 case SCTP_V4_FLOW:
1871 if ((nfc->data & RXH_L4_B_0_1) ||
1872 (nfc->data & RXH_L4_B_2_3))
1873 return -EINVAL;
1874 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1875 break;
1876 case AH_ESP_V6_FLOW:
1877 case AH_V6_FLOW:
1878 case ESP_V6_FLOW:
1879 case SCTP_V6_FLOW:
1880 if ((nfc->data & RXH_L4_B_0_1) ||
1881 (nfc->data & RXH_L4_B_2_3))
1882 return -EINVAL;
1883 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1884 break;
1885 case IPV4_FLOW:
1886 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1887 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1888 break;
1889 case IPV6_FLOW:
1890 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1891 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1892 break;
1893 default:
1894 return -EINVAL;
1895 }
1896
1897 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1898 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1899 i40e_flush(hw);
1900
1901 return 0;
1902}
1903
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001904/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001905 * i40e_match_fdir_input_set - Match a new filter against an existing one
1906 * @rule: The filter already added
1907 * @input: The new filter to comapre against
1908 *
1909 * Returns true if the two input set match
1910 **/
1911static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1912 struct i40e_fdir_filter *input)
1913{
1914 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1915 (rule->src_ip[0] != input->src_ip[0]) ||
1916 (rule->dst_port != input->dst_port) ||
1917 (rule->src_port != input->src_port))
1918 return false;
1919 return true;
1920}
1921
1922/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001923 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1924 * @vsi: Pointer to the targeted VSI
1925 * @input: The filter to update or NULL to indicate deletion
1926 * @sw_idx: Software index to the filter
1927 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001928 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001929 * This function updates (or deletes) a Flow Director entry from
1930 * the hlist of the corresponding PF
1931 *
1932 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001933 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001934static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1935 struct i40e_fdir_filter *input,
1936 u16 sw_idx,
1937 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001938{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001939 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001940 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001941 struct hlist_node *node2;
1942 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001943
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001944 parent = NULL;
1945 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001946
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001947 hlist_for_each_entry_safe(rule, node2,
1948 &pf->fdir_filter_list, fdir_node) {
1949 /* hash found, or no matching entry */
1950 if (rule->fd_id >= sw_idx)
1951 break;
1952 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001953 }
1954
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001955 /* if there is an old rule occupying our place remove it */
1956 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001957 if (input && !i40e_match_fdir_input_set(rule, input))
1958 err = i40e_add_del_fdir(vsi, rule, false);
1959 else if (!input)
1960 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001961 hlist_del(&rule->fdir_node);
1962 kfree(rule);
1963 pf->fdir_pf_active_filters--;
1964 }
1965
1966 /* If no input this was a delete, err should be 0 if a rule was
1967 * successfully found and removed from the list else -EINVAL
1968 */
1969 if (!input)
1970 return err;
1971
1972 /* initialize node and set software index */
1973 INIT_HLIST_NODE(&input->fdir_node);
1974
1975 /* add filter to the list */
1976 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07001977 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001978 else
1979 hlist_add_head(&input->fdir_node,
1980 &pf->fdir_filter_list);
1981
1982 /* update counts */
1983 pf->fdir_pf_active_filters++;
1984
1985 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001986}
1987
1988/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001989 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
1990 * @vsi: Pointer to the targeted VSI
1991 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001992 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001993 * The function removes a Flow Director filter entry from the
1994 * hlist of the corresponding PF
1995 *
1996 * Returns 0 on success
1997 */
1998static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
1999 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002000{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002001 struct ethtool_rx_flow_spec *fsp =
2002 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002003 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002004 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002005
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002006 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2007 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2008 return -EBUSY;
2009
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002010 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2011 return -EBUSY;
2012
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002013 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002014
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002015 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002016 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002017}
2018
2019/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002020 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002021 * @vsi: pointer to the targeted VSI
2022 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002023 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002024 * Add Flow Director filters for a specific flow spec based on their
2025 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002026 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002027static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2028 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002029{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002030 struct ethtool_rx_flow_spec *fsp;
2031 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002032 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002033 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002034
2035 if (!vsi)
2036 return -EINVAL;
2037
2038 pf = vsi->back;
2039
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002040 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2041 return -EOPNOTSUPP;
2042
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002043 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002044 return -ENOSPC;
2045
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002046 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2047 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2048 return -EBUSY;
2049
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002050 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2051 return -EBUSY;
2052
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002053 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2054
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002055 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2056 pf->hw.func_caps.fd_filters_guaranteed)) {
2057 return -EINVAL;
2058 }
2059
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002060 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2061 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002062 return -EINVAL;
2063
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002064 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002065
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002066 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002067 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002068
2069 input->fd_id = fsp->location;
2070
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002071 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2072 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2073 else
2074 input->dest_ctl =
2075 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2076
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002077 input->q_index = fsp->ring_cookie;
2078 input->flex_off = 0;
2079 input->pctype = 0;
2080 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002081 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00002082 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002083 input->flow_type = fsp->flow_type;
2084 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002085
2086 /* Reverse the src and dest notion, since the HW expects them to be from
2087 * Tx perspective where as the input from user is from Rx filter view.
2088 */
2089 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2090 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2091 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2092 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002093
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002094 ret = i40e_add_del_fdir(vsi, input, true);
2095 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002096 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002097 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002098 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002099
2100 return ret;
2101}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002102
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002103/**
2104 * i40e_set_rxnfc - command to set RX flow classification rules
2105 * @netdev: network interface device structure
2106 * @cmd: ethtool rxnfc command
2107 *
2108 * Returns Success if the command is supported.
2109 **/
2110static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2111{
2112 struct i40e_netdev_priv *np = netdev_priv(netdev);
2113 struct i40e_vsi *vsi = np->vsi;
2114 struct i40e_pf *pf = vsi->back;
2115 int ret = -EOPNOTSUPP;
2116
2117 switch (cmd->cmd) {
2118 case ETHTOOL_SRXFH:
2119 ret = i40e_set_rss_hash_opt(pf, cmd);
2120 break;
2121 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002122 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002123 break;
2124 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002125 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002126 break;
2127 default:
2128 break;
2129 }
2130
2131 return ret;
2132}
2133
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002134/**
2135 * i40e_max_channels - get Max number of combined channels supported
2136 * @vsi: vsi pointer
2137 **/
2138static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2139{
2140 /* TODO: This code assumes DCB and FD is disabled for now. */
2141 return vsi->alloc_queue_pairs;
2142}
2143
2144/**
2145 * i40e_get_channels - Get the current channels enabled and max supported etc.
2146 * @netdev: network interface device structure
2147 * @ch: ethtool channels structure
2148 *
2149 * We don't support separate tx and rx queues as channels. The other count
2150 * represents how many queues are being used for control. max_combined counts
2151 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2152 * q_vectors since we support a lot more queue pairs than q_vectors.
2153 **/
2154static void i40e_get_channels(struct net_device *dev,
2155 struct ethtool_channels *ch)
2156{
2157 struct i40e_netdev_priv *np = netdev_priv(dev);
2158 struct i40e_vsi *vsi = np->vsi;
2159 struct i40e_pf *pf = vsi->back;
2160
2161 /* report maximum channels */
2162 ch->max_combined = i40e_max_channels(vsi);
2163
2164 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002165 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002166 ch->max_other = ch->other_count;
2167
2168 /* Note: This code assumes DCB is disabled for now. */
2169 ch->combined_count = vsi->num_queue_pairs;
2170}
2171
2172/**
2173 * i40e_set_channels - Set the new channels count.
2174 * @netdev: network interface device structure
2175 * @ch: ethtool channels structure
2176 *
2177 * The new channels count may not be the same as requested by the user
2178 * since it gets rounded down to a power of 2 value.
2179 **/
2180static int i40e_set_channels(struct net_device *dev,
2181 struct ethtool_channels *ch)
2182{
2183 struct i40e_netdev_priv *np = netdev_priv(dev);
2184 unsigned int count = ch->combined_count;
2185 struct i40e_vsi *vsi = np->vsi;
2186 struct i40e_pf *pf = vsi->back;
2187 int new_count;
2188
2189 /* We do not support setting channels for any other VSI at present */
2190 if (vsi->type != I40E_VSI_MAIN)
2191 return -EINVAL;
2192
2193 /* verify they are not requesting separate vectors */
2194 if (!count || ch->rx_count || ch->tx_count)
2195 return -EINVAL;
2196
2197 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002198 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002199 return -EINVAL;
2200
2201 /* verify the number of channels does not exceed hardware limits */
2202 if (count > i40e_max_channels(vsi))
2203 return -EINVAL;
2204
2205 /* update feature limits from largest to smallest supported values */
2206 /* TODO: Flow director limit, DCB etc */
2207
2208 /* cap RSS limit */
2209 if (count > pf->rss_size_max)
2210 count = pf->rss_size_max;
2211
2212 /* use rss_reconfig to rebuild with new queue count and update traffic
2213 * class queue mapping
2214 */
2215 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002216 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002217 return 0;
2218 else
2219 return -EINVAL;
2220}
2221
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002222static const struct ethtool_ops i40e_ethtool_ops = {
2223 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002224 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002225 .get_drvinfo = i40e_get_drvinfo,
2226 .get_regs_len = i40e_get_regs_len,
2227 .get_regs = i40e_get_regs,
2228 .nway_reset = i40e_nway_reset,
2229 .get_link = ethtool_op_get_link,
2230 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002231 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002232 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002233 .get_eeprom_len = i40e_get_eeprom_len,
2234 .get_eeprom = i40e_get_eeprom,
2235 .get_ringparam = i40e_get_ringparam,
2236 .set_ringparam = i40e_set_ringparam,
2237 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002238 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002239 .get_msglevel = i40e_get_msglevel,
2240 .set_msglevel = i40e_set_msglevel,
2241 .get_rxnfc = i40e_get_rxnfc,
2242 .set_rxnfc = i40e_set_rxnfc,
2243 .self_test = i40e_diag_test,
2244 .get_strings = i40e_get_strings,
2245 .set_phys_id = i40e_set_phys_id,
2246 .get_sset_count = i40e_get_sset_count,
2247 .get_ethtool_stats = i40e_get_ethtool_stats,
2248 .get_coalesce = i40e_get_coalesce,
2249 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002250 .get_channels = i40e_get_channels,
2251 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002252 .get_ts_info = i40e_get_ts_info,
2253};
2254
2255void i40e_set_ethtool_ops(struct net_device *netdev)
2256{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002257 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002258}