blob: 9c93ff28d4aab24ab8062561fe34e6fb38db154f [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 Jain433c47d2014-05-22 06:32:17 +0000148 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
149 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
150
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000151 /* LPI stats */
152 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
153 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
154 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
155 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000156};
157
158#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000159 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
160 * 2 /* Tx and Rx together */ \
161 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000162#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
163#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000164#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000165#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000166 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000167 I40E_QUEUE_STATS_LEN((n)))
168#define I40E_PFC_STATS_LEN ( \
169 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
170 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
171 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
172 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
173 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
174 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000175#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000176#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
177 I40E_PFC_STATS_LEN + \
178 I40E_VSI_STATS_LEN((n)))
179
180enum i40e_ethtool_test_id {
181 I40E_ETH_TEST_REG = 0,
182 I40E_ETH_TEST_EEPROM,
183 I40E_ETH_TEST_INTR,
184 I40E_ETH_TEST_LOOPBACK,
185 I40E_ETH_TEST_LINK,
186};
187
188static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
189 "Register test (offline)",
190 "Eeprom test (offline)",
191 "Interrupt test (offline)",
192 "Loopback test (offline)",
193 "Link test (on/offline)"
194};
195
196#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
197
198/**
199 * i40e_get_settings - Get Link Speed and Duplex settings
200 * @netdev: network interface device structure
201 * @ecmd: ethtool command
202 *
203 * Reports speed/duplex settings based on media_type
204 **/
205static int i40e_get_settings(struct net_device *netdev,
206 struct ethtool_cmd *ecmd)
207{
208 struct i40e_netdev_priv *np = netdev_priv(netdev);
209 struct i40e_pf *pf = np->vsi->back;
210 struct i40e_hw *hw = &pf->hw;
211 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
212 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
213 u32 link_speed = hw_link_info->link_speed;
214
215 /* hardware is either in 40G mode or 10G mode
216 * NOTE: this section initializes supported and advertising
217 */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000218 if (!link_up) {
219 /* link is down and the driver needs to fall back on
220 * device ID to determine what kinds of info to display,
221 * it's mostly a guess that may change when link is up
222 */
223 switch (hw->device_id) {
224 case I40E_DEV_ID_QSFP_A:
225 case I40E_DEV_ID_QSFP_B:
226 case I40E_DEV_ID_QSFP_C:
227 /* pluggable QSFP */
228 ecmd->supported = SUPPORTED_40000baseSR4_Full |
229 SUPPORTED_40000baseCR4_Full |
230 SUPPORTED_40000baseLR4_Full;
231 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
232 ADVERTISED_40000baseCR4_Full |
233 ADVERTISED_40000baseLR4_Full;
234 break;
235 case I40E_DEV_ID_KX_B:
236 /* backplane 40G */
237 ecmd->supported = SUPPORTED_40000baseKR4_Full;
238 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
239 break;
240 case I40E_DEV_ID_KX_C:
241 /* backplane 10G */
242 ecmd->supported = SUPPORTED_10000baseKR_Full;
243 ecmd->advertising = ADVERTISED_10000baseKR_Full;
244 break;
245 default:
246 /* all the rest are 10G/1G */
247 ecmd->supported = SUPPORTED_10000baseT_Full |
248 SUPPORTED_1000baseT_Full;
249 ecmd->advertising = ADVERTISED_10000baseT_Full |
250 ADVERTISED_1000baseT_Full;
251 break;
252 }
253
254 /* skip phy_type use as it is zero when link is down */
255 goto no_valid_phy_type;
256 }
257
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000258 switch (hw_link_info->phy_type) {
259 case I40E_PHY_TYPE_40GBASE_CR4:
260 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000261 ecmd->supported = SUPPORTED_Autoneg |
262 SUPPORTED_40000baseCR4_Full;
263 ecmd->advertising = ADVERTISED_Autoneg |
264 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000265 break;
266 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000267 ecmd->supported = SUPPORTED_Autoneg |
268 SUPPORTED_40000baseKR4_Full;
269 ecmd->advertising = ADVERTISED_Autoneg |
270 ADVERTISED_40000baseKR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000271 break;
272 case I40E_PHY_TYPE_40GBASE_SR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000273 case I40E_PHY_TYPE_XLPPI:
274 case I40E_PHY_TYPE_XLAUI:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000275 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000276 break;
277 case I40E_PHY_TYPE_40GBASE_LR4:
278 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000279 break;
280 case I40E_PHY_TYPE_10GBASE_KX4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000281 ecmd->supported = SUPPORTED_Autoneg |
282 SUPPORTED_10000baseKX4_Full;
283 ecmd->advertising = ADVERTISED_Autoneg |
284 ADVERTISED_10000baseKX4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000285 break;
286 case I40E_PHY_TYPE_10GBASE_KR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000287 ecmd->supported = SUPPORTED_Autoneg |
288 SUPPORTED_10000baseKR_Full;
289 ecmd->advertising = ADVERTISED_Autoneg |
290 ADVERTISED_10000baseKR_Full;
291 break;
292 case I40E_PHY_TYPE_10GBASE_SR:
293 case I40E_PHY_TYPE_10GBASE_LR:
294 ecmd->supported = SUPPORTED_10000baseT_Full;
295 break;
296 case I40E_PHY_TYPE_10GBASE_CR1_CU:
297 case I40E_PHY_TYPE_10GBASE_CR1:
298 case I40E_PHY_TYPE_10GBASE_T:
299 ecmd->supported = SUPPORTED_Autoneg |
300 SUPPORTED_10000baseT_Full;
301 ecmd->advertising = ADVERTISED_Autoneg |
302 ADVERTISED_10000baseT_Full;
303 break;
304 case I40E_PHY_TYPE_XAUI:
305 case I40E_PHY_TYPE_XFI:
306 case I40E_PHY_TYPE_SFI:
307 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
308 ecmd->supported = SUPPORTED_10000baseT_Full;
309 break;
310 case I40E_PHY_TYPE_1000BASE_KX:
311 case I40E_PHY_TYPE_1000BASE_T:
312 ecmd->supported = SUPPORTED_Autoneg |
313 SUPPORTED_1000baseT_Full;
314 ecmd->advertising = ADVERTISED_Autoneg |
315 ADVERTISED_1000baseT_Full;
316 break;
317 case I40E_PHY_TYPE_100BASE_TX:
318 ecmd->supported = SUPPORTED_Autoneg |
319 SUPPORTED_100baseT_Full;
320 ecmd->advertising = ADVERTISED_Autoneg |
321 ADVERTISED_100baseT_Full;
322 break;
323 case I40E_PHY_TYPE_SGMII:
324 ecmd->supported = SUPPORTED_Autoneg |
325 SUPPORTED_1000baseT_Full |
326 SUPPORTED_100baseT_Full;
327 ecmd->advertising = ADVERTISED_Autoneg |
328 ADVERTISED_1000baseT_Full |
329 ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000330 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000331 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000332 /* if we got here and link is up something bad is afoot */
333 WARN_ON(link_up);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000334 }
335
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000336no_valid_phy_type:
337 /* this is if autoneg is enabled or disabled */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000338 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
339 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000340
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000341 switch (hw->phy.media_type) {
342 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000343 ecmd->supported |= SUPPORTED_Autoneg |
344 SUPPORTED_Backplane;
345 ecmd->advertising |= ADVERTISED_Autoneg |
346 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000347 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000348 break;
349 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000350 ecmd->supported |= SUPPORTED_TP;
351 ecmd->advertising |= ADVERTISED_TP;
352 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000353 break;
354 case I40E_MEDIA_TYPE_DA:
355 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000356 ecmd->supported |= SUPPORTED_FIBRE;
357 ecmd->advertising |= ADVERTISED_FIBRE;
358 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000359 break;
360 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000361 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000362 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000363 break;
364 case I40E_MEDIA_TYPE_UNKNOWN:
365 default:
366 ecmd->port = PORT_OTHER;
367 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000368 }
369
370 ecmd->transceiver = XCVR_EXTERNAL;
371
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000372 ecmd->supported |= SUPPORTED_Pause;
373
374 switch (hw->fc.current_mode) {
375 case I40E_FC_FULL:
376 ecmd->advertising |= ADVERTISED_Pause;
377 break;
378 case I40E_FC_TX_PAUSE:
379 ecmd->advertising |= ADVERTISED_Asym_Pause;
380 break;
381 case I40E_FC_RX_PAUSE:
382 ecmd->advertising |= (ADVERTISED_Pause |
383 ADVERTISED_Asym_Pause);
384 break;
385 default:
386 ecmd->advertising &= ~(ADVERTISED_Pause |
387 ADVERTISED_Asym_Pause);
388 break;
389 }
390
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000391 if (link_up) {
392 switch (link_speed) {
393 case I40E_LINK_SPEED_40GB:
394 /* need a SPEED_40000 in ethtool.h */
395 ethtool_cmd_speed_set(ecmd, 40000);
396 break;
397 case I40E_LINK_SPEED_10GB:
398 ethtool_cmd_speed_set(ecmd, SPEED_10000);
399 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000400 case I40E_LINK_SPEED_1GB:
401 ethtool_cmd_speed_set(ecmd, SPEED_1000);
402 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000403 default:
404 break;
405 }
406 ecmd->duplex = DUPLEX_FULL;
407 } else {
408 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
409 ecmd->duplex = DUPLEX_UNKNOWN;
410 }
411
412 return 0;
413}
414
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000415/**
416 * i40e_set_settings - Set Speed and Duplex
417 * @netdev: network interface device structure
418 * @ecmd: ethtool command
419 *
420 * Set speed/duplex per media_types advertised/forced
421 **/
422static int i40e_set_settings(struct net_device *netdev,
423 struct ethtool_cmd *ecmd)
424{
425 struct i40e_netdev_priv *np = netdev_priv(netdev);
426 struct i40e_aq_get_phy_abilities_resp abilities;
427 struct i40e_aq_set_phy_config config;
428 struct i40e_pf *pf = np->vsi->back;
429 struct i40e_vsi *vsi = np->vsi;
430 struct i40e_hw *hw = &pf->hw;
431 struct ethtool_cmd safe_ecmd;
432 i40e_status status = 0;
433 bool change = false;
434 int err = 0;
435 u8 autoneg;
436 u32 advertise;
437
438 if (vsi != pf->vsi[pf->lan_vsi])
439 return -EOPNOTSUPP;
440
441 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
442 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
443 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE)
444 return -EOPNOTSUPP;
445
446 /* get our own copy of the bits to check against */
447 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
448 i40e_get_settings(netdev, &safe_ecmd);
449
450 /* save autoneg and speed out of ecmd */
451 autoneg = ecmd->autoneg;
452 advertise = ecmd->advertising;
453
454 /* set autoneg and speed back to what they currently are */
455 ecmd->autoneg = safe_ecmd.autoneg;
456 ecmd->advertising = safe_ecmd.advertising;
457
458 ecmd->cmd = safe_ecmd.cmd;
459 /* If ecmd and safe_ecmd are not the same now, then they are
460 * trying to set something that we do not support
461 */
462 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
463 return -EOPNOTSUPP;
464
465 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
466 usleep_range(1000, 2000);
467
468 /* Get the current phy config */
469 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
470 NULL);
471 if (status)
472 return -EAGAIN;
473
474 /* Copy link_speed and abilities to config in case they are not
475 * set below
476 */
477 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
478 config.link_speed = abilities.link_speed;
479 config.abilities = abilities.abilities;
480
481 /* Check autoneg */
482 if (autoneg == AUTONEG_ENABLE) {
483 /* If autoneg is not supported, return error */
484 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
485 netdev_info(netdev, "Autoneg not supported on this phy\n");
486 return -EINVAL;
487 }
488 /* If autoneg was not already enabled */
489 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
490 config.abilities = abilities.abilities |
491 I40E_AQ_PHY_ENABLE_AN;
492 change = true;
493 }
494 } else {
495 /* If autoneg is supported 10GBASE_T is the only phy that
496 * can disable it, so otherwise return error
497 */
498 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
499 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
500 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
501 return -EINVAL;
502 }
503 /* If autoneg is currently enabled */
504 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
505 config.abilities = abilities.abilities |
506 ~I40E_AQ_PHY_ENABLE_AN;
507 change = true;
508 }
509 }
510
511 if (advertise & ~safe_ecmd.supported)
512 return -EINVAL;
513
514 if (advertise & ADVERTISED_100baseT_Full)
515 if (!(abilities.link_speed & I40E_LINK_SPEED_100MB)) {
516 config.link_speed |= I40E_LINK_SPEED_100MB;
517 change = true;
518 }
519 if (advertise & ADVERTISED_1000baseT_Full ||
520 advertise & ADVERTISED_1000baseKX_Full)
521 if (!(abilities.link_speed & I40E_LINK_SPEED_1GB)) {
522 config.link_speed |= I40E_LINK_SPEED_1GB;
523 change = true;
524 }
525 if (advertise & ADVERTISED_10000baseT_Full ||
526 advertise & ADVERTISED_10000baseKX4_Full ||
527 advertise & ADVERTISED_10000baseKR_Full)
528 if (!(abilities.link_speed & I40E_LINK_SPEED_10GB)) {
529 config.link_speed |= I40E_LINK_SPEED_10GB;
530 change = true;
531 }
532 if (advertise & ADVERTISED_40000baseKR4_Full ||
533 advertise & ADVERTISED_40000baseCR4_Full ||
534 advertise & ADVERTISED_40000baseSR4_Full ||
535 advertise & ADVERTISED_40000baseLR4_Full)
536 if (!(abilities.link_speed & I40E_LINK_SPEED_40GB)) {
537 config.link_speed |= I40E_LINK_SPEED_40GB;
538 change = true;
539 }
540
541 if (change) {
542 /* copy over the rest of the abilities */
543 config.phy_type = abilities.phy_type;
544 config.eee_capability = abilities.eee_capability;
545 config.eeer = abilities.eeer_val;
546 config.low_power_ctrl = abilities.d3_lpan;
547
548 /* If link is up set link and an so changes take effect */
549 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
550 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
551
552 /* make the aq call */
553 status = i40e_aq_set_phy_config(hw, &config, NULL);
554 if (status) {
555 netdev_info(netdev, "Set phy config failed with error %d.\n",
556 status);
557 return -EAGAIN;
558 }
559
560 status = i40e_update_link_info(hw, true);
561 if (status)
562 netdev_info(netdev, "Updating link info failed with error %d\n",
563 status);
564
565 } else {
566 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
567 }
568
569 return err;
570}
571
Jesse Brandeburga6599722014-06-04 08:45:25 +0000572static int i40e_nway_reset(struct net_device *netdev)
573{
574 /* restart autonegotiation */
575 struct i40e_netdev_priv *np = netdev_priv(netdev);
576 struct i40e_pf *pf = np->vsi->back;
577 struct i40e_hw *hw = &pf->hw;
578 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
579 i40e_status ret = 0;
580
581 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
582 if (ret) {
583 netdev_info(netdev, "link restart failed, aq_err=%d\n",
584 pf->hw.aq.asq_last_status);
585 return -EIO;
586 }
587
588 return 0;
589}
590
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000591/**
592 * i40e_get_pauseparam - Get Flow Control status
593 * Return tx/rx-pause status
594 **/
595static void i40e_get_pauseparam(struct net_device *netdev,
596 struct ethtool_pauseparam *pause)
597{
598 struct i40e_netdev_priv *np = netdev_priv(netdev);
599 struct i40e_pf *pf = np->vsi->back;
600 struct i40e_hw *hw = &pf->hw;
601 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
602
603 pause->autoneg =
604 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
605 AUTONEG_ENABLE : AUTONEG_DISABLE);
606
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000607 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000608 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000609 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000610 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000611 } else if (hw->fc.current_mode == I40E_FC_FULL) {
612 pause->rx_pause = 1;
613 pause->tx_pause = 1;
614 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000615}
616
Catherine Sullivan2becc352014-06-04 08:45:27 +0000617/**
618 * i40e_set_pauseparam - Set Flow Control parameter
619 * @netdev: network interface device structure
620 * @pause: return tx/rx flow control status
621 **/
622static int i40e_set_pauseparam(struct net_device *netdev,
623 struct ethtool_pauseparam *pause)
624{
625 struct i40e_netdev_priv *np = netdev_priv(netdev);
626 struct i40e_pf *pf = np->vsi->back;
627 struct i40e_vsi *vsi = np->vsi;
628 struct i40e_hw *hw = &pf->hw;
629 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
630 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
631 i40e_status status;
632 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000633 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000634
635 if (vsi != pf->vsi[pf->lan_vsi])
636 return -EOPNOTSUPP;
637
638 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
639 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
640 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
641 return -EOPNOTSUPP;
642 }
643
644 /* If we have link and don't have autoneg */
645 if (!test_bit(__I40E_DOWN, &pf->state) &&
646 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
647 /* Send message that it might not necessarily work*/
648 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
649 }
650
651 if (hw->fc.current_mode == I40E_FC_PFC) {
652 netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
653 return -EOPNOTSUPP;
654 }
655
656 if (pause->rx_pause && pause->tx_pause)
657 hw->fc.requested_mode = I40E_FC_FULL;
658 else if (pause->rx_pause && !pause->tx_pause)
659 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
660 else if (!pause->rx_pause && pause->tx_pause)
661 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
662 else if (!pause->rx_pause && !pause->tx_pause)
663 hw->fc.requested_mode = I40E_FC_NONE;
664 else
665 return -EINVAL;
666
667 /* Set the fc mode and only restart an if link is up*/
668 status = i40e_set_fc(hw, &aq_failures, link_up);
669
670 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
671 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
672 status, hw->aq.asq_last_status);
673 err = -EAGAIN;
674 }
675 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
676 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
677 status, hw->aq.asq_last_status);
678 err = -EAGAIN;
679 }
680 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
681 netdev_info(netdev, "Set fc failed on the update_link_info call with error %d and status %d\n",
682 status, hw->aq.asq_last_status);
683 err = -EAGAIN;
684 }
685
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000686 if (!test_bit(__I40E_DOWN, &pf->state)) {
687 /* Give it a little more time to try to come back */
688 msleep(75);
689 if (!test_bit(__I40E_DOWN, &pf->state))
690 return i40e_nway_reset(netdev);
691 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000692
693 return err;
694}
695
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000696static u32 i40e_get_msglevel(struct net_device *netdev)
697{
698 struct i40e_netdev_priv *np = netdev_priv(netdev);
699 struct i40e_pf *pf = np->vsi->back;
700
701 return pf->msg_enable;
702}
703
704static void i40e_set_msglevel(struct net_device *netdev, u32 data)
705{
706 struct i40e_netdev_priv *np = netdev_priv(netdev);
707 struct i40e_pf *pf = np->vsi->back;
708
709 if (I40E_DEBUG_USER & data)
710 pf->hw.debug_mask = data;
711 pf->msg_enable = data;
712}
713
714static int i40e_get_regs_len(struct net_device *netdev)
715{
716 int reg_count = 0;
717 int i;
718
719 for (i = 0; i40e_reg_list[i].offset != 0; i++)
720 reg_count += i40e_reg_list[i].elements;
721
722 return reg_count * sizeof(u32);
723}
724
725static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
726 void *p)
727{
728 struct i40e_netdev_priv *np = netdev_priv(netdev);
729 struct i40e_pf *pf = np->vsi->back;
730 struct i40e_hw *hw = &pf->hw;
731 u32 *reg_buf = p;
732 int i, j, ri;
733 u32 reg;
734
735 /* Tell ethtool which driver-version-specific regs output we have.
736 *
737 * At some point, if we have ethtool doing special formatting of
738 * this data, it will rely on this version number to know how to
739 * interpret things. Hence, this needs to be updated if/when the
740 * diags register table is changed.
741 */
742 regs->version = 1;
743
744 /* loop through the diags reg table for what to print */
745 ri = 0;
746 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
747 for (j = 0; j < i40e_reg_list[i].elements; j++) {
748 reg = i40e_reg_list[i].offset
749 + (j * i40e_reg_list[i].stride);
750 reg_buf[ri++] = rd32(hw, reg);
751 }
752 }
753
754}
755
756static int i40e_get_eeprom(struct net_device *netdev,
757 struct ethtool_eeprom *eeprom, u8 *bytes)
758{
759 struct i40e_netdev_priv *np = netdev_priv(netdev);
760 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000761 struct i40e_pf *pf = np->vsi->back;
762 int ret_val = 0, len;
763 u8 *eeprom_buff;
764 u16 i, sectors;
765 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000766 u32 magic;
767
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000768#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000769 if (eeprom->len == 0)
770 return -EINVAL;
771
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000772 /* check for NVMUpdate access method */
773 magic = hw->vendor_id | (hw->device_id << 16);
774 if (eeprom->magic && eeprom->magic != magic) {
775 int errno;
776
777 /* make sure it is the right magic for NVMUpdate */
778 if ((eeprom->magic >> 16) != hw->device_id)
779 return -EINVAL;
780
781 ret_val = i40e_nvmupd_command(hw,
782 (struct i40e_nvm_access *)eeprom,
783 bytes, &errno);
784 if (ret_val)
785 dev_info(&pf->pdev->dev,
786 "NVMUpdate read failed err=%d status=0x%x\n",
787 ret_val, hw->aq.asq_last_status);
788
789 return errno;
790 }
791
792 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000793 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
794
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000795 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000796 if (!eeprom_buff)
797 return -ENOMEM;
798
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000799 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
800 if (ret_val) {
801 dev_info(&pf->pdev->dev,
802 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
803 ret_val, hw->aq.asq_last_status);
804 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000805 }
806
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000807 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
808 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
809 len = I40E_NVM_SECTOR_SIZE;
810 last = false;
811 for (i = 0; i < sectors; i++) {
812 if (i == (sectors - 1)) {
813 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
814 last = true;
815 }
816 ret_val = i40e_aq_read_nvm(hw, 0x0,
817 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
818 len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000819 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000820 last, NULL);
821 if (ret_val) {
822 dev_info(&pf->pdev->dev,
823 "read NVM failed err=%d status=0x%x\n",
824 ret_val, hw->aq.asq_last_status);
825 goto release_nvm;
826 }
827 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000828
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000829release_nvm:
830 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000831 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000832free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000833 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000834 return ret_val;
835}
836
837static int i40e_get_eeprom_len(struct net_device *netdev)
838{
839 struct i40e_netdev_priv *np = netdev_priv(netdev);
840 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000841 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000842
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000843 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
844 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
845 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
846 /* register returns value in power of 2, 64Kbyte chunks. */
847 val = (64 * 1024) * (1 << val);
848 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000849}
850
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000851static int i40e_set_eeprom(struct net_device *netdev,
852 struct ethtool_eeprom *eeprom, u8 *bytes)
853{
854 struct i40e_netdev_priv *np = netdev_priv(netdev);
855 struct i40e_hw *hw = &np->vsi->back->hw;
856 struct i40e_pf *pf = np->vsi->back;
857 int ret_val = 0;
858 int errno;
859 u32 magic;
860
861 /* normal ethtool set_eeprom is not supported */
862 magic = hw->vendor_id | (hw->device_id << 16);
863 if (eeprom->magic == magic)
864 return -EOPNOTSUPP;
865
866 /* check for NVMUpdate access method */
867 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
868 return -EINVAL;
869
870 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
871 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
872 return -EBUSY;
873
874 ret_val = i40e_nvmupd_command(hw, (struct i40e_nvm_access *)eeprom,
875 bytes, &errno);
876 if (ret_val)
877 dev_info(&pf->pdev->dev,
878 "NVMUpdate write failed err=%d status=0x%x\n",
879 ret_val, hw->aq.asq_last_status);
880
881 return errno;
882}
883
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000884static void i40e_get_drvinfo(struct net_device *netdev,
885 struct ethtool_drvinfo *drvinfo)
886{
887 struct i40e_netdev_priv *np = netdev_priv(netdev);
888 struct i40e_vsi *vsi = np->vsi;
889 struct i40e_pf *pf = vsi->back;
890
891 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
892 strlcpy(drvinfo->version, i40e_driver_version_str,
893 sizeof(drvinfo->version));
894 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
895 sizeof(drvinfo->fw_version));
896 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
897 sizeof(drvinfo->bus_info));
898}
899
900static void i40e_get_ringparam(struct net_device *netdev,
901 struct ethtool_ringparam *ring)
902{
903 struct i40e_netdev_priv *np = netdev_priv(netdev);
904 struct i40e_pf *pf = np->vsi->back;
905 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
906
907 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
908 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
909 ring->rx_mini_max_pending = 0;
910 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +0000911 ring->rx_pending = vsi->rx_rings[0]->count;
912 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000913 ring->rx_mini_pending = 0;
914 ring->rx_jumbo_pending = 0;
915}
916
917static int i40e_set_ringparam(struct net_device *netdev,
918 struct ethtool_ringparam *ring)
919{
920 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
921 struct i40e_netdev_priv *np = netdev_priv(netdev);
922 struct i40e_vsi *vsi = np->vsi;
923 struct i40e_pf *pf = vsi->back;
924 u32 new_rx_count, new_tx_count;
925 int i, err = 0;
926
927 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
928 return -EINVAL;
929
Shannon Nelson1fa18372013-11-20 10:03:08 +0000930 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
931 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
932 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
933 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
934 netdev_info(netdev,
935 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
936 ring->tx_pending, ring->rx_pending,
937 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
938 return -EINVAL;
939 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000940
Shannon Nelson1fa18372013-11-20 10:03:08 +0000941 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
942 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000943
944 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000945 if ((new_tx_count == vsi->tx_rings[0]->count) &&
946 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000947 return 0;
948
949 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
950 usleep_range(1000, 2000);
951
952 if (!netif_running(vsi->netdev)) {
953 /* simple case - set for the next time the netdev is started */
954 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000955 vsi->tx_rings[i]->count = new_tx_count;
956 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000957 }
958 goto done;
959 }
960
961 /* We can't just free everything and then setup again,
962 * because the ISRs in MSI-X mode get passed pointers
963 * to the Tx and Rx ring structs.
964 */
965
966 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000967 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000968 netdev_info(netdev,
969 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000970 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000971 tx_rings = kcalloc(vsi->alloc_queue_pairs,
972 sizeof(struct i40e_ring), GFP_KERNEL);
973 if (!tx_rings) {
974 err = -ENOMEM;
975 goto done;
976 }
977
978 for (i = 0; i < vsi->num_queue_pairs; i++) {
979 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000980 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000981 tx_rings[i].count = new_tx_count;
982 err = i40e_setup_tx_descriptors(&tx_rings[i]);
983 if (err) {
984 while (i) {
985 i--;
986 i40e_free_tx_resources(&tx_rings[i]);
987 }
988 kfree(tx_rings);
989 tx_rings = NULL;
990
991 goto done;
992 }
993 }
994 }
995
996 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000997 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000998 netdev_info(netdev,
999 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001000 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001001 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1002 sizeof(struct i40e_ring), GFP_KERNEL);
1003 if (!rx_rings) {
1004 err = -ENOMEM;
1005 goto free_tx;
1006 }
1007
1008 for (i = 0; i < vsi->num_queue_pairs; i++) {
1009 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001010 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001011 rx_rings[i].count = new_rx_count;
1012 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1013 if (err) {
1014 while (i) {
1015 i--;
1016 i40e_free_rx_resources(&rx_rings[i]);
1017 }
1018 kfree(rx_rings);
1019 rx_rings = NULL;
1020
1021 goto free_tx;
1022 }
1023 }
1024 }
1025
1026 /* Bring interface down, copy in the new ring info,
1027 * then restore the interface
1028 */
1029 i40e_down(vsi);
1030
1031 if (tx_rings) {
1032 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001033 i40e_free_tx_resources(vsi->tx_rings[i]);
1034 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001035 }
1036 kfree(tx_rings);
1037 tx_rings = NULL;
1038 }
1039
1040 if (rx_rings) {
1041 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001042 i40e_free_rx_resources(vsi->rx_rings[i]);
1043 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001044 }
1045 kfree(rx_rings);
1046 rx_rings = NULL;
1047 }
1048
1049 i40e_up(vsi);
1050
1051free_tx:
1052 /* error cleanup if the Rx allocations failed after getting Tx */
1053 if (tx_rings) {
1054 for (i = 0; i < vsi->num_queue_pairs; i++)
1055 i40e_free_tx_resources(&tx_rings[i]);
1056 kfree(tx_rings);
1057 tx_rings = NULL;
1058 }
1059
1060done:
1061 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1062
1063 return err;
1064}
1065
1066static int i40e_get_sset_count(struct net_device *netdev, int sset)
1067{
1068 struct i40e_netdev_priv *np = netdev_priv(netdev);
1069 struct i40e_vsi *vsi = np->vsi;
1070 struct i40e_pf *pf = vsi->back;
1071
1072 switch (sset) {
1073 case ETH_SS_TEST:
1074 return I40E_TEST_LEN;
1075 case ETH_SS_STATS:
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001076 if (vsi == pf->vsi[pf->lan_vsi]) {
1077 int len = I40E_PF_STATS_LEN(netdev);
1078
1079 if (pf->lan_veb != I40E_NO_VEB)
1080 len += I40E_VEB_STATS_LEN;
1081 return len;
1082 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001083 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001084 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001085 default:
1086 return -EOPNOTSUPP;
1087 }
1088}
1089
1090static void i40e_get_ethtool_stats(struct net_device *netdev,
1091 struct ethtool_stats *stats, u64 *data)
1092{
1093 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001094 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001095 struct i40e_vsi *vsi = np->vsi;
1096 struct i40e_pf *pf = vsi->back;
1097 int i = 0;
1098 char *p;
1099 int j;
1100 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001101 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001102
1103 i40e_update_stats(vsi);
1104
1105 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1106 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1107 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1108 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1109 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001110 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1111 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1112 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1113 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1114 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001115 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001116 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001117 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001118
1119 if (!tx_ring)
1120 continue;
1121
1122 /* process Tx ring statistics */
1123 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001124 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001125 data[i] = tx_ring->stats.packets;
1126 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001127 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001128 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001129
1130 /* Rx ring is the 2nd half of the queue pair */
1131 rx_ring = &tx_ring[1];
1132 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001133 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001134 data[i] = rx_ring->stats.packets;
1135 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001136 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001137 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001138 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001139 rcu_read_unlock();
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001140 if (vsi != pf->vsi[pf->lan_vsi])
1141 return;
1142
1143 if (pf->lan_veb != I40E_NO_VEB) {
1144 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1145 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1146 p = (char *)veb;
1147 p += i40e_gstrings_veb_stats[j].stat_offset;
1148 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1149 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001150 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001151 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001152 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1153 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1154 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1155 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1156 }
1157 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1158 data[i++] = pf->stats.priority_xon_tx[j];
1159 data[i++] = pf->stats.priority_xoff_tx[j];
1160 }
1161 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1162 data[i++] = pf->stats.priority_xon_rx[j];
1163 data[i++] = pf->stats.priority_xoff_rx[j];
1164 }
1165 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1166 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001167}
1168
1169static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1170 u8 *data)
1171{
1172 struct i40e_netdev_priv *np = netdev_priv(netdev);
1173 struct i40e_vsi *vsi = np->vsi;
1174 struct i40e_pf *pf = vsi->back;
1175 char *p = (char *)data;
1176 int i;
1177
1178 switch (stringset) {
1179 case ETH_SS_TEST:
1180 for (i = 0; i < I40E_TEST_LEN; i++) {
1181 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1182 data += ETH_GSTRING_LEN;
1183 }
1184 break;
1185 case ETH_SS_STATS:
1186 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1187 snprintf(p, ETH_GSTRING_LEN, "%s",
1188 i40e_gstrings_net_stats[i].stat_string);
1189 p += ETH_GSTRING_LEN;
1190 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001191 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1192 snprintf(p, ETH_GSTRING_LEN, "%s",
1193 i40e_gstrings_misc_stats[i].stat_string);
1194 p += ETH_GSTRING_LEN;
1195 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001196 for (i = 0; i < vsi->num_queue_pairs; i++) {
1197 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1198 p += ETH_GSTRING_LEN;
1199 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1200 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001201 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1202 p += ETH_GSTRING_LEN;
1203 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1204 p += ETH_GSTRING_LEN;
1205 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001206 if (vsi != pf->vsi[pf->lan_vsi])
1207 return;
1208
1209 if (pf->lan_veb != I40E_NO_VEB) {
1210 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1211 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1212 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001213 p += ETH_GSTRING_LEN;
1214 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001215 }
1216 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1217 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1218 i40e_gstrings_stats[i].stat_string);
1219 p += ETH_GSTRING_LEN;
1220 }
1221 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1222 snprintf(p, ETH_GSTRING_LEN,
1223 "port.tx_priority_%u_xon", i);
1224 p += ETH_GSTRING_LEN;
1225 snprintf(p, ETH_GSTRING_LEN,
1226 "port.tx_priority_%u_xoff", i);
1227 p += ETH_GSTRING_LEN;
1228 }
1229 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1230 snprintf(p, ETH_GSTRING_LEN,
1231 "port.rx_priority_%u_xon", i);
1232 p += ETH_GSTRING_LEN;
1233 snprintf(p, ETH_GSTRING_LEN,
1234 "port.rx_priority_%u_xoff", i);
1235 p += ETH_GSTRING_LEN;
1236 }
1237 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1238 snprintf(p, ETH_GSTRING_LEN,
1239 "port.rx_priority_%u_xon_2_xoff", i);
1240 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001241 }
1242 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1243 break;
1244 }
1245}
1246
1247static int i40e_get_ts_info(struct net_device *dev,
1248 struct ethtool_ts_info *info)
1249{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001250 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1251
1252 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1253 SOF_TIMESTAMPING_RX_SOFTWARE |
1254 SOF_TIMESTAMPING_SOFTWARE |
1255 SOF_TIMESTAMPING_TX_HARDWARE |
1256 SOF_TIMESTAMPING_RX_HARDWARE |
1257 SOF_TIMESTAMPING_RAW_HARDWARE;
1258
1259 if (pf->ptp_clock)
1260 info->phc_index = ptp_clock_index(pf->ptp_clock);
1261 else
1262 info->phc_index = -1;
1263
1264 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1265
1266 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1267 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1268 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1269 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1270 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1271 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1272 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1273 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1274 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1275 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1276 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1277 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1278
1279 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001280}
1281
Shannon Nelson7b086392013-11-20 10:02:59 +00001282static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001283{
Shannon Nelson7b086392013-11-20 10:02:59 +00001284 struct i40e_netdev_priv *np = netdev_priv(netdev);
1285 struct i40e_pf *pf = np->vsi->back;
1286
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001287 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001288 if (i40e_get_link_status(&pf->hw))
1289 *data = 0;
1290 else
1291 *data = 1;
1292
1293 return *data;
1294}
1295
Shannon Nelson7b086392013-11-20 10:02:59 +00001296static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001297{
Shannon Nelson7b086392013-11-20 10:02:59 +00001298 struct i40e_netdev_priv *np = netdev_priv(netdev);
1299 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001300
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001301 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001302 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001303
Shannon Nelson7b086392013-11-20 10:02:59 +00001304 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001305}
1306
Shannon Nelson7b086392013-11-20 10:02:59 +00001307static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001308{
Shannon Nelson7b086392013-11-20 10:02:59 +00001309 struct i40e_netdev_priv *np = netdev_priv(netdev);
1310 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001311
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001312 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001313 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001314
Shannon Nelson7b086392013-11-20 10:02:59 +00001315 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001316}
1317
Shannon Nelson7b086392013-11-20 10:02:59 +00001318static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001319{
Shannon Nelson7b086392013-11-20 10:02:59 +00001320 struct i40e_netdev_priv *np = netdev_priv(netdev);
1321 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001322 u16 swc_old = pf->sw_int_count;
1323
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001324 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001325 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1326 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
1327 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
1328 usleep_range(1000, 2000);
1329 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001330
1331 return *data;
1332}
1333
Shannon Nelson7b086392013-11-20 10:02:59 +00001334static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001335{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001336 struct i40e_netdev_priv *np = netdev_priv(netdev);
1337 struct i40e_pf *pf = np->vsi->back;
1338
1339 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001340 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001341
1342 return *data;
1343}
1344
1345static void i40e_diag_test(struct net_device *netdev,
1346 struct ethtool_test *eth_test, u64 *data)
1347{
1348 struct i40e_netdev_priv *np = netdev_priv(netdev);
1349 struct i40e_pf *pf = np->vsi->back;
1350
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001351 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1352 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001353 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001354
Shannon Nelsonf551b432013-11-26 10:49:12 +00001355 set_bit(__I40E_TESTING, &pf->state);
1356
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001357 /* Link test performed before hardware reset
1358 * so autoneg doesn't interfere with test result
1359 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001360 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001361 eth_test->flags |= ETH_TEST_FL_FAILED;
1362
Shannon Nelson7b086392013-11-20 10:02:59 +00001363 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001364 eth_test->flags |= ETH_TEST_FL_FAILED;
1365
Shannon Nelson7b086392013-11-20 10:02:59 +00001366 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001367 eth_test->flags |= ETH_TEST_FL_FAILED;
1368
Shannon Nelson7b086392013-11-20 10:02:59 +00001369 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001370 eth_test->flags |= ETH_TEST_FL_FAILED;
1371
Shannon Nelsonf551b432013-11-26 10:49:12 +00001372 /* run reg test last, a reset is required after it */
1373 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1374 eth_test->flags |= ETH_TEST_FL_FAILED;
1375
1376 clear_bit(__I40E_TESTING, &pf->state);
1377 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001378 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001379 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001380 netif_info(pf, drv, netdev, "online testing starting\n");
1381
Shannon Nelson7b086392013-11-20 10:02:59 +00001382 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001383 eth_test->flags |= ETH_TEST_FL_FAILED;
1384
1385 /* Offline only tests, not run in online; pass by default */
1386 data[I40E_ETH_TEST_REG] = 0;
1387 data[I40E_ETH_TEST_EEPROM] = 0;
1388 data[I40E_ETH_TEST_INTR] = 0;
1389 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001390 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001391
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001392 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001393}
1394
1395static void i40e_get_wol(struct net_device *netdev,
1396 struct ethtool_wolinfo *wol)
1397{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001398 struct i40e_netdev_priv *np = netdev_priv(netdev);
1399 struct i40e_pf *pf = np->vsi->back;
1400 struct i40e_hw *hw = &pf->hw;
1401 u16 wol_nvm_bits;
1402
1403 /* NVM bit on means WoL disabled for the port */
1404 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1405 if ((1 << hw->port) & wol_nvm_bits) {
1406 wol->supported = 0;
1407 wol->wolopts = 0;
1408 } else {
1409 wol->supported = WAKE_MAGIC;
1410 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1411 }
1412}
1413
1414static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1415{
1416 struct i40e_netdev_priv *np = netdev_priv(netdev);
1417 struct i40e_pf *pf = np->vsi->back;
1418 struct i40e_hw *hw = &pf->hw;
1419 u16 wol_nvm_bits;
1420
1421 /* NVM bit on means WoL disabled for the port */
1422 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1423 if (((1 << hw->port) & wol_nvm_bits))
1424 return -EOPNOTSUPP;
1425
1426 /* only magic packet is supported */
1427 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1428 return -EOPNOTSUPP;
1429
1430 /* is this a new value? */
1431 if (pf->wol_en != !!wol->wolopts) {
1432 pf->wol_en = !!wol->wolopts;
1433 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1434 }
1435
1436 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001437}
1438
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001439static int i40e_set_phys_id(struct net_device *netdev,
1440 enum ethtool_phys_id_state state)
1441{
1442 struct i40e_netdev_priv *np = netdev_priv(netdev);
1443 struct i40e_pf *pf = np->vsi->back;
1444 struct i40e_hw *hw = &pf->hw;
1445 int blink_freq = 2;
1446
1447 switch (state) {
1448 case ETHTOOL_ID_ACTIVE:
1449 pf->led_status = i40e_led_get(hw);
1450 return blink_freq;
1451 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001452 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001453 break;
1454 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001455 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001456 break;
1457 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001458 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001459 break;
1460 }
1461
1462 return 0;
1463}
1464
1465/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1466 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1467 * 125us (8000 interrupts per second) == ITR(62)
1468 */
1469
1470static int i40e_get_coalesce(struct net_device *netdev,
1471 struct ethtool_coalesce *ec)
1472{
1473 struct i40e_netdev_priv *np = netdev_priv(netdev);
1474 struct i40e_vsi *vsi = np->vsi;
1475
1476 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1477 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1478
1479 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001480 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001481
1482 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001483 ec->use_adaptive_tx_coalesce = 1;
1484
1485 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1486 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001487
1488 return 0;
1489}
1490
1491static int i40e_set_coalesce(struct net_device *netdev,
1492 struct ethtool_coalesce *ec)
1493{
1494 struct i40e_netdev_priv *np = netdev_priv(netdev);
1495 struct i40e_q_vector *q_vector;
1496 struct i40e_vsi *vsi = np->vsi;
1497 struct i40e_pf *pf = vsi->back;
1498 struct i40e_hw *hw = &pf->hw;
1499 u16 vector;
1500 int i;
1501
1502 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1503 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1504
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001505 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001506 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001507 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001508 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001509 } else if (ec->rx_coalesce_usecs == 0) {
1510 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1511 i40e_irq_dynamic_disable(vsi, vector);
1512 if (ec->use_adaptive_rx_coalesce)
1513 netif_info(pf, drv, netdev,
1514 "Rx-secs=0, need to disable adaptive-Rx for a complete disable\n");
1515 } else {
1516 netif_info(pf, drv, netdev,
1517 "Invalid value, Rx-usecs range is 0, 8-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001518 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001519 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001520
Mitch Williams32f5f542014-04-04 04:43:10 +00001521 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001522 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001523 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001524 } else if (ec->tx_coalesce_usecs == 0) {
1525 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1526 i40e_irq_dynamic_disable(vsi, vector);
1527 if (ec->use_adaptive_tx_coalesce)
1528 netif_info(pf, drv, netdev,
1529 "Tx-secs=0, need to disable adaptive-Tx for a complete disable\n");
1530 } else {
1531 netif_info(pf, drv, netdev,
1532 "Invalid value, Tx-usecs range is 0, 8-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001533 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001534 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001535
1536 if (ec->use_adaptive_rx_coalesce)
1537 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1538 else
1539 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1540
1541 if (ec->use_adaptive_tx_coalesce)
1542 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1543 else
1544 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001545
Alexander Duyck493fb302013-09-28 07:01:44 +00001546 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1547 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001548 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1549 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1550 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1551 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1552 i40e_flush(hw);
1553 }
1554
1555 return 0;
1556}
1557
1558/**
1559 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1560 * @pf: pointer to the physical function struct
1561 * @cmd: ethtool rxnfc command
1562 *
1563 * Returns Success if the flow is supported, else Invalid Input.
1564 **/
1565static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1566{
1567 cmd->data = 0;
1568
1569 /* Report default options for RSS on i40e */
1570 switch (cmd->flow_type) {
1571 case TCP_V4_FLOW:
1572 case UDP_V4_FLOW:
1573 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1574 /* fall through to add IP fields */
1575 case SCTP_V4_FLOW:
1576 case AH_ESP_V4_FLOW:
1577 case AH_V4_FLOW:
1578 case ESP_V4_FLOW:
1579 case IPV4_FLOW:
1580 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1581 break;
1582 case TCP_V6_FLOW:
1583 case UDP_V6_FLOW:
1584 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1585 /* fall through to add IP fields */
1586 case SCTP_V6_FLOW:
1587 case AH_ESP_V6_FLOW:
1588 case AH_V6_FLOW:
1589 case ESP_V6_FLOW:
1590 case IPV6_FLOW:
1591 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1592 break;
1593 default:
1594 return -EINVAL;
1595 }
1596
1597 return 0;
1598}
1599
1600/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001601 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1602 * @pf: Pointer to the physical function struct
1603 * @cmd: The command to get or set Rx flow classification rules
1604 * @rule_locs: Array of used rule locations
1605 *
1606 * This function populates both the total and actual rule count of
1607 * the ethtool flow classification command
1608 *
1609 * Returns 0 on success or -EMSGSIZE if entry not found
1610 **/
1611static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1612 struct ethtool_rxnfc *cmd,
1613 u32 *rule_locs)
1614{
1615 struct i40e_fdir_filter *rule;
1616 struct hlist_node *node2;
1617 int cnt = 0;
1618
1619 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001620 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001621
1622 hlist_for_each_entry_safe(rule, node2,
1623 &pf->fdir_filter_list, fdir_node) {
1624 if (cnt == cmd->rule_cnt)
1625 return -EMSGSIZE;
1626
1627 rule_locs[cnt] = rule->fd_id;
1628 cnt++;
1629 }
1630
1631 cmd->rule_cnt = cnt;
1632
1633 return 0;
1634}
1635
1636/**
1637 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1638 * @pf: Pointer to the physical function struct
1639 * @cmd: The command to get or set Rx flow classification rules
1640 *
1641 * This function looks up a filter based on the Rx flow classification
1642 * command and fills the flow spec info for it if found
1643 *
1644 * Returns 0 on success or -EINVAL if filter not found
1645 **/
1646static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1647 struct ethtool_rxnfc *cmd)
1648{
1649 struct ethtool_rx_flow_spec *fsp =
1650 (struct ethtool_rx_flow_spec *)&cmd->fs;
1651 struct i40e_fdir_filter *rule = NULL;
1652 struct hlist_node *node2;
1653
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001654 hlist_for_each_entry_safe(rule, node2,
1655 &pf->fdir_filter_list, fdir_node) {
1656 if (fsp->location <= rule->fd_id)
1657 break;
1658 }
1659
1660 if (!rule || fsp->location != rule->fd_id)
1661 return -EINVAL;
1662
1663 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001664 if (fsp->flow_type == IP_USER_FLOW) {
1665 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1666 fsp->h_u.usr_ip4_spec.proto = 0;
1667 fsp->m_u.usr_ip4_spec.proto = 0;
1668 }
1669
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001670 /* Reverse the src and dest notion, since the HW views them from
1671 * Tx perspective where as the user expects it from Rx filter view.
1672 */
1673 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1674 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1675 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1676 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001677
1678 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1679 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1680 else
1681 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001682
1683 return 0;
1684}
1685
1686/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001687 * i40e_get_rxnfc - command to get RX flow classification rules
1688 * @netdev: network interface device structure
1689 * @cmd: ethtool rxnfc command
1690 *
1691 * Returns Success if the command is supported.
1692 **/
1693static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1694 u32 *rule_locs)
1695{
1696 struct i40e_netdev_priv *np = netdev_priv(netdev);
1697 struct i40e_vsi *vsi = np->vsi;
1698 struct i40e_pf *pf = vsi->back;
1699 int ret = -EOPNOTSUPP;
1700
1701 switch (cmd->cmd) {
1702 case ETHTOOL_GRXRINGS:
1703 cmd->data = vsi->alloc_queue_pairs;
1704 ret = 0;
1705 break;
1706 case ETHTOOL_GRXFH:
1707 ret = i40e_get_rss_hash_opts(pf, cmd);
1708 break;
1709 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001710 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001711 /* report total rule count */
1712 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001713 ret = 0;
1714 break;
1715 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001716 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001717 break;
1718 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001719 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1720 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001721 default:
1722 break;
1723 }
1724
1725 return ret;
1726}
1727
1728/**
1729 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1730 * @pf: pointer to the physical function struct
1731 * @cmd: ethtool rxnfc command
1732 *
1733 * Returns Success if the flow input set is supported.
1734 **/
1735static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1736{
1737 struct i40e_hw *hw = &pf->hw;
1738 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1739 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1740
1741 /* RSS does not support anything other than hashing
1742 * to queues on src and dst IPs and ports
1743 */
1744 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1745 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1746 return -EINVAL;
1747
1748 /* We need at least the IP SRC and DEST fields for hashing */
1749 if (!(nfc->data & RXH_IP_SRC) ||
1750 !(nfc->data & RXH_IP_DST))
1751 return -EINVAL;
1752
1753 switch (nfc->flow_type) {
1754 case TCP_V4_FLOW:
1755 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1756 case 0:
1757 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1758 break;
1759 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1760 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1761 break;
1762 default:
1763 return -EINVAL;
1764 }
1765 break;
1766 case TCP_V6_FLOW:
1767 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1768 case 0:
1769 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1770 break;
1771 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1772 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1773 break;
1774 default:
1775 return -EINVAL;
1776 }
1777 break;
1778 case UDP_V4_FLOW:
1779 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1780 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001781 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1782 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001783 break;
1784 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001785 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1786 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001787 break;
1788 default:
1789 return -EINVAL;
1790 }
1791 break;
1792 case UDP_V6_FLOW:
1793 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1794 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001795 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1796 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001797 break;
1798 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001799 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1800 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001801 break;
1802 default:
1803 return -EINVAL;
1804 }
1805 break;
1806 case AH_ESP_V4_FLOW:
1807 case AH_V4_FLOW:
1808 case ESP_V4_FLOW:
1809 case SCTP_V4_FLOW:
1810 if ((nfc->data & RXH_L4_B_0_1) ||
1811 (nfc->data & RXH_L4_B_2_3))
1812 return -EINVAL;
1813 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1814 break;
1815 case AH_ESP_V6_FLOW:
1816 case AH_V6_FLOW:
1817 case ESP_V6_FLOW:
1818 case SCTP_V6_FLOW:
1819 if ((nfc->data & RXH_L4_B_0_1) ||
1820 (nfc->data & RXH_L4_B_2_3))
1821 return -EINVAL;
1822 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1823 break;
1824 case IPV4_FLOW:
1825 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1826 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1827 break;
1828 case IPV6_FLOW:
1829 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1830 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1831 break;
1832 default:
1833 return -EINVAL;
1834 }
1835
1836 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1837 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1838 i40e_flush(hw);
1839
1840 return 0;
1841}
1842
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001843/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001844 * i40e_match_fdir_input_set - Match a new filter against an existing one
1845 * @rule: The filter already added
1846 * @input: The new filter to comapre against
1847 *
1848 * Returns true if the two input set match
1849 **/
1850static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1851 struct i40e_fdir_filter *input)
1852{
1853 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1854 (rule->src_ip[0] != input->src_ip[0]) ||
1855 (rule->dst_port != input->dst_port) ||
1856 (rule->src_port != input->src_port))
1857 return false;
1858 return true;
1859}
1860
1861/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001862 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1863 * @vsi: Pointer to the targeted VSI
1864 * @input: The filter to update or NULL to indicate deletion
1865 * @sw_idx: Software index to the filter
1866 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001867 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001868 * This function updates (or deletes) a Flow Director entry from
1869 * the hlist of the corresponding PF
1870 *
1871 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001872 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001873static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1874 struct i40e_fdir_filter *input,
1875 u16 sw_idx,
1876 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001877{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001878 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001879 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001880 struct hlist_node *node2;
1881 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001882
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001883 parent = NULL;
1884 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001885
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001886 hlist_for_each_entry_safe(rule, node2,
1887 &pf->fdir_filter_list, fdir_node) {
1888 /* hash found, or no matching entry */
1889 if (rule->fd_id >= sw_idx)
1890 break;
1891 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001892 }
1893
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001894 /* if there is an old rule occupying our place remove it */
1895 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001896 if (input && !i40e_match_fdir_input_set(rule, input))
1897 err = i40e_add_del_fdir(vsi, rule, false);
1898 else if (!input)
1899 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001900 hlist_del(&rule->fdir_node);
1901 kfree(rule);
1902 pf->fdir_pf_active_filters--;
1903 }
1904
1905 /* If no input this was a delete, err should be 0 if a rule was
1906 * successfully found and removed from the list else -EINVAL
1907 */
1908 if (!input)
1909 return err;
1910
1911 /* initialize node and set software index */
1912 INIT_HLIST_NODE(&input->fdir_node);
1913
1914 /* add filter to the list */
1915 if (parent)
1916 hlist_add_after(&parent->fdir_node, &input->fdir_node);
1917 else
1918 hlist_add_head(&input->fdir_node,
1919 &pf->fdir_filter_list);
1920
1921 /* update counts */
1922 pf->fdir_pf_active_filters++;
1923
1924 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001925}
1926
1927/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001928 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
1929 * @vsi: Pointer to the targeted VSI
1930 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001931 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001932 * The function removes a Flow Director filter entry from the
1933 * hlist of the corresponding PF
1934 *
1935 * Returns 0 on success
1936 */
1937static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
1938 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001939{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001940 struct ethtool_rx_flow_spec *fsp =
1941 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001942 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001943 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001944
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001945 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001946
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001947 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001948 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001949}
1950
1951/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001952 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001953 * @vsi: pointer to the targeted VSI
1954 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001955 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001956 * Add Flow Director filters for a specific flow spec based on their
1957 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001958 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001959static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
1960 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001961{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001962 struct ethtool_rx_flow_spec *fsp;
1963 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001964 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001965 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001966
1967 if (!vsi)
1968 return -EINVAL;
1969
1970 pf = vsi->back;
1971
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001972 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
1973 return -EOPNOTSUPP;
1974
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001975 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001976 return -ENOSPC;
1977
1978 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
1979
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001980 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
1981 pf->hw.func_caps.fd_filters_guaranteed)) {
1982 return -EINVAL;
1983 }
1984
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001985 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
1986 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001987 return -EINVAL;
1988
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001989 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001990
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001991 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001992 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001993
1994 input->fd_id = fsp->location;
1995
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00001996 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
1997 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
1998 else
1999 input->dest_ctl =
2000 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2001
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002002 input->q_index = fsp->ring_cookie;
2003 input->flex_off = 0;
2004 input->pctype = 0;
2005 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002006 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00002007 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002008 input->flow_type = fsp->flow_type;
2009 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002010
2011 /* Reverse the src and dest notion, since the HW expects them to be from
2012 * Tx perspective where as the input from user is from Rx filter view.
2013 */
2014 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2015 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2016 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2017 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002018
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002019 ret = i40e_add_del_fdir(vsi, input, true);
2020 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002021 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002022 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002023 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002024
2025 return ret;
2026}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002027
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002028/**
2029 * i40e_set_rxnfc - command to set RX flow classification rules
2030 * @netdev: network interface device structure
2031 * @cmd: ethtool rxnfc command
2032 *
2033 * Returns Success if the command is supported.
2034 **/
2035static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2036{
2037 struct i40e_netdev_priv *np = netdev_priv(netdev);
2038 struct i40e_vsi *vsi = np->vsi;
2039 struct i40e_pf *pf = vsi->back;
2040 int ret = -EOPNOTSUPP;
2041
2042 switch (cmd->cmd) {
2043 case ETHTOOL_SRXFH:
2044 ret = i40e_set_rss_hash_opt(pf, cmd);
2045 break;
2046 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002047 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002048 break;
2049 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002050 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002051 break;
2052 default:
2053 break;
2054 }
2055
2056 return ret;
2057}
2058
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002059/**
2060 * i40e_max_channels - get Max number of combined channels supported
2061 * @vsi: vsi pointer
2062 **/
2063static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2064{
2065 /* TODO: This code assumes DCB and FD is disabled for now. */
2066 return vsi->alloc_queue_pairs;
2067}
2068
2069/**
2070 * i40e_get_channels - Get the current channels enabled and max supported etc.
2071 * @netdev: network interface device structure
2072 * @ch: ethtool channels structure
2073 *
2074 * We don't support separate tx and rx queues as channels. The other count
2075 * represents how many queues are being used for control. max_combined counts
2076 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2077 * q_vectors since we support a lot more queue pairs than q_vectors.
2078 **/
2079static void i40e_get_channels(struct net_device *dev,
2080 struct ethtool_channels *ch)
2081{
2082 struct i40e_netdev_priv *np = netdev_priv(dev);
2083 struct i40e_vsi *vsi = np->vsi;
2084 struct i40e_pf *pf = vsi->back;
2085
2086 /* report maximum channels */
2087 ch->max_combined = i40e_max_channels(vsi);
2088
2089 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002090 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002091 ch->max_other = ch->other_count;
2092
2093 /* Note: This code assumes DCB is disabled for now. */
2094 ch->combined_count = vsi->num_queue_pairs;
2095}
2096
2097/**
2098 * i40e_set_channels - Set the new channels count.
2099 * @netdev: network interface device structure
2100 * @ch: ethtool channels structure
2101 *
2102 * The new channels count may not be the same as requested by the user
2103 * since it gets rounded down to a power of 2 value.
2104 **/
2105static int i40e_set_channels(struct net_device *dev,
2106 struct ethtool_channels *ch)
2107{
2108 struct i40e_netdev_priv *np = netdev_priv(dev);
2109 unsigned int count = ch->combined_count;
2110 struct i40e_vsi *vsi = np->vsi;
2111 struct i40e_pf *pf = vsi->back;
2112 int new_count;
2113
2114 /* We do not support setting channels for any other VSI at present */
2115 if (vsi->type != I40E_VSI_MAIN)
2116 return -EINVAL;
2117
2118 /* verify they are not requesting separate vectors */
2119 if (!count || ch->rx_count || ch->tx_count)
2120 return -EINVAL;
2121
2122 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002123 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002124 return -EINVAL;
2125
2126 /* verify the number of channels does not exceed hardware limits */
2127 if (count > i40e_max_channels(vsi))
2128 return -EINVAL;
2129
2130 /* update feature limits from largest to smallest supported values */
2131 /* TODO: Flow director limit, DCB etc */
2132
2133 /* cap RSS limit */
2134 if (count > pf->rss_size_max)
2135 count = pf->rss_size_max;
2136
2137 /* use rss_reconfig to rebuild with new queue count and update traffic
2138 * class queue mapping
2139 */
2140 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002141 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002142 return 0;
2143 else
2144 return -EINVAL;
2145}
2146
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002147static const struct ethtool_ops i40e_ethtool_ops = {
2148 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002149 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002150 .get_drvinfo = i40e_get_drvinfo,
2151 .get_regs_len = i40e_get_regs_len,
2152 .get_regs = i40e_get_regs,
2153 .nway_reset = i40e_nway_reset,
2154 .get_link = ethtool_op_get_link,
2155 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002156 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002157 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002158 .get_eeprom_len = i40e_get_eeprom_len,
2159 .get_eeprom = i40e_get_eeprom,
2160 .get_ringparam = i40e_get_ringparam,
2161 .set_ringparam = i40e_set_ringparam,
2162 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002163 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002164 .get_msglevel = i40e_get_msglevel,
2165 .set_msglevel = i40e_set_msglevel,
2166 .get_rxnfc = i40e_get_rxnfc,
2167 .set_rxnfc = i40e_set_rxnfc,
2168 .self_test = i40e_diag_test,
2169 .get_strings = i40e_get_strings,
2170 .set_phys_id = i40e_set_phys_id,
2171 .get_sset_count = i40e_get_sset_count,
2172 .get_ethtool_stats = i40e_get_ethtool_stats,
2173 .get_coalesce = i40e_get_coalesce,
2174 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002175 .get_channels = i40e_get_channels,
2176 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002177 .get_ts_info = i40e_get_ts_info,
2178};
2179
2180void i40e_set_ethtool_ops(struct net_device *netdev)
2181{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002182 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002183}