blob: fc86761950d0fd01fd376df6804dc20c670ddca3 [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
Jesse Brandeburga6599722014-06-04 08:45:25 +0000415static int i40e_nway_reset(struct net_device *netdev)
416{
417 /* restart autonegotiation */
418 struct i40e_netdev_priv *np = netdev_priv(netdev);
419 struct i40e_pf *pf = np->vsi->back;
420 struct i40e_hw *hw = &pf->hw;
421 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
422 i40e_status ret = 0;
423
424 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
425 if (ret) {
426 netdev_info(netdev, "link restart failed, aq_err=%d\n",
427 pf->hw.aq.asq_last_status);
428 return -EIO;
429 }
430
431 return 0;
432}
433
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000434/**
435 * i40e_get_pauseparam - Get Flow Control status
436 * Return tx/rx-pause status
437 **/
438static void i40e_get_pauseparam(struct net_device *netdev,
439 struct ethtool_pauseparam *pause)
440{
441 struct i40e_netdev_priv *np = netdev_priv(netdev);
442 struct i40e_pf *pf = np->vsi->back;
443 struct i40e_hw *hw = &pf->hw;
444 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
445
446 pause->autoneg =
447 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
448 AUTONEG_ENABLE : AUTONEG_DISABLE);
449
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000450 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000451 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000452 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000453 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000454 } else if (hw->fc.current_mode == I40E_FC_FULL) {
455 pause->rx_pause = 1;
456 pause->tx_pause = 1;
457 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000458}
459
Catherine Sullivan2becc352014-06-04 08:45:27 +0000460/**
461 * i40e_set_pauseparam - Set Flow Control parameter
462 * @netdev: network interface device structure
463 * @pause: return tx/rx flow control status
464 **/
465static int i40e_set_pauseparam(struct net_device *netdev,
466 struct ethtool_pauseparam *pause)
467{
468 struct i40e_netdev_priv *np = netdev_priv(netdev);
469 struct i40e_pf *pf = np->vsi->back;
470 struct i40e_vsi *vsi = np->vsi;
471 struct i40e_hw *hw = &pf->hw;
472 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
473 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
474 i40e_status status;
475 u8 aq_failures;
476 int err;
477
478 if (vsi != pf->vsi[pf->lan_vsi])
479 return -EOPNOTSUPP;
480
481 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
482 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
483 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
484 return -EOPNOTSUPP;
485 }
486
487 /* If we have link and don't have autoneg */
488 if (!test_bit(__I40E_DOWN, &pf->state) &&
489 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
490 /* Send message that it might not necessarily work*/
491 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
492 }
493
494 if (hw->fc.current_mode == I40E_FC_PFC) {
495 netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
496 return -EOPNOTSUPP;
497 }
498
499 if (pause->rx_pause && pause->tx_pause)
500 hw->fc.requested_mode = I40E_FC_FULL;
501 else if (pause->rx_pause && !pause->tx_pause)
502 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
503 else if (!pause->rx_pause && pause->tx_pause)
504 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
505 else if (!pause->rx_pause && !pause->tx_pause)
506 hw->fc.requested_mode = I40E_FC_NONE;
507 else
508 return -EINVAL;
509
510 /* Set the fc mode and only restart an if link is up*/
511 status = i40e_set_fc(hw, &aq_failures, link_up);
512
513 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
514 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
515 status, hw->aq.asq_last_status);
516 err = -EAGAIN;
517 }
518 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
519 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
520 status, hw->aq.asq_last_status);
521 err = -EAGAIN;
522 }
523 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
524 netdev_info(netdev, "Set fc failed on the update_link_info call with error %d and status %d\n",
525 status, hw->aq.asq_last_status);
526 err = -EAGAIN;
527 }
528
529 if (!test_bit(__I40E_DOWN, &pf->state))
530 return i40e_nway_reset(netdev);
531
532 return err;
533}
534
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000535static u32 i40e_get_msglevel(struct net_device *netdev)
536{
537 struct i40e_netdev_priv *np = netdev_priv(netdev);
538 struct i40e_pf *pf = np->vsi->back;
539
540 return pf->msg_enable;
541}
542
543static void i40e_set_msglevel(struct net_device *netdev, u32 data)
544{
545 struct i40e_netdev_priv *np = netdev_priv(netdev);
546 struct i40e_pf *pf = np->vsi->back;
547
548 if (I40E_DEBUG_USER & data)
549 pf->hw.debug_mask = data;
550 pf->msg_enable = data;
551}
552
553static int i40e_get_regs_len(struct net_device *netdev)
554{
555 int reg_count = 0;
556 int i;
557
558 for (i = 0; i40e_reg_list[i].offset != 0; i++)
559 reg_count += i40e_reg_list[i].elements;
560
561 return reg_count * sizeof(u32);
562}
563
564static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
565 void *p)
566{
567 struct i40e_netdev_priv *np = netdev_priv(netdev);
568 struct i40e_pf *pf = np->vsi->back;
569 struct i40e_hw *hw = &pf->hw;
570 u32 *reg_buf = p;
571 int i, j, ri;
572 u32 reg;
573
574 /* Tell ethtool which driver-version-specific regs output we have.
575 *
576 * At some point, if we have ethtool doing special formatting of
577 * this data, it will rely on this version number to know how to
578 * interpret things. Hence, this needs to be updated if/when the
579 * diags register table is changed.
580 */
581 regs->version = 1;
582
583 /* loop through the diags reg table for what to print */
584 ri = 0;
585 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
586 for (j = 0; j < i40e_reg_list[i].elements; j++) {
587 reg = i40e_reg_list[i].offset
588 + (j * i40e_reg_list[i].stride);
589 reg_buf[ri++] = rd32(hw, reg);
590 }
591 }
592
593}
594
595static int i40e_get_eeprom(struct net_device *netdev,
596 struct ethtool_eeprom *eeprom, u8 *bytes)
597{
598 struct i40e_netdev_priv *np = netdev_priv(netdev);
599 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000600 struct i40e_pf *pf = np->vsi->back;
601 int ret_val = 0, len;
602 u8 *eeprom_buff;
603 u16 i, sectors;
604 bool last;
605#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000606 if (eeprom->len == 0)
607 return -EINVAL;
608
609 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
610
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000611 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000612 if (!eeprom_buff)
613 return -ENOMEM;
614
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000615 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
616 if (ret_val) {
617 dev_info(&pf->pdev->dev,
618 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
619 ret_val, hw->aq.asq_last_status);
620 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000621 }
622
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000623 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
624 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
625 len = I40E_NVM_SECTOR_SIZE;
626 last = false;
627 for (i = 0; i < sectors; i++) {
628 if (i == (sectors - 1)) {
629 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
630 last = true;
631 }
632 ret_val = i40e_aq_read_nvm(hw, 0x0,
633 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
634 len,
Joe Perches3dbb7fd2014-03-25 04:30:38 +0000635 eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000636 last, NULL);
637 if (ret_val) {
638 dev_info(&pf->pdev->dev,
639 "read NVM failed err=%d status=0x%x\n",
640 ret_val, hw->aq.asq_last_status);
641 goto release_nvm;
642 }
643 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000644
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000645release_nvm:
646 i40e_release_nvm(hw);
Joe Perches3dbb7fd2014-03-25 04:30:38 +0000647 memcpy(bytes, eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000648free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000649 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000650 return ret_val;
651}
652
653static int i40e_get_eeprom_len(struct net_device *netdev)
654{
655 struct i40e_netdev_priv *np = netdev_priv(netdev);
656 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000657 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000658
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000659 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
660 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
661 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
662 /* register returns value in power of 2, 64Kbyte chunks. */
663 val = (64 * 1024) * (1 << val);
664 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000665}
666
667static void i40e_get_drvinfo(struct net_device *netdev,
668 struct ethtool_drvinfo *drvinfo)
669{
670 struct i40e_netdev_priv *np = netdev_priv(netdev);
671 struct i40e_vsi *vsi = np->vsi;
672 struct i40e_pf *pf = vsi->back;
673
674 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
675 strlcpy(drvinfo->version, i40e_driver_version_str,
676 sizeof(drvinfo->version));
677 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
678 sizeof(drvinfo->fw_version));
679 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
680 sizeof(drvinfo->bus_info));
681}
682
683static void i40e_get_ringparam(struct net_device *netdev,
684 struct ethtool_ringparam *ring)
685{
686 struct i40e_netdev_priv *np = netdev_priv(netdev);
687 struct i40e_pf *pf = np->vsi->back;
688 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
689
690 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
691 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
692 ring->rx_mini_max_pending = 0;
693 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +0000694 ring->rx_pending = vsi->rx_rings[0]->count;
695 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000696 ring->rx_mini_pending = 0;
697 ring->rx_jumbo_pending = 0;
698}
699
700static int i40e_set_ringparam(struct net_device *netdev,
701 struct ethtool_ringparam *ring)
702{
703 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
704 struct i40e_netdev_priv *np = netdev_priv(netdev);
705 struct i40e_vsi *vsi = np->vsi;
706 struct i40e_pf *pf = vsi->back;
707 u32 new_rx_count, new_tx_count;
708 int i, err = 0;
709
710 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
711 return -EINVAL;
712
Shannon Nelson1fa18372013-11-20 10:03:08 +0000713 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
714 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
715 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
716 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
717 netdev_info(netdev,
718 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
719 ring->tx_pending, ring->rx_pending,
720 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
721 return -EINVAL;
722 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000723
Shannon Nelson1fa18372013-11-20 10:03:08 +0000724 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
725 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000726
727 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000728 if ((new_tx_count == vsi->tx_rings[0]->count) &&
729 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000730 return 0;
731
732 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
733 usleep_range(1000, 2000);
734
735 if (!netif_running(vsi->netdev)) {
736 /* simple case - set for the next time the netdev is started */
737 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000738 vsi->tx_rings[i]->count = new_tx_count;
739 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000740 }
741 goto done;
742 }
743
744 /* We can't just free everything and then setup again,
745 * because the ISRs in MSI-X mode get passed pointers
746 * to the Tx and Rx ring structs.
747 */
748
749 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000750 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000751 netdev_info(netdev,
752 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000753 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000754 tx_rings = kcalloc(vsi->alloc_queue_pairs,
755 sizeof(struct i40e_ring), GFP_KERNEL);
756 if (!tx_rings) {
757 err = -ENOMEM;
758 goto done;
759 }
760
761 for (i = 0; i < vsi->num_queue_pairs; i++) {
762 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000763 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000764 tx_rings[i].count = new_tx_count;
765 err = i40e_setup_tx_descriptors(&tx_rings[i]);
766 if (err) {
767 while (i) {
768 i--;
769 i40e_free_tx_resources(&tx_rings[i]);
770 }
771 kfree(tx_rings);
772 tx_rings = NULL;
773
774 goto done;
775 }
776 }
777 }
778
779 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000780 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000781 netdev_info(netdev,
782 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000783 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000784 rx_rings = kcalloc(vsi->alloc_queue_pairs,
785 sizeof(struct i40e_ring), GFP_KERNEL);
786 if (!rx_rings) {
787 err = -ENOMEM;
788 goto free_tx;
789 }
790
791 for (i = 0; i < vsi->num_queue_pairs; i++) {
792 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000793 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000794 rx_rings[i].count = new_rx_count;
795 err = i40e_setup_rx_descriptors(&rx_rings[i]);
796 if (err) {
797 while (i) {
798 i--;
799 i40e_free_rx_resources(&rx_rings[i]);
800 }
801 kfree(rx_rings);
802 rx_rings = NULL;
803
804 goto free_tx;
805 }
806 }
807 }
808
809 /* Bring interface down, copy in the new ring info,
810 * then restore the interface
811 */
812 i40e_down(vsi);
813
814 if (tx_rings) {
815 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000816 i40e_free_tx_resources(vsi->tx_rings[i]);
817 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000818 }
819 kfree(tx_rings);
820 tx_rings = NULL;
821 }
822
823 if (rx_rings) {
824 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000825 i40e_free_rx_resources(vsi->rx_rings[i]);
826 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000827 }
828 kfree(rx_rings);
829 rx_rings = NULL;
830 }
831
832 i40e_up(vsi);
833
834free_tx:
835 /* error cleanup if the Rx allocations failed after getting Tx */
836 if (tx_rings) {
837 for (i = 0; i < vsi->num_queue_pairs; i++)
838 i40e_free_tx_resources(&tx_rings[i]);
839 kfree(tx_rings);
840 tx_rings = NULL;
841 }
842
843done:
844 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
845
846 return err;
847}
848
849static int i40e_get_sset_count(struct net_device *netdev, int sset)
850{
851 struct i40e_netdev_priv *np = netdev_priv(netdev);
852 struct i40e_vsi *vsi = np->vsi;
853 struct i40e_pf *pf = vsi->back;
854
855 switch (sset) {
856 case ETH_SS_TEST:
857 return I40E_TEST_LEN;
858 case ETH_SS_STATS:
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000859 if (vsi == pf->vsi[pf->lan_vsi]) {
860 int len = I40E_PF_STATS_LEN(netdev);
861
862 if (pf->lan_veb != I40E_NO_VEB)
863 len += I40E_VEB_STATS_LEN;
864 return len;
865 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000866 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000867 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000868 default:
869 return -EOPNOTSUPP;
870 }
871}
872
873static void i40e_get_ethtool_stats(struct net_device *netdev,
874 struct ethtool_stats *stats, u64 *data)
875{
876 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +0000877 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000878 struct i40e_vsi *vsi = np->vsi;
879 struct i40e_pf *pf = vsi->back;
880 int i = 0;
881 char *p;
882 int j;
883 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000884 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000885
886 i40e_update_stats(vsi);
887
888 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
889 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
890 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
891 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
892 }
Shannon Nelson41a9e552014-04-23 04:50:20 +0000893 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
894 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
895 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
896 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
897 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000898 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000899 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +0000900 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000901
902 if (!tx_ring)
903 continue;
904
905 /* process Tx ring statistics */
906 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700907 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000908 data[i] = tx_ring->stats.packets;
909 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700910 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000911 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000912
913 /* Rx ring is the 2nd half of the queue pair */
914 rx_ring = &tx_ring[1];
915 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700916 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000917 data[i] = rx_ring->stats.packets;
918 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700919 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000920 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000921 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000922 rcu_read_unlock();
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000923 if (vsi != pf->vsi[pf->lan_vsi])
924 return;
925
926 if (pf->lan_veb != I40E_NO_VEB) {
927 struct i40e_veb *veb = pf->veb[pf->lan_veb];
928 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
929 p = (char *)veb;
930 p += i40e_gstrings_veb_stats[j].stat_offset;
931 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
932 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000933 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000934 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000935 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
936 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
937 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
938 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
939 }
940 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
941 data[i++] = pf->stats.priority_xon_tx[j];
942 data[i++] = pf->stats.priority_xoff_tx[j];
943 }
944 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
945 data[i++] = pf->stats.priority_xon_rx[j];
946 data[i++] = pf->stats.priority_xoff_rx[j];
947 }
948 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
949 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000950}
951
952static void i40e_get_strings(struct net_device *netdev, u32 stringset,
953 u8 *data)
954{
955 struct i40e_netdev_priv *np = netdev_priv(netdev);
956 struct i40e_vsi *vsi = np->vsi;
957 struct i40e_pf *pf = vsi->back;
958 char *p = (char *)data;
959 int i;
960
961 switch (stringset) {
962 case ETH_SS_TEST:
963 for (i = 0; i < I40E_TEST_LEN; i++) {
964 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
965 data += ETH_GSTRING_LEN;
966 }
967 break;
968 case ETH_SS_STATS:
969 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
970 snprintf(p, ETH_GSTRING_LEN, "%s",
971 i40e_gstrings_net_stats[i].stat_string);
972 p += ETH_GSTRING_LEN;
973 }
Shannon Nelson41a9e552014-04-23 04:50:20 +0000974 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
975 snprintf(p, ETH_GSTRING_LEN, "%s",
976 i40e_gstrings_misc_stats[i].stat_string);
977 p += ETH_GSTRING_LEN;
978 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000979 for (i = 0; i < vsi->num_queue_pairs; i++) {
980 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
981 p += ETH_GSTRING_LEN;
982 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
983 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000984 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
985 p += ETH_GSTRING_LEN;
986 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
987 p += ETH_GSTRING_LEN;
988 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000989 if (vsi != pf->vsi[pf->lan_vsi])
990 return;
991
992 if (pf->lan_veb != I40E_NO_VEB) {
993 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
994 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
995 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000996 p += ETH_GSTRING_LEN;
997 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000998 }
999 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1000 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1001 i40e_gstrings_stats[i].stat_string);
1002 p += ETH_GSTRING_LEN;
1003 }
1004 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1005 snprintf(p, ETH_GSTRING_LEN,
1006 "port.tx_priority_%u_xon", i);
1007 p += ETH_GSTRING_LEN;
1008 snprintf(p, ETH_GSTRING_LEN,
1009 "port.tx_priority_%u_xoff", i);
1010 p += ETH_GSTRING_LEN;
1011 }
1012 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1013 snprintf(p, ETH_GSTRING_LEN,
1014 "port.rx_priority_%u_xon", i);
1015 p += ETH_GSTRING_LEN;
1016 snprintf(p, ETH_GSTRING_LEN,
1017 "port.rx_priority_%u_xoff", i);
1018 p += ETH_GSTRING_LEN;
1019 }
1020 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1021 snprintf(p, ETH_GSTRING_LEN,
1022 "port.rx_priority_%u_xon_2_xoff", i);
1023 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001024 }
1025 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1026 break;
1027 }
1028}
1029
1030static int i40e_get_ts_info(struct net_device *dev,
1031 struct ethtool_ts_info *info)
1032{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001033 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1034
1035 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1036 SOF_TIMESTAMPING_RX_SOFTWARE |
1037 SOF_TIMESTAMPING_SOFTWARE |
1038 SOF_TIMESTAMPING_TX_HARDWARE |
1039 SOF_TIMESTAMPING_RX_HARDWARE |
1040 SOF_TIMESTAMPING_RAW_HARDWARE;
1041
1042 if (pf->ptp_clock)
1043 info->phc_index = ptp_clock_index(pf->ptp_clock);
1044 else
1045 info->phc_index = -1;
1046
1047 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1048
1049 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1050 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1051 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1052 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1053 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1054 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1055 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1056 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1057 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1058 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1059 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1060 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1061
1062 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001063}
1064
Shannon Nelson7b086392013-11-20 10:02:59 +00001065static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001066{
Shannon Nelson7b086392013-11-20 10:02:59 +00001067 struct i40e_netdev_priv *np = netdev_priv(netdev);
1068 struct i40e_pf *pf = np->vsi->back;
1069
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001070 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001071 if (i40e_get_link_status(&pf->hw))
1072 *data = 0;
1073 else
1074 *data = 1;
1075
1076 return *data;
1077}
1078
Shannon Nelson7b086392013-11-20 10:02:59 +00001079static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001080{
Shannon Nelson7b086392013-11-20 10:02:59 +00001081 struct i40e_netdev_priv *np = netdev_priv(netdev);
1082 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001083
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001084 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001085 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001086
Shannon Nelson7b086392013-11-20 10:02:59 +00001087 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001088}
1089
Shannon Nelson7b086392013-11-20 10:02:59 +00001090static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001091{
Shannon Nelson7b086392013-11-20 10:02:59 +00001092 struct i40e_netdev_priv *np = netdev_priv(netdev);
1093 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001094
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001095 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001096 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001097
Shannon Nelson7b086392013-11-20 10:02:59 +00001098 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001099}
1100
Shannon Nelson7b086392013-11-20 10:02:59 +00001101static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001102{
Shannon Nelson7b086392013-11-20 10:02:59 +00001103 struct i40e_netdev_priv *np = netdev_priv(netdev);
1104 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001105 u16 swc_old = pf->sw_int_count;
1106
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001107 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001108 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1109 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
1110 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
1111 usleep_range(1000, 2000);
1112 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001113
1114 return *data;
1115}
1116
Shannon Nelson7b086392013-11-20 10:02:59 +00001117static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001118{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001119 struct i40e_netdev_priv *np = netdev_priv(netdev);
1120 struct i40e_pf *pf = np->vsi->back;
1121
1122 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001123 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001124
1125 return *data;
1126}
1127
1128static void i40e_diag_test(struct net_device *netdev,
1129 struct ethtool_test *eth_test, u64 *data)
1130{
1131 struct i40e_netdev_priv *np = netdev_priv(netdev);
1132 struct i40e_pf *pf = np->vsi->back;
1133
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001134 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1135 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001136 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001137
Shannon Nelsonf551b432013-11-26 10:49:12 +00001138 set_bit(__I40E_TESTING, &pf->state);
1139
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001140 /* Link test performed before hardware reset
1141 * so autoneg doesn't interfere with test result
1142 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001143 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001144 eth_test->flags |= ETH_TEST_FL_FAILED;
1145
Shannon Nelson7b086392013-11-20 10:02:59 +00001146 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001147 eth_test->flags |= ETH_TEST_FL_FAILED;
1148
Shannon Nelson7b086392013-11-20 10:02:59 +00001149 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001150 eth_test->flags |= ETH_TEST_FL_FAILED;
1151
Shannon Nelson7b086392013-11-20 10:02:59 +00001152 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001153 eth_test->flags |= ETH_TEST_FL_FAILED;
1154
Shannon Nelsonf551b432013-11-26 10:49:12 +00001155 /* run reg test last, a reset is required after it */
1156 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1157 eth_test->flags |= ETH_TEST_FL_FAILED;
1158
1159 clear_bit(__I40E_TESTING, &pf->state);
1160 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001161 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001162 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001163 netif_info(pf, drv, netdev, "online testing starting\n");
1164
Shannon Nelson7b086392013-11-20 10:02:59 +00001165 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001166 eth_test->flags |= ETH_TEST_FL_FAILED;
1167
1168 /* Offline only tests, not run in online; pass by default */
1169 data[I40E_ETH_TEST_REG] = 0;
1170 data[I40E_ETH_TEST_EEPROM] = 0;
1171 data[I40E_ETH_TEST_INTR] = 0;
1172 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001173 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001174
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001175 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001176}
1177
1178static void i40e_get_wol(struct net_device *netdev,
1179 struct ethtool_wolinfo *wol)
1180{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001181 struct i40e_netdev_priv *np = netdev_priv(netdev);
1182 struct i40e_pf *pf = np->vsi->back;
1183 struct i40e_hw *hw = &pf->hw;
1184 u16 wol_nvm_bits;
1185
1186 /* NVM bit on means WoL disabled for the port */
1187 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1188 if ((1 << hw->port) & wol_nvm_bits) {
1189 wol->supported = 0;
1190 wol->wolopts = 0;
1191 } else {
1192 wol->supported = WAKE_MAGIC;
1193 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1194 }
1195}
1196
1197static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1198{
1199 struct i40e_netdev_priv *np = netdev_priv(netdev);
1200 struct i40e_pf *pf = np->vsi->back;
1201 struct i40e_hw *hw = &pf->hw;
1202 u16 wol_nvm_bits;
1203
1204 /* NVM bit on means WoL disabled for the port */
1205 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1206 if (((1 << hw->port) & wol_nvm_bits))
1207 return -EOPNOTSUPP;
1208
1209 /* only magic packet is supported */
1210 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1211 return -EOPNOTSUPP;
1212
1213 /* is this a new value? */
1214 if (pf->wol_en != !!wol->wolopts) {
1215 pf->wol_en = !!wol->wolopts;
1216 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1217 }
1218
1219 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001220}
1221
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001222static int i40e_set_phys_id(struct net_device *netdev,
1223 enum ethtool_phys_id_state state)
1224{
1225 struct i40e_netdev_priv *np = netdev_priv(netdev);
1226 struct i40e_pf *pf = np->vsi->back;
1227 struct i40e_hw *hw = &pf->hw;
1228 int blink_freq = 2;
1229
1230 switch (state) {
1231 case ETHTOOL_ID_ACTIVE:
1232 pf->led_status = i40e_led_get(hw);
1233 return blink_freq;
1234 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001235 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001236 break;
1237 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001238 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001239 break;
1240 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001241 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001242 break;
1243 }
1244
1245 return 0;
1246}
1247
1248/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1249 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1250 * 125us (8000 interrupts per second) == ITR(62)
1251 */
1252
1253static int i40e_get_coalesce(struct net_device *netdev,
1254 struct ethtool_coalesce *ec)
1255{
1256 struct i40e_netdev_priv *np = netdev_priv(netdev);
1257 struct i40e_vsi *vsi = np->vsi;
1258
1259 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1260 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1261
1262 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001263 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001264
1265 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001266 ec->use_adaptive_tx_coalesce = 1;
1267
1268 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1269 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001270
1271 return 0;
1272}
1273
1274static int i40e_set_coalesce(struct net_device *netdev,
1275 struct ethtool_coalesce *ec)
1276{
1277 struct i40e_netdev_priv *np = netdev_priv(netdev);
1278 struct i40e_q_vector *q_vector;
1279 struct i40e_vsi *vsi = np->vsi;
1280 struct i40e_pf *pf = vsi->back;
1281 struct i40e_hw *hw = &pf->hw;
1282 u16 vector;
1283 int i;
1284
1285 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1286 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1287
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001288 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001289 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001290 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001291 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001292 } else if (ec->rx_coalesce_usecs == 0) {
1293 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1294 i40e_irq_dynamic_disable(vsi, vector);
1295 if (ec->use_adaptive_rx_coalesce)
1296 netif_info(pf, drv, netdev,
1297 "Rx-secs=0, need to disable adaptive-Rx for a complete disable\n");
1298 } else {
1299 netif_info(pf, drv, netdev,
1300 "Invalid value, Rx-usecs range is 0, 8-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001301 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001302 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001303
Mitch Williams32f5f542014-04-04 04:43:10 +00001304 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001305 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001306 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001307 } else if (ec->tx_coalesce_usecs == 0) {
1308 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1309 i40e_irq_dynamic_disable(vsi, vector);
1310 if (ec->use_adaptive_tx_coalesce)
1311 netif_info(pf, drv, netdev,
1312 "Tx-secs=0, need to disable adaptive-Tx for a complete disable\n");
1313 } else {
1314 netif_info(pf, drv, netdev,
1315 "Invalid value, Tx-usecs range is 0, 8-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001316 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001317 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001318
1319 if (ec->use_adaptive_rx_coalesce)
1320 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1321 else
1322 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1323
1324 if (ec->use_adaptive_tx_coalesce)
1325 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1326 else
1327 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001328
Alexander Duyck493fb302013-09-28 07:01:44 +00001329 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1330 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001331 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1332 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1333 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1334 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1335 i40e_flush(hw);
1336 }
1337
1338 return 0;
1339}
1340
1341/**
1342 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1343 * @pf: pointer to the physical function struct
1344 * @cmd: ethtool rxnfc command
1345 *
1346 * Returns Success if the flow is supported, else Invalid Input.
1347 **/
1348static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1349{
1350 cmd->data = 0;
1351
1352 /* Report default options for RSS on i40e */
1353 switch (cmd->flow_type) {
1354 case TCP_V4_FLOW:
1355 case UDP_V4_FLOW:
1356 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1357 /* fall through to add IP fields */
1358 case SCTP_V4_FLOW:
1359 case AH_ESP_V4_FLOW:
1360 case AH_V4_FLOW:
1361 case ESP_V4_FLOW:
1362 case IPV4_FLOW:
1363 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1364 break;
1365 case TCP_V6_FLOW:
1366 case UDP_V6_FLOW:
1367 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1368 /* fall through to add IP fields */
1369 case SCTP_V6_FLOW:
1370 case AH_ESP_V6_FLOW:
1371 case AH_V6_FLOW:
1372 case ESP_V6_FLOW:
1373 case IPV6_FLOW:
1374 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1375 break;
1376 default:
1377 return -EINVAL;
1378 }
1379
1380 return 0;
1381}
1382
1383/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001384 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1385 * @pf: Pointer to the physical function struct
1386 * @cmd: The command to get or set Rx flow classification rules
1387 * @rule_locs: Array of used rule locations
1388 *
1389 * This function populates both the total and actual rule count of
1390 * the ethtool flow classification command
1391 *
1392 * Returns 0 on success or -EMSGSIZE if entry not found
1393 **/
1394static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1395 struct ethtool_rxnfc *cmd,
1396 u32 *rule_locs)
1397{
1398 struct i40e_fdir_filter *rule;
1399 struct hlist_node *node2;
1400 int cnt = 0;
1401
1402 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001403 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001404
1405 hlist_for_each_entry_safe(rule, node2,
1406 &pf->fdir_filter_list, fdir_node) {
1407 if (cnt == cmd->rule_cnt)
1408 return -EMSGSIZE;
1409
1410 rule_locs[cnt] = rule->fd_id;
1411 cnt++;
1412 }
1413
1414 cmd->rule_cnt = cnt;
1415
1416 return 0;
1417}
1418
1419/**
1420 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1421 * @pf: Pointer to the physical function struct
1422 * @cmd: The command to get or set Rx flow classification rules
1423 *
1424 * This function looks up a filter based on the Rx flow classification
1425 * command and fills the flow spec info for it if found
1426 *
1427 * Returns 0 on success or -EINVAL if filter not found
1428 **/
1429static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1430 struct ethtool_rxnfc *cmd)
1431{
1432 struct ethtool_rx_flow_spec *fsp =
1433 (struct ethtool_rx_flow_spec *)&cmd->fs;
1434 struct i40e_fdir_filter *rule = NULL;
1435 struct hlist_node *node2;
1436
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001437 hlist_for_each_entry_safe(rule, node2,
1438 &pf->fdir_filter_list, fdir_node) {
1439 if (fsp->location <= rule->fd_id)
1440 break;
1441 }
1442
1443 if (!rule || fsp->location != rule->fd_id)
1444 return -EINVAL;
1445
1446 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001447 if (fsp->flow_type == IP_USER_FLOW) {
1448 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1449 fsp->h_u.usr_ip4_spec.proto = 0;
1450 fsp->m_u.usr_ip4_spec.proto = 0;
1451 }
1452
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001453 /* Reverse the src and dest notion, since the HW views them from
1454 * Tx perspective where as the user expects it from Rx filter view.
1455 */
1456 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1457 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1458 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1459 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001460
1461 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1462 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1463 else
1464 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001465
1466 return 0;
1467}
1468
1469/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001470 * i40e_get_rxnfc - command to get RX flow classification rules
1471 * @netdev: network interface device structure
1472 * @cmd: ethtool rxnfc command
1473 *
1474 * Returns Success if the command is supported.
1475 **/
1476static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1477 u32 *rule_locs)
1478{
1479 struct i40e_netdev_priv *np = netdev_priv(netdev);
1480 struct i40e_vsi *vsi = np->vsi;
1481 struct i40e_pf *pf = vsi->back;
1482 int ret = -EOPNOTSUPP;
1483
1484 switch (cmd->cmd) {
1485 case ETHTOOL_GRXRINGS:
1486 cmd->data = vsi->alloc_queue_pairs;
1487 ret = 0;
1488 break;
1489 case ETHTOOL_GRXFH:
1490 ret = i40e_get_rss_hash_opts(pf, cmd);
1491 break;
1492 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001493 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001494 /* report total rule count */
1495 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001496 ret = 0;
1497 break;
1498 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001499 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001500 break;
1501 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001502 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1503 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001504 default:
1505 break;
1506 }
1507
1508 return ret;
1509}
1510
1511/**
1512 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1513 * @pf: pointer to the physical function struct
1514 * @cmd: ethtool rxnfc command
1515 *
1516 * Returns Success if the flow input set is supported.
1517 **/
1518static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1519{
1520 struct i40e_hw *hw = &pf->hw;
1521 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1522 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1523
1524 /* RSS does not support anything other than hashing
1525 * to queues on src and dst IPs and ports
1526 */
1527 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1528 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1529 return -EINVAL;
1530
1531 /* We need at least the IP SRC and DEST fields for hashing */
1532 if (!(nfc->data & RXH_IP_SRC) ||
1533 !(nfc->data & RXH_IP_DST))
1534 return -EINVAL;
1535
1536 switch (nfc->flow_type) {
1537 case TCP_V4_FLOW:
1538 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1539 case 0:
1540 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1541 break;
1542 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1543 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1544 break;
1545 default:
1546 return -EINVAL;
1547 }
1548 break;
1549 case TCP_V6_FLOW:
1550 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1551 case 0:
1552 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1553 break;
1554 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1555 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1556 break;
1557 default:
1558 return -EINVAL;
1559 }
1560 break;
1561 case UDP_V4_FLOW:
1562 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1563 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001564 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1565 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001566 break;
1567 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001568 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1569 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001570 break;
1571 default:
1572 return -EINVAL;
1573 }
1574 break;
1575 case UDP_V6_FLOW:
1576 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1577 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001578 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1579 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001580 break;
1581 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001582 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1583 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001584 break;
1585 default:
1586 return -EINVAL;
1587 }
1588 break;
1589 case AH_ESP_V4_FLOW:
1590 case AH_V4_FLOW:
1591 case ESP_V4_FLOW:
1592 case SCTP_V4_FLOW:
1593 if ((nfc->data & RXH_L4_B_0_1) ||
1594 (nfc->data & RXH_L4_B_2_3))
1595 return -EINVAL;
1596 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1597 break;
1598 case AH_ESP_V6_FLOW:
1599 case AH_V6_FLOW:
1600 case ESP_V6_FLOW:
1601 case SCTP_V6_FLOW:
1602 if ((nfc->data & RXH_L4_B_0_1) ||
1603 (nfc->data & RXH_L4_B_2_3))
1604 return -EINVAL;
1605 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1606 break;
1607 case IPV4_FLOW:
1608 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1609 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1610 break;
1611 case IPV6_FLOW:
1612 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1613 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1614 break;
1615 default:
1616 return -EINVAL;
1617 }
1618
1619 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1620 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1621 i40e_flush(hw);
1622
1623 return 0;
1624}
1625
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001626/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001627 * i40e_match_fdir_input_set - Match a new filter against an existing one
1628 * @rule: The filter already added
1629 * @input: The new filter to comapre against
1630 *
1631 * Returns true if the two input set match
1632 **/
1633static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1634 struct i40e_fdir_filter *input)
1635{
1636 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1637 (rule->src_ip[0] != input->src_ip[0]) ||
1638 (rule->dst_port != input->dst_port) ||
1639 (rule->src_port != input->src_port))
1640 return false;
1641 return true;
1642}
1643
1644/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001645 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1646 * @vsi: Pointer to the targeted VSI
1647 * @input: The filter to update or NULL to indicate deletion
1648 * @sw_idx: Software index to the filter
1649 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001650 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001651 * This function updates (or deletes) a Flow Director entry from
1652 * the hlist of the corresponding PF
1653 *
1654 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001655 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001656static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1657 struct i40e_fdir_filter *input,
1658 u16 sw_idx,
1659 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001660{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001661 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001662 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001663 struct hlist_node *node2;
1664 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001665
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001666 parent = NULL;
1667 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001668
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001669 hlist_for_each_entry_safe(rule, node2,
1670 &pf->fdir_filter_list, fdir_node) {
1671 /* hash found, or no matching entry */
1672 if (rule->fd_id >= sw_idx)
1673 break;
1674 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001675 }
1676
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001677 /* if there is an old rule occupying our place remove it */
1678 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001679 if (input && !i40e_match_fdir_input_set(rule, input))
1680 err = i40e_add_del_fdir(vsi, rule, false);
1681 else if (!input)
1682 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001683 hlist_del(&rule->fdir_node);
1684 kfree(rule);
1685 pf->fdir_pf_active_filters--;
1686 }
1687
1688 /* If no input this was a delete, err should be 0 if a rule was
1689 * successfully found and removed from the list else -EINVAL
1690 */
1691 if (!input)
1692 return err;
1693
1694 /* initialize node and set software index */
1695 INIT_HLIST_NODE(&input->fdir_node);
1696
1697 /* add filter to the list */
1698 if (parent)
1699 hlist_add_after(&parent->fdir_node, &input->fdir_node);
1700 else
1701 hlist_add_head(&input->fdir_node,
1702 &pf->fdir_filter_list);
1703
1704 /* update counts */
1705 pf->fdir_pf_active_filters++;
1706
1707 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001708}
1709
1710/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001711 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
1712 * @vsi: Pointer to the targeted VSI
1713 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001714 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001715 * The function removes a Flow Director filter entry from the
1716 * hlist of the corresponding PF
1717 *
1718 * Returns 0 on success
1719 */
1720static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
1721 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001722{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001723 struct ethtool_rx_flow_spec *fsp =
1724 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001725 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001726 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001727
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001728 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001729
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001730 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001731 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001732}
1733
1734/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001735 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001736 * @vsi: pointer to the targeted VSI
1737 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001738 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001739 * Add Flow Director filters for a specific flow spec based on their
1740 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001741 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001742static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
1743 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001744{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001745 struct ethtool_rx_flow_spec *fsp;
1746 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001747 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001748 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001749
1750 if (!vsi)
1751 return -EINVAL;
1752
1753 pf = vsi->back;
1754
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001755 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
1756 return -EOPNOTSUPP;
1757
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001758 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001759 return -ENOSPC;
1760
1761 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
1762
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001763 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
1764 pf->hw.func_caps.fd_filters_guaranteed)) {
1765 return -EINVAL;
1766 }
1767
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001768 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
1769 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001770 return -EINVAL;
1771
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001772 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001773
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001774 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001775 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001776
1777 input->fd_id = fsp->location;
1778
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00001779 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
1780 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
1781 else
1782 input->dest_ctl =
1783 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
1784
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001785 input->q_index = fsp->ring_cookie;
1786 input->flex_off = 0;
1787 input->pctype = 0;
1788 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001789 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001790 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001791 input->flow_type = fsp->flow_type;
1792 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001793
1794 /* Reverse the src and dest notion, since the HW expects them to be from
1795 * Tx perspective where as the input from user is from Rx filter view.
1796 */
1797 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
1798 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
1799 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
1800 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001801
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001802 ret = i40e_add_del_fdir(vsi, input, true);
1803 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001804 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001805 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001806 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001807
1808 return ret;
1809}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08001810
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001811/**
1812 * i40e_set_rxnfc - command to set RX flow classification rules
1813 * @netdev: network interface device structure
1814 * @cmd: ethtool rxnfc command
1815 *
1816 * Returns Success if the command is supported.
1817 **/
1818static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1819{
1820 struct i40e_netdev_priv *np = netdev_priv(netdev);
1821 struct i40e_vsi *vsi = np->vsi;
1822 struct i40e_pf *pf = vsi->back;
1823 int ret = -EOPNOTSUPP;
1824
1825 switch (cmd->cmd) {
1826 case ETHTOOL_SRXFH:
1827 ret = i40e_set_rss_hash_opt(pf, cmd);
1828 break;
1829 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001830 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001831 break;
1832 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001833 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001834 break;
1835 default:
1836 break;
1837 }
1838
1839 return ret;
1840}
1841
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001842/**
1843 * i40e_max_channels - get Max number of combined channels supported
1844 * @vsi: vsi pointer
1845 **/
1846static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
1847{
1848 /* TODO: This code assumes DCB and FD is disabled for now. */
1849 return vsi->alloc_queue_pairs;
1850}
1851
1852/**
1853 * i40e_get_channels - Get the current channels enabled and max supported etc.
1854 * @netdev: network interface device structure
1855 * @ch: ethtool channels structure
1856 *
1857 * We don't support separate tx and rx queues as channels. The other count
1858 * represents how many queues are being used for control. max_combined counts
1859 * how many queue pairs we can support. They may not be mapped 1 to 1 with
1860 * q_vectors since we support a lot more queue pairs than q_vectors.
1861 **/
1862static void i40e_get_channels(struct net_device *dev,
1863 struct ethtool_channels *ch)
1864{
1865 struct i40e_netdev_priv *np = netdev_priv(dev);
1866 struct i40e_vsi *vsi = np->vsi;
1867 struct i40e_pf *pf = vsi->back;
1868
1869 /* report maximum channels */
1870 ch->max_combined = i40e_max_channels(vsi);
1871
1872 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08001873 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001874 ch->max_other = ch->other_count;
1875
1876 /* Note: This code assumes DCB is disabled for now. */
1877 ch->combined_count = vsi->num_queue_pairs;
1878}
1879
1880/**
1881 * i40e_set_channels - Set the new channels count.
1882 * @netdev: network interface device structure
1883 * @ch: ethtool channels structure
1884 *
1885 * The new channels count may not be the same as requested by the user
1886 * since it gets rounded down to a power of 2 value.
1887 **/
1888static int i40e_set_channels(struct net_device *dev,
1889 struct ethtool_channels *ch)
1890{
1891 struct i40e_netdev_priv *np = netdev_priv(dev);
1892 unsigned int count = ch->combined_count;
1893 struct i40e_vsi *vsi = np->vsi;
1894 struct i40e_pf *pf = vsi->back;
1895 int new_count;
1896
1897 /* We do not support setting channels for any other VSI at present */
1898 if (vsi->type != I40E_VSI_MAIN)
1899 return -EINVAL;
1900
1901 /* verify they are not requesting separate vectors */
1902 if (!count || ch->rx_count || ch->tx_count)
1903 return -EINVAL;
1904
1905 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08001906 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001907 return -EINVAL;
1908
1909 /* verify the number of channels does not exceed hardware limits */
1910 if (count > i40e_max_channels(vsi))
1911 return -EINVAL;
1912
1913 /* update feature limits from largest to smallest supported values */
1914 /* TODO: Flow director limit, DCB etc */
1915
1916 /* cap RSS limit */
1917 if (count > pf->rss_size_max)
1918 count = pf->rss_size_max;
1919
1920 /* use rss_reconfig to rebuild with new queue count and update traffic
1921 * class queue mapping
1922 */
1923 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00001924 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001925 return 0;
1926 else
1927 return -EINVAL;
1928}
1929
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001930static const struct ethtool_ops i40e_ethtool_ops = {
1931 .get_settings = i40e_get_settings,
1932 .get_drvinfo = i40e_get_drvinfo,
1933 .get_regs_len = i40e_get_regs_len,
1934 .get_regs = i40e_get_regs,
1935 .nway_reset = i40e_nway_reset,
1936 .get_link = ethtool_op_get_link,
1937 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001938 .set_wol = i40e_set_wol,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001939 .get_eeprom_len = i40e_get_eeprom_len,
1940 .get_eeprom = i40e_get_eeprom,
1941 .get_ringparam = i40e_get_ringparam,
1942 .set_ringparam = i40e_set_ringparam,
1943 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00001944 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001945 .get_msglevel = i40e_get_msglevel,
1946 .set_msglevel = i40e_set_msglevel,
1947 .get_rxnfc = i40e_get_rxnfc,
1948 .set_rxnfc = i40e_set_rxnfc,
1949 .self_test = i40e_diag_test,
1950 .get_strings = i40e_get_strings,
1951 .set_phys_id = i40e_set_phys_id,
1952 .get_sset_count = i40e_get_sset_count,
1953 .get_ethtool_stats = i40e_get_ethtool_stats,
1954 .get_coalesce = i40e_get_coalesce,
1955 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001956 .get_channels = i40e_get_channels,
1957 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001958 .get_ts_info = i40e_get_ts_info,
1959};
1960
1961void i40e_set_ethtool_ops(struct net_device *netdev)
1962{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00001963 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001964}