blob: 3abd3cbab75fe8730c41d8f1cd1e76e72430cdc4 [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;
633 int err;
634
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
686 if (!test_bit(__I40E_DOWN, &pf->state))
687 return i40e_nway_reset(netdev);
688
689 return err;
690}
691
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000692static u32 i40e_get_msglevel(struct net_device *netdev)
693{
694 struct i40e_netdev_priv *np = netdev_priv(netdev);
695 struct i40e_pf *pf = np->vsi->back;
696
697 return pf->msg_enable;
698}
699
700static void i40e_set_msglevel(struct net_device *netdev, u32 data)
701{
702 struct i40e_netdev_priv *np = netdev_priv(netdev);
703 struct i40e_pf *pf = np->vsi->back;
704
705 if (I40E_DEBUG_USER & data)
706 pf->hw.debug_mask = data;
707 pf->msg_enable = data;
708}
709
710static int i40e_get_regs_len(struct net_device *netdev)
711{
712 int reg_count = 0;
713 int i;
714
715 for (i = 0; i40e_reg_list[i].offset != 0; i++)
716 reg_count += i40e_reg_list[i].elements;
717
718 return reg_count * sizeof(u32);
719}
720
721static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
722 void *p)
723{
724 struct i40e_netdev_priv *np = netdev_priv(netdev);
725 struct i40e_pf *pf = np->vsi->back;
726 struct i40e_hw *hw = &pf->hw;
727 u32 *reg_buf = p;
728 int i, j, ri;
729 u32 reg;
730
731 /* Tell ethtool which driver-version-specific regs output we have.
732 *
733 * At some point, if we have ethtool doing special formatting of
734 * this data, it will rely on this version number to know how to
735 * interpret things. Hence, this needs to be updated if/when the
736 * diags register table is changed.
737 */
738 regs->version = 1;
739
740 /* loop through the diags reg table for what to print */
741 ri = 0;
742 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
743 for (j = 0; j < i40e_reg_list[i].elements; j++) {
744 reg = i40e_reg_list[i].offset
745 + (j * i40e_reg_list[i].stride);
746 reg_buf[ri++] = rd32(hw, reg);
747 }
748 }
749
750}
751
752static int i40e_get_eeprom(struct net_device *netdev,
753 struct ethtool_eeprom *eeprom, u8 *bytes)
754{
755 struct i40e_netdev_priv *np = netdev_priv(netdev);
756 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000757 struct i40e_pf *pf = np->vsi->back;
758 int ret_val = 0, len;
759 u8 *eeprom_buff;
760 u16 i, sectors;
761 bool last;
762#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000763 if (eeprom->len == 0)
764 return -EINVAL;
765
766 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
767
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000768 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000769 if (!eeprom_buff)
770 return -ENOMEM;
771
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000772 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
773 if (ret_val) {
774 dev_info(&pf->pdev->dev,
775 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
776 ret_val, hw->aq.asq_last_status);
777 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000778 }
779
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000780 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
781 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
782 len = I40E_NVM_SECTOR_SIZE;
783 last = false;
784 for (i = 0; i < sectors; i++) {
785 if (i == (sectors - 1)) {
786 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
787 last = true;
788 }
789 ret_val = i40e_aq_read_nvm(hw, 0x0,
790 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
791 len,
Joe Perches3dbb7fd2014-03-25 04:30:38 +0000792 eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000793 last, NULL);
794 if (ret_val) {
795 dev_info(&pf->pdev->dev,
796 "read NVM failed err=%d status=0x%x\n",
797 ret_val, hw->aq.asq_last_status);
798 goto release_nvm;
799 }
800 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000801
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000802release_nvm:
803 i40e_release_nvm(hw);
Joe Perches3dbb7fd2014-03-25 04:30:38 +0000804 memcpy(bytes, eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000805free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000806 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000807 return ret_val;
808}
809
810static int i40e_get_eeprom_len(struct net_device *netdev)
811{
812 struct i40e_netdev_priv *np = netdev_priv(netdev);
813 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000814 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000815
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000816 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
817 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
818 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
819 /* register returns value in power of 2, 64Kbyte chunks. */
820 val = (64 * 1024) * (1 << val);
821 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000822}
823
824static void i40e_get_drvinfo(struct net_device *netdev,
825 struct ethtool_drvinfo *drvinfo)
826{
827 struct i40e_netdev_priv *np = netdev_priv(netdev);
828 struct i40e_vsi *vsi = np->vsi;
829 struct i40e_pf *pf = vsi->back;
830
831 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
832 strlcpy(drvinfo->version, i40e_driver_version_str,
833 sizeof(drvinfo->version));
834 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
835 sizeof(drvinfo->fw_version));
836 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
837 sizeof(drvinfo->bus_info));
838}
839
840static void i40e_get_ringparam(struct net_device *netdev,
841 struct ethtool_ringparam *ring)
842{
843 struct i40e_netdev_priv *np = netdev_priv(netdev);
844 struct i40e_pf *pf = np->vsi->back;
845 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
846
847 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
848 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
849 ring->rx_mini_max_pending = 0;
850 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +0000851 ring->rx_pending = vsi->rx_rings[0]->count;
852 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000853 ring->rx_mini_pending = 0;
854 ring->rx_jumbo_pending = 0;
855}
856
857static int i40e_set_ringparam(struct net_device *netdev,
858 struct ethtool_ringparam *ring)
859{
860 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
861 struct i40e_netdev_priv *np = netdev_priv(netdev);
862 struct i40e_vsi *vsi = np->vsi;
863 struct i40e_pf *pf = vsi->back;
864 u32 new_rx_count, new_tx_count;
865 int i, err = 0;
866
867 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
868 return -EINVAL;
869
Shannon Nelson1fa18372013-11-20 10:03:08 +0000870 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
871 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
872 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
873 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
874 netdev_info(netdev,
875 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
876 ring->tx_pending, ring->rx_pending,
877 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
878 return -EINVAL;
879 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000880
Shannon Nelson1fa18372013-11-20 10:03:08 +0000881 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
882 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000883
884 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000885 if ((new_tx_count == vsi->tx_rings[0]->count) &&
886 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000887 return 0;
888
889 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
890 usleep_range(1000, 2000);
891
892 if (!netif_running(vsi->netdev)) {
893 /* simple case - set for the next time the netdev is started */
894 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000895 vsi->tx_rings[i]->count = new_tx_count;
896 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000897 }
898 goto done;
899 }
900
901 /* We can't just free everything and then setup again,
902 * because the ISRs in MSI-X mode get passed pointers
903 * to the Tx and Rx ring structs.
904 */
905
906 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000907 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000908 netdev_info(netdev,
909 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000910 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000911 tx_rings = kcalloc(vsi->alloc_queue_pairs,
912 sizeof(struct i40e_ring), GFP_KERNEL);
913 if (!tx_rings) {
914 err = -ENOMEM;
915 goto done;
916 }
917
918 for (i = 0; i < vsi->num_queue_pairs; i++) {
919 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000920 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000921 tx_rings[i].count = new_tx_count;
922 err = i40e_setup_tx_descriptors(&tx_rings[i]);
923 if (err) {
924 while (i) {
925 i--;
926 i40e_free_tx_resources(&tx_rings[i]);
927 }
928 kfree(tx_rings);
929 tx_rings = NULL;
930
931 goto done;
932 }
933 }
934 }
935
936 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000937 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000938 netdev_info(netdev,
939 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000940 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000941 rx_rings = kcalloc(vsi->alloc_queue_pairs,
942 sizeof(struct i40e_ring), GFP_KERNEL);
943 if (!rx_rings) {
944 err = -ENOMEM;
945 goto free_tx;
946 }
947
948 for (i = 0; i < vsi->num_queue_pairs; i++) {
949 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000950 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000951 rx_rings[i].count = new_rx_count;
952 err = i40e_setup_rx_descriptors(&rx_rings[i]);
953 if (err) {
954 while (i) {
955 i--;
956 i40e_free_rx_resources(&rx_rings[i]);
957 }
958 kfree(rx_rings);
959 rx_rings = NULL;
960
961 goto free_tx;
962 }
963 }
964 }
965
966 /* Bring interface down, copy in the new ring info,
967 * then restore the interface
968 */
969 i40e_down(vsi);
970
971 if (tx_rings) {
972 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000973 i40e_free_tx_resources(vsi->tx_rings[i]);
974 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000975 }
976 kfree(tx_rings);
977 tx_rings = NULL;
978 }
979
980 if (rx_rings) {
981 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000982 i40e_free_rx_resources(vsi->rx_rings[i]);
983 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000984 }
985 kfree(rx_rings);
986 rx_rings = NULL;
987 }
988
989 i40e_up(vsi);
990
991free_tx:
992 /* error cleanup if the Rx allocations failed after getting Tx */
993 if (tx_rings) {
994 for (i = 0; i < vsi->num_queue_pairs; i++)
995 i40e_free_tx_resources(&tx_rings[i]);
996 kfree(tx_rings);
997 tx_rings = NULL;
998 }
999
1000done:
1001 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1002
1003 return err;
1004}
1005
1006static int i40e_get_sset_count(struct net_device *netdev, int sset)
1007{
1008 struct i40e_netdev_priv *np = netdev_priv(netdev);
1009 struct i40e_vsi *vsi = np->vsi;
1010 struct i40e_pf *pf = vsi->back;
1011
1012 switch (sset) {
1013 case ETH_SS_TEST:
1014 return I40E_TEST_LEN;
1015 case ETH_SS_STATS:
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001016 if (vsi == pf->vsi[pf->lan_vsi]) {
1017 int len = I40E_PF_STATS_LEN(netdev);
1018
1019 if (pf->lan_veb != I40E_NO_VEB)
1020 len += I40E_VEB_STATS_LEN;
1021 return len;
1022 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001023 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001024 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001025 default:
1026 return -EOPNOTSUPP;
1027 }
1028}
1029
1030static void i40e_get_ethtool_stats(struct net_device *netdev,
1031 struct ethtool_stats *stats, u64 *data)
1032{
1033 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001034 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001035 struct i40e_vsi *vsi = np->vsi;
1036 struct i40e_pf *pf = vsi->back;
1037 int i = 0;
1038 char *p;
1039 int j;
1040 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001041 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001042
1043 i40e_update_stats(vsi);
1044
1045 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1046 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1047 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1048 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1049 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001050 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1051 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1052 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1053 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1054 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001055 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001056 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001057 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001058
1059 if (!tx_ring)
1060 continue;
1061
1062 /* process Tx ring statistics */
1063 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001064 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001065 data[i] = tx_ring->stats.packets;
1066 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001067 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001068 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001069
1070 /* Rx ring is the 2nd half of the queue pair */
1071 rx_ring = &tx_ring[1];
1072 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001073 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001074 data[i] = rx_ring->stats.packets;
1075 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001076 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001077 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001078 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001079 rcu_read_unlock();
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001080 if (vsi != pf->vsi[pf->lan_vsi])
1081 return;
1082
1083 if (pf->lan_veb != I40E_NO_VEB) {
1084 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1085 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1086 p = (char *)veb;
1087 p += i40e_gstrings_veb_stats[j].stat_offset;
1088 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1089 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001090 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001091 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001092 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1093 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1094 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1095 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1096 }
1097 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1098 data[i++] = pf->stats.priority_xon_tx[j];
1099 data[i++] = pf->stats.priority_xoff_tx[j];
1100 }
1101 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1102 data[i++] = pf->stats.priority_xon_rx[j];
1103 data[i++] = pf->stats.priority_xoff_rx[j];
1104 }
1105 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1106 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001107}
1108
1109static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1110 u8 *data)
1111{
1112 struct i40e_netdev_priv *np = netdev_priv(netdev);
1113 struct i40e_vsi *vsi = np->vsi;
1114 struct i40e_pf *pf = vsi->back;
1115 char *p = (char *)data;
1116 int i;
1117
1118 switch (stringset) {
1119 case ETH_SS_TEST:
1120 for (i = 0; i < I40E_TEST_LEN; i++) {
1121 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1122 data += ETH_GSTRING_LEN;
1123 }
1124 break;
1125 case ETH_SS_STATS:
1126 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1127 snprintf(p, ETH_GSTRING_LEN, "%s",
1128 i40e_gstrings_net_stats[i].stat_string);
1129 p += ETH_GSTRING_LEN;
1130 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001131 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1132 snprintf(p, ETH_GSTRING_LEN, "%s",
1133 i40e_gstrings_misc_stats[i].stat_string);
1134 p += ETH_GSTRING_LEN;
1135 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001136 for (i = 0; i < vsi->num_queue_pairs; i++) {
1137 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1138 p += ETH_GSTRING_LEN;
1139 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1140 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001141 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1142 p += ETH_GSTRING_LEN;
1143 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1144 p += ETH_GSTRING_LEN;
1145 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001146 if (vsi != pf->vsi[pf->lan_vsi])
1147 return;
1148
1149 if (pf->lan_veb != I40E_NO_VEB) {
1150 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1151 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1152 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001153 p += ETH_GSTRING_LEN;
1154 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001155 }
1156 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1157 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1158 i40e_gstrings_stats[i].stat_string);
1159 p += ETH_GSTRING_LEN;
1160 }
1161 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1162 snprintf(p, ETH_GSTRING_LEN,
1163 "port.tx_priority_%u_xon", i);
1164 p += ETH_GSTRING_LEN;
1165 snprintf(p, ETH_GSTRING_LEN,
1166 "port.tx_priority_%u_xoff", i);
1167 p += ETH_GSTRING_LEN;
1168 }
1169 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1170 snprintf(p, ETH_GSTRING_LEN,
1171 "port.rx_priority_%u_xon", i);
1172 p += ETH_GSTRING_LEN;
1173 snprintf(p, ETH_GSTRING_LEN,
1174 "port.rx_priority_%u_xoff", i);
1175 p += ETH_GSTRING_LEN;
1176 }
1177 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1178 snprintf(p, ETH_GSTRING_LEN,
1179 "port.rx_priority_%u_xon_2_xoff", i);
1180 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001181 }
1182 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1183 break;
1184 }
1185}
1186
1187static int i40e_get_ts_info(struct net_device *dev,
1188 struct ethtool_ts_info *info)
1189{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001190 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1191
1192 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1193 SOF_TIMESTAMPING_RX_SOFTWARE |
1194 SOF_TIMESTAMPING_SOFTWARE |
1195 SOF_TIMESTAMPING_TX_HARDWARE |
1196 SOF_TIMESTAMPING_RX_HARDWARE |
1197 SOF_TIMESTAMPING_RAW_HARDWARE;
1198
1199 if (pf->ptp_clock)
1200 info->phc_index = ptp_clock_index(pf->ptp_clock);
1201 else
1202 info->phc_index = -1;
1203
1204 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1205
1206 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1207 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1208 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1209 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1210 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1211 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1212 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1213 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1214 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1215 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1216 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1217 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1218
1219 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001220}
1221
Shannon Nelson7b086392013-11-20 10:02:59 +00001222static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001223{
Shannon Nelson7b086392013-11-20 10:02:59 +00001224 struct i40e_netdev_priv *np = netdev_priv(netdev);
1225 struct i40e_pf *pf = np->vsi->back;
1226
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001227 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001228 if (i40e_get_link_status(&pf->hw))
1229 *data = 0;
1230 else
1231 *data = 1;
1232
1233 return *data;
1234}
1235
Shannon Nelson7b086392013-11-20 10:02:59 +00001236static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001237{
Shannon Nelson7b086392013-11-20 10:02:59 +00001238 struct i40e_netdev_priv *np = netdev_priv(netdev);
1239 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001240
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001241 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001242 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001243
Shannon Nelson7b086392013-11-20 10:02:59 +00001244 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001245}
1246
Shannon Nelson7b086392013-11-20 10:02:59 +00001247static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001248{
Shannon Nelson7b086392013-11-20 10:02:59 +00001249 struct i40e_netdev_priv *np = netdev_priv(netdev);
1250 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001251
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001252 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001253 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001254
Shannon Nelson7b086392013-11-20 10:02:59 +00001255 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001256}
1257
Shannon Nelson7b086392013-11-20 10:02:59 +00001258static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001259{
Shannon Nelson7b086392013-11-20 10:02:59 +00001260 struct i40e_netdev_priv *np = netdev_priv(netdev);
1261 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001262 u16 swc_old = pf->sw_int_count;
1263
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001264 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001265 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1266 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
1267 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
1268 usleep_range(1000, 2000);
1269 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001270
1271 return *data;
1272}
1273
Shannon Nelson7b086392013-11-20 10:02:59 +00001274static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001275{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001276 struct i40e_netdev_priv *np = netdev_priv(netdev);
1277 struct i40e_pf *pf = np->vsi->back;
1278
1279 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001280 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001281
1282 return *data;
1283}
1284
1285static void i40e_diag_test(struct net_device *netdev,
1286 struct ethtool_test *eth_test, u64 *data)
1287{
1288 struct i40e_netdev_priv *np = netdev_priv(netdev);
1289 struct i40e_pf *pf = np->vsi->back;
1290
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001291 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1292 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001293 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001294
Shannon Nelsonf551b432013-11-26 10:49:12 +00001295 set_bit(__I40E_TESTING, &pf->state);
1296
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001297 /* Link test performed before hardware reset
1298 * so autoneg doesn't interfere with test result
1299 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001300 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001301 eth_test->flags |= ETH_TEST_FL_FAILED;
1302
Shannon Nelson7b086392013-11-20 10:02:59 +00001303 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001304 eth_test->flags |= ETH_TEST_FL_FAILED;
1305
Shannon Nelson7b086392013-11-20 10:02:59 +00001306 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001307 eth_test->flags |= ETH_TEST_FL_FAILED;
1308
Shannon Nelson7b086392013-11-20 10:02:59 +00001309 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001310 eth_test->flags |= ETH_TEST_FL_FAILED;
1311
Shannon Nelsonf551b432013-11-26 10:49:12 +00001312 /* run reg test last, a reset is required after it */
1313 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1314 eth_test->flags |= ETH_TEST_FL_FAILED;
1315
1316 clear_bit(__I40E_TESTING, &pf->state);
1317 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001318 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001319 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001320 netif_info(pf, drv, netdev, "online testing starting\n");
1321
Shannon Nelson7b086392013-11-20 10:02:59 +00001322 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001323 eth_test->flags |= ETH_TEST_FL_FAILED;
1324
1325 /* Offline only tests, not run in online; pass by default */
1326 data[I40E_ETH_TEST_REG] = 0;
1327 data[I40E_ETH_TEST_EEPROM] = 0;
1328 data[I40E_ETH_TEST_INTR] = 0;
1329 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001330 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001331
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001332 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001333}
1334
1335static void i40e_get_wol(struct net_device *netdev,
1336 struct ethtool_wolinfo *wol)
1337{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001338 struct i40e_netdev_priv *np = netdev_priv(netdev);
1339 struct i40e_pf *pf = np->vsi->back;
1340 struct i40e_hw *hw = &pf->hw;
1341 u16 wol_nvm_bits;
1342
1343 /* NVM bit on means WoL disabled for the port */
1344 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1345 if ((1 << hw->port) & wol_nvm_bits) {
1346 wol->supported = 0;
1347 wol->wolopts = 0;
1348 } else {
1349 wol->supported = WAKE_MAGIC;
1350 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1351 }
1352}
1353
1354static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1355{
1356 struct i40e_netdev_priv *np = netdev_priv(netdev);
1357 struct i40e_pf *pf = np->vsi->back;
1358 struct i40e_hw *hw = &pf->hw;
1359 u16 wol_nvm_bits;
1360
1361 /* NVM bit on means WoL disabled for the port */
1362 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1363 if (((1 << hw->port) & wol_nvm_bits))
1364 return -EOPNOTSUPP;
1365
1366 /* only magic packet is supported */
1367 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1368 return -EOPNOTSUPP;
1369
1370 /* is this a new value? */
1371 if (pf->wol_en != !!wol->wolopts) {
1372 pf->wol_en = !!wol->wolopts;
1373 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1374 }
1375
1376 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001377}
1378
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001379static int i40e_set_phys_id(struct net_device *netdev,
1380 enum ethtool_phys_id_state state)
1381{
1382 struct i40e_netdev_priv *np = netdev_priv(netdev);
1383 struct i40e_pf *pf = np->vsi->back;
1384 struct i40e_hw *hw = &pf->hw;
1385 int blink_freq = 2;
1386
1387 switch (state) {
1388 case ETHTOOL_ID_ACTIVE:
1389 pf->led_status = i40e_led_get(hw);
1390 return blink_freq;
1391 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001392 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001393 break;
1394 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001395 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001396 break;
1397 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001398 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001399 break;
1400 }
1401
1402 return 0;
1403}
1404
1405/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1406 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1407 * 125us (8000 interrupts per second) == ITR(62)
1408 */
1409
1410static int i40e_get_coalesce(struct net_device *netdev,
1411 struct ethtool_coalesce *ec)
1412{
1413 struct i40e_netdev_priv *np = netdev_priv(netdev);
1414 struct i40e_vsi *vsi = np->vsi;
1415
1416 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1417 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1418
1419 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001420 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001421
1422 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001423 ec->use_adaptive_tx_coalesce = 1;
1424
1425 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1426 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001427
1428 return 0;
1429}
1430
1431static int i40e_set_coalesce(struct net_device *netdev,
1432 struct ethtool_coalesce *ec)
1433{
1434 struct i40e_netdev_priv *np = netdev_priv(netdev);
1435 struct i40e_q_vector *q_vector;
1436 struct i40e_vsi *vsi = np->vsi;
1437 struct i40e_pf *pf = vsi->back;
1438 struct i40e_hw *hw = &pf->hw;
1439 u16 vector;
1440 int i;
1441
1442 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1443 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1444
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001445 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001446 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001447 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001448 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001449 } else if (ec->rx_coalesce_usecs == 0) {
1450 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1451 i40e_irq_dynamic_disable(vsi, vector);
1452 if (ec->use_adaptive_rx_coalesce)
1453 netif_info(pf, drv, netdev,
1454 "Rx-secs=0, need to disable adaptive-Rx for a complete disable\n");
1455 } else {
1456 netif_info(pf, drv, netdev,
1457 "Invalid value, Rx-usecs range is 0, 8-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001458 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001459 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001460
Mitch Williams32f5f542014-04-04 04:43:10 +00001461 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001462 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001463 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001464 } else if (ec->tx_coalesce_usecs == 0) {
1465 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1466 i40e_irq_dynamic_disable(vsi, vector);
1467 if (ec->use_adaptive_tx_coalesce)
1468 netif_info(pf, drv, netdev,
1469 "Tx-secs=0, need to disable adaptive-Tx for a complete disable\n");
1470 } else {
1471 netif_info(pf, drv, netdev,
1472 "Invalid value, Tx-usecs range is 0, 8-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001473 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001474 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001475
1476 if (ec->use_adaptive_rx_coalesce)
1477 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1478 else
1479 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1480
1481 if (ec->use_adaptive_tx_coalesce)
1482 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1483 else
1484 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001485
Alexander Duyck493fb302013-09-28 07:01:44 +00001486 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1487 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001488 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1489 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1490 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1491 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1492 i40e_flush(hw);
1493 }
1494
1495 return 0;
1496}
1497
1498/**
1499 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1500 * @pf: pointer to the physical function struct
1501 * @cmd: ethtool rxnfc command
1502 *
1503 * Returns Success if the flow is supported, else Invalid Input.
1504 **/
1505static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1506{
1507 cmd->data = 0;
1508
1509 /* Report default options for RSS on i40e */
1510 switch (cmd->flow_type) {
1511 case TCP_V4_FLOW:
1512 case UDP_V4_FLOW:
1513 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1514 /* fall through to add IP fields */
1515 case SCTP_V4_FLOW:
1516 case AH_ESP_V4_FLOW:
1517 case AH_V4_FLOW:
1518 case ESP_V4_FLOW:
1519 case IPV4_FLOW:
1520 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1521 break;
1522 case TCP_V6_FLOW:
1523 case UDP_V6_FLOW:
1524 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1525 /* fall through to add IP fields */
1526 case SCTP_V6_FLOW:
1527 case AH_ESP_V6_FLOW:
1528 case AH_V6_FLOW:
1529 case ESP_V6_FLOW:
1530 case IPV6_FLOW:
1531 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1532 break;
1533 default:
1534 return -EINVAL;
1535 }
1536
1537 return 0;
1538}
1539
1540/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001541 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1542 * @pf: Pointer to the physical function struct
1543 * @cmd: The command to get or set Rx flow classification rules
1544 * @rule_locs: Array of used rule locations
1545 *
1546 * This function populates both the total and actual rule count of
1547 * the ethtool flow classification command
1548 *
1549 * Returns 0 on success or -EMSGSIZE if entry not found
1550 **/
1551static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1552 struct ethtool_rxnfc *cmd,
1553 u32 *rule_locs)
1554{
1555 struct i40e_fdir_filter *rule;
1556 struct hlist_node *node2;
1557 int cnt = 0;
1558
1559 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001560 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001561
1562 hlist_for_each_entry_safe(rule, node2,
1563 &pf->fdir_filter_list, fdir_node) {
1564 if (cnt == cmd->rule_cnt)
1565 return -EMSGSIZE;
1566
1567 rule_locs[cnt] = rule->fd_id;
1568 cnt++;
1569 }
1570
1571 cmd->rule_cnt = cnt;
1572
1573 return 0;
1574}
1575
1576/**
1577 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1578 * @pf: Pointer to the physical function struct
1579 * @cmd: The command to get or set Rx flow classification rules
1580 *
1581 * This function looks up a filter based on the Rx flow classification
1582 * command and fills the flow spec info for it if found
1583 *
1584 * Returns 0 on success or -EINVAL if filter not found
1585 **/
1586static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1587 struct ethtool_rxnfc *cmd)
1588{
1589 struct ethtool_rx_flow_spec *fsp =
1590 (struct ethtool_rx_flow_spec *)&cmd->fs;
1591 struct i40e_fdir_filter *rule = NULL;
1592 struct hlist_node *node2;
1593
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001594 hlist_for_each_entry_safe(rule, node2,
1595 &pf->fdir_filter_list, fdir_node) {
1596 if (fsp->location <= rule->fd_id)
1597 break;
1598 }
1599
1600 if (!rule || fsp->location != rule->fd_id)
1601 return -EINVAL;
1602
1603 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001604 if (fsp->flow_type == IP_USER_FLOW) {
1605 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1606 fsp->h_u.usr_ip4_spec.proto = 0;
1607 fsp->m_u.usr_ip4_spec.proto = 0;
1608 }
1609
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001610 /* Reverse the src and dest notion, since the HW views them from
1611 * Tx perspective where as the user expects it from Rx filter view.
1612 */
1613 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1614 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1615 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1616 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001617
1618 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1619 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1620 else
1621 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001622
1623 return 0;
1624}
1625
1626/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001627 * i40e_get_rxnfc - command to get RX flow classification rules
1628 * @netdev: network interface device structure
1629 * @cmd: ethtool rxnfc command
1630 *
1631 * Returns Success if the command is supported.
1632 **/
1633static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1634 u32 *rule_locs)
1635{
1636 struct i40e_netdev_priv *np = netdev_priv(netdev);
1637 struct i40e_vsi *vsi = np->vsi;
1638 struct i40e_pf *pf = vsi->back;
1639 int ret = -EOPNOTSUPP;
1640
1641 switch (cmd->cmd) {
1642 case ETHTOOL_GRXRINGS:
1643 cmd->data = vsi->alloc_queue_pairs;
1644 ret = 0;
1645 break;
1646 case ETHTOOL_GRXFH:
1647 ret = i40e_get_rss_hash_opts(pf, cmd);
1648 break;
1649 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001650 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001651 /* report total rule count */
1652 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001653 ret = 0;
1654 break;
1655 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001656 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001657 break;
1658 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001659 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1660 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001661 default:
1662 break;
1663 }
1664
1665 return ret;
1666}
1667
1668/**
1669 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1670 * @pf: pointer to the physical function struct
1671 * @cmd: ethtool rxnfc command
1672 *
1673 * Returns Success if the flow input set is supported.
1674 **/
1675static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1676{
1677 struct i40e_hw *hw = &pf->hw;
1678 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1679 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1680
1681 /* RSS does not support anything other than hashing
1682 * to queues on src and dst IPs and ports
1683 */
1684 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1685 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1686 return -EINVAL;
1687
1688 /* We need at least the IP SRC and DEST fields for hashing */
1689 if (!(nfc->data & RXH_IP_SRC) ||
1690 !(nfc->data & RXH_IP_DST))
1691 return -EINVAL;
1692
1693 switch (nfc->flow_type) {
1694 case TCP_V4_FLOW:
1695 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1696 case 0:
1697 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1698 break;
1699 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1700 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1701 break;
1702 default:
1703 return -EINVAL;
1704 }
1705 break;
1706 case TCP_V6_FLOW:
1707 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1708 case 0:
1709 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1710 break;
1711 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1712 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1713 break;
1714 default:
1715 return -EINVAL;
1716 }
1717 break;
1718 case UDP_V4_FLOW:
1719 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1720 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001721 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1722 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001723 break;
1724 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001725 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1726 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001727 break;
1728 default:
1729 return -EINVAL;
1730 }
1731 break;
1732 case UDP_V6_FLOW:
1733 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1734 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001735 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1736 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001737 break;
1738 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001739 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1740 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001741 break;
1742 default:
1743 return -EINVAL;
1744 }
1745 break;
1746 case AH_ESP_V4_FLOW:
1747 case AH_V4_FLOW:
1748 case ESP_V4_FLOW:
1749 case SCTP_V4_FLOW:
1750 if ((nfc->data & RXH_L4_B_0_1) ||
1751 (nfc->data & RXH_L4_B_2_3))
1752 return -EINVAL;
1753 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1754 break;
1755 case AH_ESP_V6_FLOW:
1756 case AH_V6_FLOW:
1757 case ESP_V6_FLOW:
1758 case SCTP_V6_FLOW:
1759 if ((nfc->data & RXH_L4_B_0_1) ||
1760 (nfc->data & RXH_L4_B_2_3))
1761 return -EINVAL;
1762 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1763 break;
1764 case IPV4_FLOW:
1765 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1766 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1767 break;
1768 case IPV6_FLOW:
1769 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1770 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1771 break;
1772 default:
1773 return -EINVAL;
1774 }
1775
1776 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1777 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1778 i40e_flush(hw);
1779
1780 return 0;
1781}
1782
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001783/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001784 * i40e_match_fdir_input_set - Match a new filter against an existing one
1785 * @rule: The filter already added
1786 * @input: The new filter to comapre against
1787 *
1788 * Returns true if the two input set match
1789 **/
1790static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1791 struct i40e_fdir_filter *input)
1792{
1793 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1794 (rule->src_ip[0] != input->src_ip[0]) ||
1795 (rule->dst_port != input->dst_port) ||
1796 (rule->src_port != input->src_port))
1797 return false;
1798 return true;
1799}
1800
1801/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001802 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1803 * @vsi: Pointer to the targeted VSI
1804 * @input: The filter to update or NULL to indicate deletion
1805 * @sw_idx: Software index to the filter
1806 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001807 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001808 * This function updates (or deletes) a Flow Director entry from
1809 * the hlist of the corresponding PF
1810 *
1811 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001812 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001813static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1814 struct i40e_fdir_filter *input,
1815 u16 sw_idx,
1816 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001817{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001818 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001819 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001820 struct hlist_node *node2;
1821 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001822
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001823 parent = NULL;
1824 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001825
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001826 hlist_for_each_entry_safe(rule, node2,
1827 &pf->fdir_filter_list, fdir_node) {
1828 /* hash found, or no matching entry */
1829 if (rule->fd_id >= sw_idx)
1830 break;
1831 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001832 }
1833
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001834 /* if there is an old rule occupying our place remove it */
1835 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001836 if (input && !i40e_match_fdir_input_set(rule, input))
1837 err = i40e_add_del_fdir(vsi, rule, false);
1838 else if (!input)
1839 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001840 hlist_del(&rule->fdir_node);
1841 kfree(rule);
1842 pf->fdir_pf_active_filters--;
1843 }
1844
1845 /* If no input this was a delete, err should be 0 if a rule was
1846 * successfully found and removed from the list else -EINVAL
1847 */
1848 if (!input)
1849 return err;
1850
1851 /* initialize node and set software index */
1852 INIT_HLIST_NODE(&input->fdir_node);
1853
1854 /* add filter to the list */
1855 if (parent)
1856 hlist_add_after(&parent->fdir_node, &input->fdir_node);
1857 else
1858 hlist_add_head(&input->fdir_node,
1859 &pf->fdir_filter_list);
1860
1861 /* update counts */
1862 pf->fdir_pf_active_filters++;
1863
1864 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001865}
1866
1867/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001868 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
1869 * @vsi: Pointer to the targeted VSI
1870 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001871 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001872 * The function removes a Flow Director filter entry from the
1873 * hlist of the corresponding PF
1874 *
1875 * Returns 0 on success
1876 */
1877static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
1878 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001879{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001880 struct ethtool_rx_flow_spec *fsp =
1881 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001882 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001883 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001884
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001885 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001886
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001887 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001888 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001889}
1890
1891/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001892 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001893 * @vsi: pointer to the targeted VSI
1894 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001895 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001896 * Add Flow Director filters for a specific flow spec based on their
1897 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001898 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001899static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
1900 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001901{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001902 struct ethtool_rx_flow_spec *fsp;
1903 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001904 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001905 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001906
1907 if (!vsi)
1908 return -EINVAL;
1909
1910 pf = vsi->back;
1911
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001912 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
1913 return -EOPNOTSUPP;
1914
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001915 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001916 return -ENOSPC;
1917
1918 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
1919
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001920 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
1921 pf->hw.func_caps.fd_filters_guaranteed)) {
1922 return -EINVAL;
1923 }
1924
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001925 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
1926 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001927 return -EINVAL;
1928
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001929 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001930
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001931 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001932 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001933
1934 input->fd_id = fsp->location;
1935
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00001936 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
1937 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
1938 else
1939 input->dest_ctl =
1940 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
1941
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001942 input->q_index = fsp->ring_cookie;
1943 input->flex_off = 0;
1944 input->pctype = 0;
1945 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001946 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001947 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001948 input->flow_type = fsp->flow_type;
1949 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001950
1951 /* Reverse the src and dest notion, since the HW expects them to be from
1952 * Tx perspective where as the input from user is from Rx filter view.
1953 */
1954 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
1955 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
1956 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
1957 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001958
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001959 ret = i40e_add_del_fdir(vsi, input, true);
1960 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001961 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001962 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001963 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001964
1965 return ret;
1966}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08001967
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001968/**
1969 * i40e_set_rxnfc - command to set RX flow classification rules
1970 * @netdev: network interface device structure
1971 * @cmd: ethtool rxnfc command
1972 *
1973 * Returns Success if the command is supported.
1974 **/
1975static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1976{
1977 struct i40e_netdev_priv *np = netdev_priv(netdev);
1978 struct i40e_vsi *vsi = np->vsi;
1979 struct i40e_pf *pf = vsi->back;
1980 int ret = -EOPNOTSUPP;
1981
1982 switch (cmd->cmd) {
1983 case ETHTOOL_SRXFH:
1984 ret = i40e_set_rss_hash_opt(pf, cmd);
1985 break;
1986 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001987 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001988 break;
1989 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001990 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001991 break;
1992 default:
1993 break;
1994 }
1995
1996 return ret;
1997}
1998
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001999/**
2000 * i40e_max_channels - get Max number of combined channels supported
2001 * @vsi: vsi pointer
2002 **/
2003static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2004{
2005 /* TODO: This code assumes DCB and FD is disabled for now. */
2006 return vsi->alloc_queue_pairs;
2007}
2008
2009/**
2010 * i40e_get_channels - Get the current channels enabled and max supported etc.
2011 * @netdev: network interface device structure
2012 * @ch: ethtool channels structure
2013 *
2014 * We don't support separate tx and rx queues as channels. The other count
2015 * represents how many queues are being used for control. max_combined counts
2016 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2017 * q_vectors since we support a lot more queue pairs than q_vectors.
2018 **/
2019static void i40e_get_channels(struct net_device *dev,
2020 struct ethtool_channels *ch)
2021{
2022 struct i40e_netdev_priv *np = netdev_priv(dev);
2023 struct i40e_vsi *vsi = np->vsi;
2024 struct i40e_pf *pf = vsi->back;
2025
2026 /* report maximum channels */
2027 ch->max_combined = i40e_max_channels(vsi);
2028
2029 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002030 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002031 ch->max_other = ch->other_count;
2032
2033 /* Note: This code assumes DCB is disabled for now. */
2034 ch->combined_count = vsi->num_queue_pairs;
2035}
2036
2037/**
2038 * i40e_set_channels - Set the new channels count.
2039 * @netdev: network interface device structure
2040 * @ch: ethtool channels structure
2041 *
2042 * The new channels count may not be the same as requested by the user
2043 * since it gets rounded down to a power of 2 value.
2044 **/
2045static int i40e_set_channels(struct net_device *dev,
2046 struct ethtool_channels *ch)
2047{
2048 struct i40e_netdev_priv *np = netdev_priv(dev);
2049 unsigned int count = ch->combined_count;
2050 struct i40e_vsi *vsi = np->vsi;
2051 struct i40e_pf *pf = vsi->back;
2052 int new_count;
2053
2054 /* We do not support setting channels for any other VSI at present */
2055 if (vsi->type != I40E_VSI_MAIN)
2056 return -EINVAL;
2057
2058 /* verify they are not requesting separate vectors */
2059 if (!count || ch->rx_count || ch->tx_count)
2060 return -EINVAL;
2061
2062 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002063 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002064 return -EINVAL;
2065
2066 /* verify the number of channels does not exceed hardware limits */
2067 if (count > i40e_max_channels(vsi))
2068 return -EINVAL;
2069
2070 /* update feature limits from largest to smallest supported values */
2071 /* TODO: Flow director limit, DCB etc */
2072
2073 /* cap RSS limit */
2074 if (count > pf->rss_size_max)
2075 count = pf->rss_size_max;
2076
2077 /* use rss_reconfig to rebuild with new queue count and update traffic
2078 * class queue mapping
2079 */
2080 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002081 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002082 return 0;
2083 else
2084 return -EINVAL;
2085}
2086
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002087static const struct ethtool_ops i40e_ethtool_ops = {
2088 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002089 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002090 .get_drvinfo = i40e_get_drvinfo,
2091 .get_regs_len = i40e_get_regs_len,
2092 .get_regs = i40e_get_regs,
2093 .nway_reset = i40e_nway_reset,
2094 .get_link = ethtool_op_get_link,
2095 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002096 .set_wol = i40e_set_wol,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002097 .get_eeprom_len = i40e_get_eeprom_len,
2098 .get_eeprom = i40e_get_eeprom,
2099 .get_ringparam = i40e_get_ringparam,
2100 .set_ringparam = i40e_set_ringparam,
2101 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002102 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002103 .get_msglevel = i40e_get_msglevel,
2104 .set_msglevel = i40e_set_msglevel,
2105 .get_rxnfc = i40e_get_rxnfc,
2106 .set_rxnfc = i40e_set_rxnfc,
2107 .self_test = i40e_diag_test,
2108 .get_strings = i40e_get_strings,
2109 .set_phys_id = i40e_set_phys_id,
2110 .get_sset_count = i40e_get_sset_count,
2111 .get_ethtool_stats = i40e_get_ethtool_stats,
2112 .get_coalesce = i40e_get_coalesce,
2113 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002114 .get_channels = i40e_get_channels,
2115 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002116 .get_ts_info = i40e_get_ts_info,
2117};
2118
2119void i40e_set_ethtool_ops(struct net_device *netdev)
2120{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002121 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002122}