blob: b105e6f321d0b53287d84dd210c8228f656dc81b [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
415/**
416 * i40e_get_pauseparam - Get Flow Control status
417 * Return tx/rx-pause status
418 **/
419static void i40e_get_pauseparam(struct net_device *netdev,
420 struct ethtool_pauseparam *pause)
421{
422 struct i40e_netdev_priv *np = netdev_priv(netdev);
423 struct i40e_pf *pf = np->vsi->back;
424 struct i40e_hw *hw = &pf->hw;
425 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
426
427 pause->autoneg =
428 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
429 AUTONEG_ENABLE : AUTONEG_DISABLE);
430
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000431 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000432 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000433 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000434 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000435 } else if (hw->fc.current_mode == I40E_FC_FULL) {
436 pause->rx_pause = 1;
437 pause->tx_pause = 1;
438 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000439}
440
441static u32 i40e_get_msglevel(struct net_device *netdev)
442{
443 struct i40e_netdev_priv *np = netdev_priv(netdev);
444 struct i40e_pf *pf = np->vsi->back;
445
446 return pf->msg_enable;
447}
448
449static void i40e_set_msglevel(struct net_device *netdev, u32 data)
450{
451 struct i40e_netdev_priv *np = netdev_priv(netdev);
452 struct i40e_pf *pf = np->vsi->back;
453
454 if (I40E_DEBUG_USER & data)
455 pf->hw.debug_mask = data;
456 pf->msg_enable = data;
457}
458
459static int i40e_get_regs_len(struct net_device *netdev)
460{
461 int reg_count = 0;
462 int i;
463
464 for (i = 0; i40e_reg_list[i].offset != 0; i++)
465 reg_count += i40e_reg_list[i].elements;
466
467 return reg_count * sizeof(u32);
468}
469
470static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
471 void *p)
472{
473 struct i40e_netdev_priv *np = netdev_priv(netdev);
474 struct i40e_pf *pf = np->vsi->back;
475 struct i40e_hw *hw = &pf->hw;
476 u32 *reg_buf = p;
477 int i, j, ri;
478 u32 reg;
479
480 /* Tell ethtool which driver-version-specific regs output we have.
481 *
482 * At some point, if we have ethtool doing special formatting of
483 * this data, it will rely on this version number to know how to
484 * interpret things. Hence, this needs to be updated if/when the
485 * diags register table is changed.
486 */
487 regs->version = 1;
488
489 /* loop through the diags reg table for what to print */
490 ri = 0;
491 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
492 for (j = 0; j < i40e_reg_list[i].elements; j++) {
493 reg = i40e_reg_list[i].offset
494 + (j * i40e_reg_list[i].stride);
495 reg_buf[ri++] = rd32(hw, reg);
496 }
497 }
498
499}
500
501static int i40e_get_eeprom(struct net_device *netdev,
502 struct ethtool_eeprom *eeprom, u8 *bytes)
503{
504 struct i40e_netdev_priv *np = netdev_priv(netdev);
505 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000506 struct i40e_pf *pf = np->vsi->back;
507 int ret_val = 0, len;
508 u8 *eeprom_buff;
509 u16 i, sectors;
510 bool last;
511#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000512 if (eeprom->len == 0)
513 return -EINVAL;
514
515 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
516
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000517 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000518 if (!eeprom_buff)
519 return -ENOMEM;
520
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000521 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
522 if (ret_val) {
523 dev_info(&pf->pdev->dev,
524 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
525 ret_val, hw->aq.asq_last_status);
526 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000527 }
528
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000529 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
530 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
531 len = I40E_NVM_SECTOR_SIZE;
532 last = false;
533 for (i = 0; i < sectors; i++) {
534 if (i == (sectors - 1)) {
535 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
536 last = true;
537 }
538 ret_val = i40e_aq_read_nvm(hw, 0x0,
539 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
540 len,
Joe Perches3dbb7fd2014-03-25 04:30:38 +0000541 eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000542 last, NULL);
543 if (ret_val) {
544 dev_info(&pf->pdev->dev,
545 "read NVM failed err=%d status=0x%x\n",
546 ret_val, hw->aq.asq_last_status);
547 goto release_nvm;
548 }
549 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000550
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000551release_nvm:
552 i40e_release_nvm(hw);
Joe Perches3dbb7fd2014-03-25 04:30:38 +0000553 memcpy(bytes, eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000554free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000555 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000556 return ret_val;
557}
558
559static int i40e_get_eeprom_len(struct net_device *netdev)
560{
561 struct i40e_netdev_priv *np = netdev_priv(netdev);
562 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000563 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000564
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000565 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
566 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
567 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
568 /* register returns value in power of 2, 64Kbyte chunks. */
569 val = (64 * 1024) * (1 << val);
570 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000571}
572
573static void i40e_get_drvinfo(struct net_device *netdev,
574 struct ethtool_drvinfo *drvinfo)
575{
576 struct i40e_netdev_priv *np = netdev_priv(netdev);
577 struct i40e_vsi *vsi = np->vsi;
578 struct i40e_pf *pf = vsi->back;
579
580 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
581 strlcpy(drvinfo->version, i40e_driver_version_str,
582 sizeof(drvinfo->version));
583 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
584 sizeof(drvinfo->fw_version));
585 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
586 sizeof(drvinfo->bus_info));
587}
588
589static void i40e_get_ringparam(struct net_device *netdev,
590 struct ethtool_ringparam *ring)
591{
592 struct i40e_netdev_priv *np = netdev_priv(netdev);
593 struct i40e_pf *pf = np->vsi->back;
594 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
595
596 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
597 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
598 ring->rx_mini_max_pending = 0;
599 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +0000600 ring->rx_pending = vsi->rx_rings[0]->count;
601 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000602 ring->rx_mini_pending = 0;
603 ring->rx_jumbo_pending = 0;
604}
605
606static int i40e_set_ringparam(struct net_device *netdev,
607 struct ethtool_ringparam *ring)
608{
609 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
610 struct i40e_netdev_priv *np = netdev_priv(netdev);
611 struct i40e_vsi *vsi = np->vsi;
612 struct i40e_pf *pf = vsi->back;
613 u32 new_rx_count, new_tx_count;
614 int i, err = 0;
615
616 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
617 return -EINVAL;
618
Shannon Nelson1fa18372013-11-20 10:03:08 +0000619 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
620 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
621 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
622 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
623 netdev_info(netdev,
624 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
625 ring->tx_pending, ring->rx_pending,
626 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
627 return -EINVAL;
628 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000629
Shannon Nelson1fa18372013-11-20 10:03:08 +0000630 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
631 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000632
633 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000634 if ((new_tx_count == vsi->tx_rings[0]->count) &&
635 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000636 return 0;
637
638 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
639 usleep_range(1000, 2000);
640
641 if (!netif_running(vsi->netdev)) {
642 /* simple case - set for the next time the netdev is started */
643 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000644 vsi->tx_rings[i]->count = new_tx_count;
645 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000646 }
647 goto done;
648 }
649
650 /* We can't just free everything and then setup again,
651 * because the ISRs in MSI-X mode get passed pointers
652 * to the Tx and Rx ring structs.
653 */
654
655 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000656 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000657 netdev_info(netdev,
658 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000659 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000660 tx_rings = kcalloc(vsi->alloc_queue_pairs,
661 sizeof(struct i40e_ring), GFP_KERNEL);
662 if (!tx_rings) {
663 err = -ENOMEM;
664 goto done;
665 }
666
667 for (i = 0; i < vsi->num_queue_pairs; i++) {
668 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000669 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000670 tx_rings[i].count = new_tx_count;
671 err = i40e_setup_tx_descriptors(&tx_rings[i]);
672 if (err) {
673 while (i) {
674 i--;
675 i40e_free_tx_resources(&tx_rings[i]);
676 }
677 kfree(tx_rings);
678 tx_rings = NULL;
679
680 goto done;
681 }
682 }
683 }
684
685 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000686 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000687 netdev_info(netdev,
688 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000689 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000690 rx_rings = kcalloc(vsi->alloc_queue_pairs,
691 sizeof(struct i40e_ring), GFP_KERNEL);
692 if (!rx_rings) {
693 err = -ENOMEM;
694 goto free_tx;
695 }
696
697 for (i = 0; i < vsi->num_queue_pairs; i++) {
698 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000699 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000700 rx_rings[i].count = new_rx_count;
701 err = i40e_setup_rx_descriptors(&rx_rings[i]);
702 if (err) {
703 while (i) {
704 i--;
705 i40e_free_rx_resources(&rx_rings[i]);
706 }
707 kfree(rx_rings);
708 rx_rings = NULL;
709
710 goto free_tx;
711 }
712 }
713 }
714
715 /* Bring interface down, copy in the new ring info,
716 * then restore the interface
717 */
718 i40e_down(vsi);
719
720 if (tx_rings) {
721 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000722 i40e_free_tx_resources(vsi->tx_rings[i]);
723 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000724 }
725 kfree(tx_rings);
726 tx_rings = NULL;
727 }
728
729 if (rx_rings) {
730 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000731 i40e_free_rx_resources(vsi->rx_rings[i]);
732 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000733 }
734 kfree(rx_rings);
735 rx_rings = NULL;
736 }
737
738 i40e_up(vsi);
739
740free_tx:
741 /* error cleanup if the Rx allocations failed after getting Tx */
742 if (tx_rings) {
743 for (i = 0; i < vsi->num_queue_pairs; i++)
744 i40e_free_tx_resources(&tx_rings[i]);
745 kfree(tx_rings);
746 tx_rings = NULL;
747 }
748
749done:
750 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
751
752 return err;
753}
754
755static int i40e_get_sset_count(struct net_device *netdev, int sset)
756{
757 struct i40e_netdev_priv *np = netdev_priv(netdev);
758 struct i40e_vsi *vsi = np->vsi;
759 struct i40e_pf *pf = vsi->back;
760
761 switch (sset) {
762 case ETH_SS_TEST:
763 return I40E_TEST_LEN;
764 case ETH_SS_STATS:
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000765 if (vsi == pf->vsi[pf->lan_vsi]) {
766 int len = I40E_PF_STATS_LEN(netdev);
767
768 if (pf->lan_veb != I40E_NO_VEB)
769 len += I40E_VEB_STATS_LEN;
770 return len;
771 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000772 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000773 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000774 default:
775 return -EOPNOTSUPP;
776 }
777}
778
779static void i40e_get_ethtool_stats(struct net_device *netdev,
780 struct ethtool_stats *stats, u64 *data)
781{
782 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +0000783 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000784 struct i40e_vsi *vsi = np->vsi;
785 struct i40e_pf *pf = vsi->back;
786 int i = 0;
787 char *p;
788 int j;
789 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000790 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000791
792 i40e_update_stats(vsi);
793
794 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
795 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
796 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
797 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
798 }
Shannon Nelson41a9e552014-04-23 04:50:20 +0000799 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
800 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
801 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
802 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
803 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000804 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000805 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +0000806 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000807
808 if (!tx_ring)
809 continue;
810
811 /* process Tx ring statistics */
812 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700813 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000814 data[i] = tx_ring->stats.packets;
815 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700816 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000817 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000818
819 /* Rx ring is the 2nd half of the queue pair */
820 rx_ring = &tx_ring[1];
821 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700822 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000823 data[i] = rx_ring->stats.packets;
824 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700825 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000826 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000827 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000828 rcu_read_unlock();
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000829 if (vsi != pf->vsi[pf->lan_vsi])
830 return;
831
832 if (pf->lan_veb != I40E_NO_VEB) {
833 struct i40e_veb *veb = pf->veb[pf->lan_veb];
834 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
835 p = (char *)veb;
836 p += i40e_gstrings_veb_stats[j].stat_offset;
837 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
838 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000839 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000840 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000841 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
842 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
843 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
844 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
845 }
846 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
847 data[i++] = pf->stats.priority_xon_tx[j];
848 data[i++] = pf->stats.priority_xoff_tx[j];
849 }
850 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
851 data[i++] = pf->stats.priority_xon_rx[j];
852 data[i++] = pf->stats.priority_xoff_rx[j];
853 }
854 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
855 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000856}
857
858static void i40e_get_strings(struct net_device *netdev, u32 stringset,
859 u8 *data)
860{
861 struct i40e_netdev_priv *np = netdev_priv(netdev);
862 struct i40e_vsi *vsi = np->vsi;
863 struct i40e_pf *pf = vsi->back;
864 char *p = (char *)data;
865 int i;
866
867 switch (stringset) {
868 case ETH_SS_TEST:
869 for (i = 0; i < I40E_TEST_LEN; i++) {
870 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
871 data += ETH_GSTRING_LEN;
872 }
873 break;
874 case ETH_SS_STATS:
875 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
876 snprintf(p, ETH_GSTRING_LEN, "%s",
877 i40e_gstrings_net_stats[i].stat_string);
878 p += ETH_GSTRING_LEN;
879 }
Shannon Nelson41a9e552014-04-23 04:50:20 +0000880 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
881 snprintf(p, ETH_GSTRING_LEN, "%s",
882 i40e_gstrings_misc_stats[i].stat_string);
883 p += ETH_GSTRING_LEN;
884 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000885 for (i = 0; i < vsi->num_queue_pairs; i++) {
886 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
887 p += ETH_GSTRING_LEN;
888 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
889 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000890 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
891 p += ETH_GSTRING_LEN;
892 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
893 p += ETH_GSTRING_LEN;
894 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000895 if (vsi != pf->vsi[pf->lan_vsi])
896 return;
897
898 if (pf->lan_veb != I40E_NO_VEB) {
899 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
900 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
901 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000902 p += ETH_GSTRING_LEN;
903 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000904 }
905 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
906 snprintf(p, ETH_GSTRING_LEN, "port.%s",
907 i40e_gstrings_stats[i].stat_string);
908 p += ETH_GSTRING_LEN;
909 }
910 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
911 snprintf(p, ETH_GSTRING_LEN,
912 "port.tx_priority_%u_xon", i);
913 p += ETH_GSTRING_LEN;
914 snprintf(p, ETH_GSTRING_LEN,
915 "port.tx_priority_%u_xoff", i);
916 p += ETH_GSTRING_LEN;
917 }
918 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
919 snprintf(p, ETH_GSTRING_LEN,
920 "port.rx_priority_%u_xon", i);
921 p += ETH_GSTRING_LEN;
922 snprintf(p, ETH_GSTRING_LEN,
923 "port.rx_priority_%u_xoff", i);
924 p += ETH_GSTRING_LEN;
925 }
926 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
927 snprintf(p, ETH_GSTRING_LEN,
928 "port.rx_priority_%u_xon_2_xoff", i);
929 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000930 }
931 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
932 break;
933 }
934}
935
936static int i40e_get_ts_info(struct net_device *dev,
937 struct ethtool_ts_info *info)
938{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000939 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
940
941 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
942 SOF_TIMESTAMPING_RX_SOFTWARE |
943 SOF_TIMESTAMPING_SOFTWARE |
944 SOF_TIMESTAMPING_TX_HARDWARE |
945 SOF_TIMESTAMPING_RX_HARDWARE |
946 SOF_TIMESTAMPING_RAW_HARDWARE;
947
948 if (pf->ptp_clock)
949 info->phc_index = ptp_clock_index(pf->ptp_clock);
950 else
951 info->phc_index = -1;
952
953 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
954
955 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
956 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
957 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
958 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
959 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
960 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
961 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
962 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
963 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
964 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
965 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
966 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
967
968 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000969}
970
Shannon Nelson7b086392013-11-20 10:02:59 +0000971static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000972{
Shannon Nelson7b086392013-11-20 10:02:59 +0000973 struct i40e_netdev_priv *np = netdev_priv(netdev);
974 struct i40e_pf *pf = np->vsi->back;
975
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000976 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000977 if (i40e_get_link_status(&pf->hw))
978 *data = 0;
979 else
980 *data = 1;
981
982 return *data;
983}
984
Shannon Nelson7b086392013-11-20 10:02:59 +0000985static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000986{
Shannon Nelson7b086392013-11-20 10:02:59 +0000987 struct i40e_netdev_priv *np = netdev_priv(netdev);
988 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000989
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000990 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +0000991 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000992
Shannon Nelson7b086392013-11-20 10:02:59 +0000993 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000994}
995
Shannon Nelson7b086392013-11-20 10:02:59 +0000996static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000997{
Shannon Nelson7b086392013-11-20 10:02:59 +0000998 struct i40e_netdev_priv *np = netdev_priv(netdev);
999 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001000
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001001 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001002 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001003
Shannon Nelson7b086392013-11-20 10:02:59 +00001004 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001005}
1006
Shannon Nelson7b086392013-11-20 10:02:59 +00001007static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001008{
Shannon Nelson7b086392013-11-20 10:02:59 +00001009 struct i40e_netdev_priv *np = netdev_priv(netdev);
1010 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001011 u16 swc_old = pf->sw_int_count;
1012
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001013 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001014 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1015 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
1016 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
1017 usleep_range(1000, 2000);
1018 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001019
1020 return *data;
1021}
1022
Shannon Nelson7b086392013-11-20 10:02:59 +00001023static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001024{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001025 struct i40e_netdev_priv *np = netdev_priv(netdev);
1026 struct i40e_pf *pf = np->vsi->back;
1027
1028 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001029 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001030
1031 return *data;
1032}
1033
1034static void i40e_diag_test(struct net_device *netdev,
1035 struct ethtool_test *eth_test, u64 *data)
1036{
1037 struct i40e_netdev_priv *np = netdev_priv(netdev);
1038 struct i40e_pf *pf = np->vsi->back;
1039
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001040 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1041 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001042 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001043
Shannon Nelsonf551b432013-11-26 10:49:12 +00001044 set_bit(__I40E_TESTING, &pf->state);
1045
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001046 /* Link test performed before hardware reset
1047 * so autoneg doesn't interfere with test result
1048 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001049 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001050 eth_test->flags |= ETH_TEST_FL_FAILED;
1051
Shannon Nelson7b086392013-11-20 10:02:59 +00001052 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001053 eth_test->flags |= ETH_TEST_FL_FAILED;
1054
Shannon Nelson7b086392013-11-20 10:02:59 +00001055 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001056 eth_test->flags |= ETH_TEST_FL_FAILED;
1057
Shannon Nelson7b086392013-11-20 10:02:59 +00001058 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001059 eth_test->flags |= ETH_TEST_FL_FAILED;
1060
Shannon Nelsonf551b432013-11-26 10:49:12 +00001061 /* run reg test last, a reset is required after it */
1062 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1063 eth_test->flags |= ETH_TEST_FL_FAILED;
1064
1065 clear_bit(__I40E_TESTING, &pf->state);
1066 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001067 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001068 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001069 netif_info(pf, drv, netdev, "online testing starting\n");
1070
Shannon Nelson7b086392013-11-20 10:02:59 +00001071 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001072 eth_test->flags |= ETH_TEST_FL_FAILED;
1073
1074 /* Offline only tests, not run in online; pass by default */
1075 data[I40E_ETH_TEST_REG] = 0;
1076 data[I40E_ETH_TEST_EEPROM] = 0;
1077 data[I40E_ETH_TEST_INTR] = 0;
1078 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001079 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001080
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001081 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001082}
1083
1084static void i40e_get_wol(struct net_device *netdev,
1085 struct ethtool_wolinfo *wol)
1086{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001087 struct i40e_netdev_priv *np = netdev_priv(netdev);
1088 struct i40e_pf *pf = np->vsi->back;
1089 struct i40e_hw *hw = &pf->hw;
1090 u16 wol_nvm_bits;
1091
1092 /* NVM bit on means WoL disabled for the port */
1093 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1094 if ((1 << hw->port) & wol_nvm_bits) {
1095 wol->supported = 0;
1096 wol->wolopts = 0;
1097 } else {
1098 wol->supported = WAKE_MAGIC;
1099 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1100 }
1101}
1102
1103static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1104{
1105 struct i40e_netdev_priv *np = netdev_priv(netdev);
1106 struct i40e_pf *pf = np->vsi->back;
1107 struct i40e_hw *hw = &pf->hw;
1108 u16 wol_nvm_bits;
1109
1110 /* NVM bit on means WoL disabled for the port */
1111 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1112 if (((1 << hw->port) & wol_nvm_bits))
1113 return -EOPNOTSUPP;
1114
1115 /* only magic packet is supported */
1116 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1117 return -EOPNOTSUPP;
1118
1119 /* is this a new value? */
1120 if (pf->wol_en != !!wol->wolopts) {
1121 pf->wol_en = !!wol->wolopts;
1122 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1123 }
1124
1125 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001126}
1127
1128static int i40e_nway_reset(struct net_device *netdev)
1129{
1130 /* restart autonegotiation */
1131 struct i40e_netdev_priv *np = netdev_priv(netdev);
1132 struct i40e_pf *pf = np->vsi->back;
1133 struct i40e_hw *hw = &pf->hw;
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001134 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001135 i40e_status ret = 0;
1136
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001137 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001138 if (ret) {
1139 netdev_info(netdev, "link restart failed, aq_err=%d\n",
1140 pf->hw.aq.asq_last_status);
1141 return -EIO;
1142 }
1143
1144 return 0;
1145}
1146
1147static int i40e_set_phys_id(struct net_device *netdev,
1148 enum ethtool_phys_id_state state)
1149{
1150 struct i40e_netdev_priv *np = netdev_priv(netdev);
1151 struct i40e_pf *pf = np->vsi->back;
1152 struct i40e_hw *hw = &pf->hw;
1153 int blink_freq = 2;
1154
1155 switch (state) {
1156 case ETHTOOL_ID_ACTIVE:
1157 pf->led_status = i40e_led_get(hw);
1158 return blink_freq;
1159 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001160 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001161 break;
1162 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001163 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001164 break;
1165 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001166 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001167 break;
1168 }
1169
1170 return 0;
1171}
1172
1173/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1174 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1175 * 125us (8000 interrupts per second) == ITR(62)
1176 */
1177
1178static int i40e_get_coalesce(struct net_device *netdev,
1179 struct ethtool_coalesce *ec)
1180{
1181 struct i40e_netdev_priv *np = netdev_priv(netdev);
1182 struct i40e_vsi *vsi = np->vsi;
1183
1184 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1185 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1186
1187 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001188 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001189
1190 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001191 ec->use_adaptive_tx_coalesce = 1;
1192
1193 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1194 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001195
1196 return 0;
1197}
1198
1199static int i40e_set_coalesce(struct net_device *netdev,
1200 struct ethtool_coalesce *ec)
1201{
1202 struct i40e_netdev_priv *np = netdev_priv(netdev);
1203 struct i40e_q_vector *q_vector;
1204 struct i40e_vsi *vsi = np->vsi;
1205 struct i40e_pf *pf = vsi->back;
1206 struct i40e_hw *hw = &pf->hw;
1207 u16 vector;
1208 int i;
1209
1210 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1211 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1212
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001213 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001214 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001215 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001216 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001217 } else if (ec->rx_coalesce_usecs == 0) {
1218 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1219 i40e_irq_dynamic_disable(vsi, vector);
1220 if (ec->use_adaptive_rx_coalesce)
1221 netif_info(pf, drv, netdev,
1222 "Rx-secs=0, need to disable adaptive-Rx for a complete disable\n");
1223 } else {
1224 netif_info(pf, drv, netdev,
1225 "Invalid value, Rx-usecs range is 0, 8-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001226 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001227 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001228
Mitch Williams32f5f542014-04-04 04:43:10 +00001229 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001230 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001231 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001232 } else if (ec->tx_coalesce_usecs == 0) {
1233 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1234 i40e_irq_dynamic_disable(vsi, vector);
1235 if (ec->use_adaptive_tx_coalesce)
1236 netif_info(pf, drv, netdev,
1237 "Tx-secs=0, need to disable adaptive-Tx for a complete disable\n");
1238 } else {
1239 netif_info(pf, drv, netdev,
1240 "Invalid value, Tx-usecs range is 0, 8-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001241 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001242 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001243
1244 if (ec->use_adaptive_rx_coalesce)
1245 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1246 else
1247 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1248
1249 if (ec->use_adaptive_tx_coalesce)
1250 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1251 else
1252 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001253
Alexander Duyck493fb302013-09-28 07:01:44 +00001254 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1255 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001256 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1257 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1258 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1259 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1260 i40e_flush(hw);
1261 }
1262
1263 return 0;
1264}
1265
1266/**
1267 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1268 * @pf: pointer to the physical function struct
1269 * @cmd: ethtool rxnfc command
1270 *
1271 * Returns Success if the flow is supported, else Invalid Input.
1272 **/
1273static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1274{
1275 cmd->data = 0;
1276
1277 /* Report default options for RSS on i40e */
1278 switch (cmd->flow_type) {
1279 case TCP_V4_FLOW:
1280 case UDP_V4_FLOW:
1281 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1282 /* fall through to add IP fields */
1283 case SCTP_V4_FLOW:
1284 case AH_ESP_V4_FLOW:
1285 case AH_V4_FLOW:
1286 case ESP_V4_FLOW:
1287 case IPV4_FLOW:
1288 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1289 break;
1290 case TCP_V6_FLOW:
1291 case UDP_V6_FLOW:
1292 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1293 /* fall through to add IP fields */
1294 case SCTP_V6_FLOW:
1295 case AH_ESP_V6_FLOW:
1296 case AH_V6_FLOW:
1297 case ESP_V6_FLOW:
1298 case IPV6_FLOW:
1299 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1300 break;
1301 default:
1302 return -EINVAL;
1303 }
1304
1305 return 0;
1306}
1307
1308/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001309 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1310 * @pf: Pointer to the physical function struct
1311 * @cmd: The command to get or set Rx flow classification rules
1312 * @rule_locs: Array of used rule locations
1313 *
1314 * This function populates both the total and actual rule count of
1315 * the ethtool flow classification command
1316 *
1317 * Returns 0 on success or -EMSGSIZE if entry not found
1318 **/
1319static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1320 struct ethtool_rxnfc *cmd,
1321 u32 *rule_locs)
1322{
1323 struct i40e_fdir_filter *rule;
1324 struct hlist_node *node2;
1325 int cnt = 0;
1326
1327 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001328 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001329
1330 hlist_for_each_entry_safe(rule, node2,
1331 &pf->fdir_filter_list, fdir_node) {
1332 if (cnt == cmd->rule_cnt)
1333 return -EMSGSIZE;
1334
1335 rule_locs[cnt] = rule->fd_id;
1336 cnt++;
1337 }
1338
1339 cmd->rule_cnt = cnt;
1340
1341 return 0;
1342}
1343
1344/**
1345 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1346 * @pf: Pointer to the physical function struct
1347 * @cmd: The command to get or set Rx flow classification rules
1348 *
1349 * This function looks up a filter based on the Rx flow classification
1350 * command and fills the flow spec info for it if found
1351 *
1352 * Returns 0 on success or -EINVAL if filter not found
1353 **/
1354static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1355 struct ethtool_rxnfc *cmd)
1356{
1357 struct ethtool_rx_flow_spec *fsp =
1358 (struct ethtool_rx_flow_spec *)&cmd->fs;
1359 struct i40e_fdir_filter *rule = NULL;
1360 struct hlist_node *node2;
1361
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001362 hlist_for_each_entry_safe(rule, node2,
1363 &pf->fdir_filter_list, fdir_node) {
1364 if (fsp->location <= rule->fd_id)
1365 break;
1366 }
1367
1368 if (!rule || fsp->location != rule->fd_id)
1369 return -EINVAL;
1370
1371 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001372 if (fsp->flow_type == IP_USER_FLOW) {
1373 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1374 fsp->h_u.usr_ip4_spec.proto = 0;
1375 fsp->m_u.usr_ip4_spec.proto = 0;
1376 }
1377
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001378 /* Reverse the src and dest notion, since the HW views them from
1379 * Tx perspective where as the user expects it from Rx filter view.
1380 */
1381 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1382 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1383 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1384 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001385
1386 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1387 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1388 else
1389 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001390
1391 return 0;
1392}
1393
1394/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001395 * i40e_get_rxnfc - command to get RX flow classification rules
1396 * @netdev: network interface device structure
1397 * @cmd: ethtool rxnfc command
1398 *
1399 * Returns Success if the command is supported.
1400 **/
1401static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1402 u32 *rule_locs)
1403{
1404 struct i40e_netdev_priv *np = netdev_priv(netdev);
1405 struct i40e_vsi *vsi = np->vsi;
1406 struct i40e_pf *pf = vsi->back;
1407 int ret = -EOPNOTSUPP;
1408
1409 switch (cmd->cmd) {
1410 case ETHTOOL_GRXRINGS:
1411 cmd->data = vsi->alloc_queue_pairs;
1412 ret = 0;
1413 break;
1414 case ETHTOOL_GRXFH:
1415 ret = i40e_get_rss_hash_opts(pf, cmd);
1416 break;
1417 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001418 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001419 /* report total rule count */
1420 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001421 ret = 0;
1422 break;
1423 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001424 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001425 break;
1426 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001427 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1428 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001429 default:
1430 break;
1431 }
1432
1433 return ret;
1434}
1435
1436/**
1437 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1438 * @pf: pointer to the physical function struct
1439 * @cmd: ethtool rxnfc command
1440 *
1441 * Returns Success if the flow input set is supported.
1442 **/
1443static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1444{
1445 struct i40e_hw *hw = &pf->hw;
1446 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1447 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1448
1449 /* RSS does not support anything other than hashing
1450 * to queues on src and dst IPs and ports
1451 */
1452 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1453 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1454 return -EINVAL;
1455
1456 /* We need at least the IP SRC and DEST fields for hashing */
1457 if (!(nfc->data & RXH_IP_SRC) ||
1458 !(nfc->data & RXH_IP_DST))
1459 return -EINVAL;
1460
1461 switch (nfc->flow_type) {
1462 case TCP_V4_FLOW:
1463 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1464 case 0:
1465 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1466 break;
1467 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1468 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1469 break;
1470 default:
1471 return -EINVAL;
1472 }
1473 break;
1474 case TCP_V6_FLOW:
1475 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1476 case 0:
1477 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1478 break;
1479 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1480 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1481 break;
1482 default:
1483 return -EINVAL;
1484 }
1485 break;
1486 case UDP_V4_FLOW:
1487 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1488 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001489 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1490 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001491 break;
1492 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001493 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1494 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001495 break;
1496 default:
1497 return -EINVAL;
1498 }
1499 break;
1500 case UDP_V6_FLOW:
1501 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1502 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001503 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1504 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001505 break;
1506 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001507 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1508 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001509 break;
1510 default:
1511 return -EINVAL;
1512 }
1513 break;
1514 case AH_ESP_V4_FLOW:
1515 case AH_V4_FLOW:
1516 case ESP_V4_FLOW:
1517 case SCTP_V4_FLOW:
1518 if ((nfc->data & RXH_L4_B_0_1) ||
1519 (nfc->data & RXH_L4_B_2_3))
1520 return -EINVAL;
1521 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1522 break;
1523 case AH_ESP_V6_FLOW:
1524 case AH_V6_FLOW:
1525 case ESP_V6_FLOW:
1526 case SCTP_V6_FLOW:
1527 if ((nfc->data & RXH_L4_B_0_1) ||
1528 (nfc->data & RXH_L4_B_2_3))
1529 return -EINVAL;
1530 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1531 break;
1532 case IPV4_FLOW:
1533 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1534 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1535 break;
1536 case IPV6_FLOW:
1537 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1538 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1539 break;
1540 default:
1541 return -EINVAL;
1542 }
1543
1544 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1545 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1546 i40e_flush(hw);
1547
1548 return 0;
1549}
1550
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001551/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001552 * i40e_match_fdir_input_set - Match a new filter against an existing one
1553 * @rule: The filter already added
1554 * @input: The new filter to comapre against
1555 *
1556 * Returns true if the two input set match
1557 **/
1558static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1559 struct i40e_fdir_filter *input)
1560{
1561 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1562 (rule->src_ip[0] != input->src_ip[0]) ||
1563 (rule->dst_port != input->dst_port) ||
1564 (rule->src_port != input->src_port))
1565 return false;
1566 return true;
1567}
1568
1569/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001570 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1571 * @vsi: Pointer to the targeted VSI
1572 * @input: The filter to update or NULL to indicate deletion
1573 * @sw_idx: Software index to the filter
1574 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001575 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001576 * This function updates (or deletes) a Flow Director entry from
1577 * the hlist of the corresponding PF
1578 *
1579 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001580 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001581static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1582 struct i40e_fdir_filter *input,
1583 u16 sw_idx,
1584 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001585{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001586 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001587 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001588 struct hlist_node *node2;
1589 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001590
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001591 parent = NULL;
1592 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001593
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001594 hlist_for_each_entry_safe(rule, node2,
1595 &pf->fdir_filter_list, fdir_node) {
1596 /* hash found, or no matching entry */
1597 if (rule->fd_id >= sw_idx)
1598 break;
1599 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001600 }
1601
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001602 /* if there is an old rule occupying our place remove it */
1603 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001604 if (input && !i40e_match_fdir_input_set(rule, input))
1605 err = i40e_add_del_fdir(vsi, rule, false);
1606 else if (!input)
1607 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001608 hlist_del(&rule->fdir_node);
1609 kfree(rule);
1610 pf->fdir_pf_active_filters--;
1611 }
1612
1613 /* If no input this was a delete, err should be 0 if a rule was
1614 * successfully found and removed from the list else -EINVAL
1615 */
1616 if (!input)
1617 return err;
1618
1619 /* initialize node and set software index */
1620 INIT_HLIST_NODE(&input->fdir_node);
1621
1622 /* add filter to the list */
1623 if (parent)
1624 hlist_add_after(&parent->fdir_node, &input->fdir_node);
1625 else
1626 hlist_add_head(&input->fdir_node,
1627 &pf->fdir_filter_list);
1628
1629 /* update counts */
1630 pf->fdir_pf_active_filters++;
1631
1632 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001633}
1634
1635/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001636 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
1637 * @vsi: Pointer to the targeted VSI
1638 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001639 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001640 * The function removes a Flow Director filter entry from the
1641 * hlist of the corresponding PF
1642 *
1643 * Returns 0 on success
1644 */
1645static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
1646 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001647{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001648 struct ethtool_rx_flow_spec *fsp =
1649 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001650 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001651 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001652
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001653 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001654
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001655 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001656 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001657}
1658
1659/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001660 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001661 * @vsi: pointer to the targeted VSI
1662 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001663 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001664 * Add Flow Director filters for a specific flow spec based on their
1665 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001666 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001667static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
1668 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001669{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001670 struct ethtool_rx_flow_spec *fsp;
1671 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001672 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001673 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001674
1675 if (!vsi)
1676 return -EINVAL;
1677
1678 pf = vsi->back;
1679
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001680 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
1681 return -EOPNOTSUPP;
1682
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001683 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001684 return -ENOSPC;
1685
1686 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
1687
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001688 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
1689 pf->hw.func_caps.fd_filters_guaranteed)) {
1690 return -EINVAL;
1691 }
1692
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001693 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
1694 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001695 return -EINVAL;
1696
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001697 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001698
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001699 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001700 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001701
1702 input->fd_id = fsp->location;
1703
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00001704 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
1705 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
1706 else
1707 input->dest_ctl =
1708 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
1709
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001710 input->q_index = fsp->ring_cookie;
1711 input->flex_off = 0;
1712 input->pctype = 0;
1713 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001714 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00001715 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001716 input->flow_type = fsp->flow_type;
1717 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001718
1719 /* Reverse the src and dest notion, since the HW expects them to be from
1720 * Tx perspective where as the input from user is from Rx filter view.
1721 */
1722 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
1723 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
1724 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
1725 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001726
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001727 ret = i40e_add_del_fdir(vsi, input, true);
1728 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001729 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001730 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001731 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001732
1733 return ret;
1734}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08001735
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001736/**
1737 * i40e_set_rxnfc - command to set RX flow classification rules
1738 * @netdev: network interface device structure
1739 * @cmd: ethtool rxnfc command
1740 *
1741 * Returns Success if the command is supported.
1742 **/
1743static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1744{
1745 struct i40e_netdev_priv *np = netdev_priv(netdev);
1746 struct i40e_vsi *vsi = np->vsi;
1747 struct i40e_pf *pf = vsi->back;
1748 int ret = -EOPNOTSUPP;
1749
1750 switch (cmd->cmd) {
1751 case ETHTOOL_SRXFH:
1752 ret = i40e_set_rss_hash_opt(pf, cmd);
1753 break;
1754 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001755 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001756 break;
1757 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001758 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001759 break;
1760 default:
1761 break;
1762 }
1763
1764 return ret;
1765}
1766
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001767/**
1768 * i40e_max_channels - get Max number of combined channels supported
1769 * @vsi: vsi pointer
1770 **/
1771static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
1772{
1773 /* TODO: This code assumes DCB and FD is disabled for now. */
1774 return vsi->alloc_queue_pairs;
1775}
1776
1777/**
1778 * i40e_get_channels - Get the current channels enabled and max supported etc.
1779 * @netdev: network interface device structure
1780 * @ch: ethtool channels structure
1781 *
1782 * We don't support separate tx and rx queues as channels. The other count
1783 * represents how many queues are being used for control. max_combined counts
1784 * how many queue pairs we can support. They may not be mapped 1 to 1 with
1785 * q_vectors since we support a lot more queue pairs than q_vectors.
1786 **/
1787static void i40e_get_channels(struct net_device *dev,
1788 struct ethtool_channels *ch)
1789{
1790 struct i40e_netdev_priv *np = netdev_priv(dev);
1791 struct i40e_vsi *vsi = np->vsi;
1792 struct i40e_pf *pf = vsi->back;
1793
1794 /* report maximum channels */
1795 ch->max_combined = i40e_max_channels(vsi);
1796
1797 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08001798 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001799 ch->max_other = ch->other_count;
1800
1801 /* Note: This code assumes DCB is disabled for now. */
1802 ch->combined_count = vsi->num_queue_pairs;
1803}
1804
1805/**
1806 * i40e_set_channels - Set the new channels count.
1807 * @netdev: network interface device structure
1808 * @ch: ethtool channels structure
1809 *
1810 * The new channels count may not be the same as requested by the user
1811 * since it gets rounded down to a power of 2 value.
1812 **/
1813static int i40e_set_channels(struct net_device *dev,
1814 struct ethtool_channels *ch)
1815{
1816 struct i40e_netdev_priv *np = netdev_priv(dev);
1817 unsigned int count = ch->combined_count;
1818 struct i40e_vsi *vsi = np->vsi;
1819 struct i40e_pf *pf = vsi->back;
1820 int new_count;
1821
1822 /* We do not support setting channels for any other VSI at present */
1823 if (vsi->type != I40E_VSI_MAIN)
1824 return -EINVAL;
1825
1826 /* verify they are not requesting separate vectors */
1827 if (!count || ch->rx_count || ch->tx_count)
1828 return -EINVAL;
1829
1830 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08001831 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001832 return -EINVAL;
1833
1834 /* verify the number of channels does not exceed hardware limits */
1835 if (count > i40e_max_channels(vsi))
1836 return -EINVAL;
1837
1838 /* update feature limits from largest to smallest supported values */
1839 /* TODO: Flow director limit, DCB etc */
1840
1841 /* cap RSS limit */
1842 if (count > pf->rss_size_max)
1843 count = pf->rss_size_max;
1844
1845 /* use rss_reconfig to rebuild with new queue count and update traffic
1846 * class queue mapping
1847 */
1848 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00001849 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001850 return 0;
1851 else
1852 return -EINVAL;
1853}
1854
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001855static const struct ethtool_ops i40e_ethtool_ops = {
1856 .get_settings = i40e_get_settings,
1857 .get_drvinfo = i40e_get_drvinfo,
1858 .get_regs_len = i40e_get_regs_len,
1859 .get_regs = i40e_get_regs,
1860 .nway_reset = i40e_nway_reset,
1861 .get_link = ethtool_op_get_link,
1862 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001863 .set_wol = i40e_set_wol,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001864 .get_eeprom_len = i40e_get_eeprom_len,
1865 .get_eeprom = i40e_get_eeprom,
1866 .get_ringparam = i40e_get_ringparam,
1867 .set_ringparam = i40e_set_ringparam,
1868 .get_pauseparam = i40e_get_pauseparam,
1869 .get_msglevel = i40e_get_msglevel,
1870 .set_msglevel = i40e_set_msglevel,
1871 .get_rxnfc = i40e_get_rxnfc,
1872 .set_rxnfc = i40e_set_rxnfc,
1873 .self_test = i40e_diag_test,
1874 .get_strings = i40e_get_strings,
1875 .set_phys_id = i40e_set_phys_id,
1876 .get_sset_count = i40e_get_sset_count,
1877 .get_ethtool_stats = i40e_get_ethtool_stats,
1878 .get_coalesce = i40e_get_coalesce,
1879 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001880 .get_channels = i40e_get_channels,
1881 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001882 .get_ts_info = i40e_get_ts_info,
1883};
1884
1885void i40e_set_ethtool_ops(struct net_device *netdev)
1886{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00001887 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001888}