blob: 6508a1b64a7ebc5f5f4427b20587bf3fe4666dd3 [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
460static u32 i40e_get_msglevel(struct net_device *netdev)
461{
462 struct i40e_netdev_priv *np = netdev_priv(netdev);
463 struct i40e_pf *pf = np->vsi->back;
464
465 return pf->msg_enable;
466}
467
468static void i40e_set_msglevel(struct net_device *netdev, u32 data)
469{
470 struct i40e_netdev_priv *np = netdev_priv(netdev);
471 struct i40e_pf *pf = np->vsi->back;
472
473 if (I40E_DEBUG_USER & data)
474 pf->hw.debug_mask = data;
475 pf->msg_enable = data;
476}
477
478static int i40e_get_regs_len(struct net_device *netdev)
479{
480 int reg_count = 0;
481 int i;
482
483 for (i = 0; i40e_reg_list[i].offset != 0; i++)
484 reg_count += i40e_reg_list[i].elements;
485
486 return reg_count * sizeof(u32);
487}
488
489static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
490 void *p)
491{
492 struct i40e_netdev_priv *np = netdev_priv(netdev);
493 struct i40e_pf *pf = np->vsi->back;
494 struct i40e_hw *hw = &pf->hw;
495 u32 *reg_buf = p;
496 int i, j, ri;
497 u32 reg;
498
499 /* Tell ethtool which driver-version-specific regs output we have.
500 *
501 * At some point, if we have ethtool doing special formatting of
502 * this data, it will rely on this version number to know how to
503 * interpret things. Hence, this needs to be updated if/when the
504 * diags register table is changed.
505 */
506 regs->version = 1;
507
508 /* loop through the diags reg table for what to print */
509 ri = 0;
510 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
511 for (j = 0; j < i40e_reg_list[i].elements; j++) {
512 reg = i40e_reg_list[i].offset
513 + (j * i40e_reg_list[i].stride);
514 reg_buf[ri++] = rd32(hw, reg);
515 }
516 }
517
518}
519
520static int i40e_get_eeprom(struct net_device *netdev,
521 struct ethtool_eeprom *eeprom, u8 *bytes)
522{
523 struct i40e_netdev_priv *np = netdev_priv(netdev);
524 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000525 struct i40e_pf *pf = np->vsi->back;
526 int ret_val = 0, len;
527 u8 *eeprom_buff;
528 u16 i, sectors;
529 bool last;
530#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000531 if (eeprom->len == 0)
532 return -EINVAL;
533
534 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
535
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000536 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000537 if (!eeprom_buff)
538 return -ENOMEM;
539
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000540 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
541 if (ret_val) {
542 dev_info(&pf->pdev->dev,
543 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
544 ret_val, hw->aq.asq_last_status);
545 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000546 }
547
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000548 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
549 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
550 len = I40E_NVM_SECTOR_SIZE;
551 last = false;
552 for (i = 0; i < sectors; i++) {
553 if (i == (sectors - 1)) {
554 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
555 last = true;
556 }
557 ret_val = i40e_aq_read_nvm(hw, 0x0,
558 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
559 len,
Joe Perches3dbb7fd2014-03-25 04:30:38 +0000560 eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000561 last, NULL);
562 if (ret_val) {
563 dev_info(&pf->pdev->dev,
564 "read NVM failed err=%d status=0x%x\n",
565 ret_val, hw->aq.asq_last_status);
566 goto release_nvm;
567 }
568 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000569
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000570release_nvm:
571 i40e_release_nvm(hw);
Joe Perches3dbb7fd2014-03-25 04:30:38 +0000572 memcpy(bytes, eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000573free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000574 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000575 return ret_val;
576}
577
578static int i40e_get_eeprom_len(struct net_device *netdev)
579{
580 struct i40e_netdev_priv *np = netdev_priv(netdev);
581 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000582 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000583
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000584 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
585 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
586 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
587 /* register returns value in power of 2, 64Kbyte chunks. */
588 val = (64 * 1024) * (1 << val);
589 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000590}
591
592static void i40e_get_drvinfo(struct net_device *netdev,
593 struct ethtool_drvinfo *drvinfo)
594{
595 struct i40e_netdev_priv *np = netdev_priv(netdev);
596 struct i40e_vsi *vsi = np->vsi;
597 struct i40e_pf *pf = vsi->back;
598
599 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
600 strlcpy(drvinfo->version, i40e_driver_version_str,
601 sizeof(drvinfo->version));
602 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
603 sizeof(drvinfo->fw_version));
604 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
605 sizeof(drvinfo->bus_info));
606}
607
608static void i40e_get_ringparam(struct net_device *netdev,
609 struct ethtool_ringparam *ring)
610{
611 struct i40e_netdev_priv *np = netdev_priv(netdev);
612 struct i40e_pf *pf = np->vsi->back;
613 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
614
615 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
616 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
617 ring->rx_mini_max_pending = 0;
618 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +0000619 ring->rx_pending = vsi->rx_rings[0]->count;
620 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000621 ring->rx_mini_pending = 0;
622 ring->rx_jumbo_pending = 0;
623}
624
625static int i40e_set_ringparam(struct net_device *netdev,
626 struct ethtool_ringparam *ring)
627{
628 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
629 struct i40e_netdev_priv *np = netdev_priv(netdev);
630 struct i40e_vsi *vsi = np->vsi;
631 struct i40e_pf *pf = vsi->back;
632 u32 new_rx_count, new_tx_count;
633 int i, err = 0;
634
635 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
636 return -EINVAL;
637
Shannon Nelson1fa18372013-11-20 10:03:08 +0000638 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
639 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
640 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
641 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
642 netdev_info(netdev,
643 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
644 ring->tx_pending, ring->rx_pending,
645 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
646 return -EINVAL;
647 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000648
Shannon Nelson1fa18372013-11-20 10:03:08 +0000649 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
650 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000651
652 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000653 if ((new_tx_count == vsi->tx_rings[0]->count) &&
654 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000655 return 0;
656
657 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
658 usleep_range(1000, 2000);
659
660 if (!netif_running(vsi->netdev)) {
661 /* simple case - set for the next time the netdev is started */
662 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000663 vsi->tx_rings[i]->count = new_tx_count;
664 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000665 }
666 goto done;
667 }
668
669 /* We can't just free everything and then setup again,
670 * because the ISRs in MSI-X mode get passed pointers
671 * to the Tx and Rx ring structs.
672 */
673
674 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000675 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000676 netdev_info(netdev,
677 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000678 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000679 tx_rings = kcalloc(vsi->alloc_queue_pairs,
680 sizeof(struct i40e_ring), GFP_KERNEL);
681 if (!tx_rings) {
682 err = -ENOMEM;
683 goto done;
684 }
685
686 for (i = 0; i < vsi->num_queue_pairs; i++) {
687 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000688 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000689 tx_rings[i].count = new_tx_count;
690 err = i40e_setup_tx_descriptors(&tx_rings[i]);
691 if (err) {
692 while (i) {
693 i--;
694 i40e_free_tx_resources(&tx_rings[i]);
695 }
696 kfree(tx_rings);
697 tx_rings = NULL;
698
699 goto done;
700 }
701 }
702 }
703
704 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000705 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000706 netdev_info(netdev,
707 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000708 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000709 rx_rings = kcalloc(vsi->alloc_queue_pairs,
710 sizeof(struct i40e_ring), GFP_KERNEL);
711 if (!rx_rings) {
712 err = -ENOMEM;
713 goto free_tx;
714 }
715
716 for (i = 0; i < vsi->num_queue_pairs; i++) {
717 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000718 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000719 rx_rings[i].count = new_rx_count;
720 err = i40e_setup_rx_descriptors(&rx_rings[i]);
721 if (err) {
722 while (i) {
723 i--;
724 i40e_free_rx_resources(&rx_rings[i]);
725 }
726 kfree(rx_rings);
727 rx_rings = NULL;
728
729 goto free_tx;
730 }
731 }
732 }
733
734 /* Bring interface down, copy in the new ring info,
735 * then restore the interface
736 */
737 i40e_down(vsi);
738
739 if (tx_rings) {
740 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000741 i40e_free_tx_resources(vsi->tx_rings[i]);
742 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000743 }
744 kfree(tx_rings);
745 tx_rings = NULL;
746 }
747
748 if (rx_rings) {
749 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000750 i40e_free_rx_resources(vsi->rx_rings[i]);
751 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000752 }
753 kfree(rx_rings);
754 rx_rings = NULL;
755 }
756
757 i40e_up(vsi);
758
759free_tx:
760 /* error cleanup if the Rx allocations failed after getting Tx */
761 if (tx_rings) {
762 for (i = 0; i < vsi->num_queue_pairs; i++)
763 i40e_free_tx_resources(&tx_rings[i]);
764 kfree(tx_rings);
765 tx_rings = NULL;
766 }
767
768done:
769 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
770
771 return err;
772}
773
774static int i40e_get_sset_count(struct net_device *netdev, int sset)
775{
776 struct i40e_netdev_priv *np = netdev_priv(netdev);
777 struct i40e_vsi *vsi = np->vsi;
778 struct i40e_pf *pf = vsi->back;
779
780 switch (sset) {
781 case ETH_SS_TEST:
782 return I40E_TEST_LEN;
783 case ETH_SS_STATS:
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000784 if (vsi == pf->vsi[pf->lan_vsi]) {
785 int len = I40E_PF_STATS_LEN(netdev);
786
787 if (pf->lan_veb != I40E_NO_VEB)
788 len += I40E_VEB_STATS_LEN;
789 return len;
790 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000791 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000792 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000793 default:
794 return -EOPNOTSUPP;
795 }
796}
797
798static void i40e_get_ethtool_stats(struct net_device *netdev,
799 struct ethtool_stats *stats, u64 *data)
800{
801 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +0000802 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000803 struct i40e_vsi *vsi = np->vsi;
804 struct i40e_pf *pf = vsi->back;
805 int i = 0;
806 char *p;
807 int j;
808 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000809 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000810
811 i40e_update_stats(vsi);
812
813 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
814 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
815 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
816 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
817 }
Shannon Nelson41a9e552014-04-23 04:50:20 +0000818 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
819 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
820 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
821 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
822 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000823 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000824 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +0000825 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000826
827 if (!tx_ring)
828 continue;
829
830 /* process Tx ring statistics */
831 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700832 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000833 data[i] = tx_ring->stats.packets;
834 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700835 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000836 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000837
838 /* Rx ring is the 2nd half of the queue pair */
839 rx_ring = &tx_ring[1];
840 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700841 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000842 data[i] = rx_ring->stats.packets;
843 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700844 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000845 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000846 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000847 rcu_read_unlock();
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000848 if (vsi != pf->vsi[pf->lan_vsi])
849 return;
850
851 if (pf->lan_veb != I40E_NO_VEB) {
852 struct i40e_veb *veb = pf->veb[pf->lan_veb];
853 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
854 p = (char *)veb;
855 p += i40e_gstrings_veb_stats[j].stat_offset;
856 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
857 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000858 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000859 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000860 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
861 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
862 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
863 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
864 }
865 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
866 data[i++] = pf->stats.priority_xon_tx[j];
867 data[i++] = pf->stats.priority_xoff_tx[j];
868 }
869 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
870 data[i++] = pf->stats.priority_xon_rx[j];
871 data[i++] = pf->stats.priority_xoff_rx[j];
872 }
873 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
874 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000875}
876
877static void i40e_get_strings(struct net_device *netdev, u32 stringset,
878 u8 *data)
879{
880 struct i40e_netdev_priv *np = netdev_priv(netdev);
881 struct i40e_vsi *vsi = np->vsi;
882 struct i40e_pf *pf = vsi->back;
883 char *p = (char *)data;
884 int i;
885
886 switch (stringset) {
887 case ETH_SS_TEST:
888 for (i = 0; i < I40E_TEST_LEN; i++) {
889 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
890 data += ETH_GSTRING_LEN;
891 }
892 break;
893 case ETH_SS_STATS:
894 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
895 snprintf(p, ETH_GSTRING_LEN, "%s",
896 i40e_gstrings_net_stats[i].stat_string);
897 p += ETH_GSTRING_LEN;
898 }
Shannon Nelson41a9e552014-04-23 04:50:20 +0000899 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
900 snprintf(p, ETH_GSTRING_LEN, "%s",
901 i40e_gstrings_misc_stats[i].stat_string);
902 p += ETH_GSTRING_LEN;
903 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000904 for (i = 0; i < vsi->num_queue_pairs; i++) {
905 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
906 p += ETH_GSTRING_LEN;
907 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
908 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000909 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
910 p += ETH_GSTRING_LEN;
911 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
912 p += ETH_GSTRING_LEN;
913 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000914 if (vsi != pf->vsi[pf->lan_vsi])
915 return;
916
917 if (pf->lan_veb != I40E_NO_VEB) {
918 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
919 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
920 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000921 p += ETH_GSTRING_LEN;
922 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000923 }
924 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
925 snprintf(p, ETH_GSTRING_LEN, "port.%s",
926 i40e_gstrings_stats[i].stat_string);
927 p += ETH_GSTRING_LEN;
928 }
929 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
930 snprintf(p, ETH_GSTRING_LEN,
931 "port.tx_priority_%u_xon", i);
932 p += ETH_GSTRING_LEN;
933 snprintf(p, ETH_GSTRING_LEN,
934 "port.tx_priority_%u_xoff", i);
935 p += ETH_GSTRING_LEN;
936 }
937 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
938 snprintf(p, ETH_GSTRING_LEN,
939 "port.rx_priority_%u_xon", i);
940 p += ETH_GSTRING_LEN;
941 snprintf(p, ETH_GSTRING_LEN,
942 "port.rx_priority_%u_xoff", i);
943 p += ETH_GSTRING_LEN;
944 }
945 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
946 snprintf(p, ETH_GSTRING_LEN,
947 "port.rx_priority_%u_xon_2_xoff", i);
948 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000949 }
950 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
951 break;
952 }
953}
954
955static int i40e_get_ts_info(struct net_device *dev,
956 struct ethtool_ts_info *info)
957{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000958 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
959
960 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
961 SOF_TIMESTAMPING_RX_SOFTWARE |
962 SOF_TIMESTAMPING_SOFTWARE |
963 SOF_TIMESTAMPING_TX_HARDWARE |
964 SOF_TIMESTAMPING_RX_HARDWARE |
965 SOF_TIMESTAMPING_RAW_HARDWARE;
966
967 if (pf->ptp_clock)
968 info->phc_index = ptp_clock_index(pf->ptp_clock);
969 else
970 info->phc_index = -1;
971
972 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
973
974 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
975 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
976 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
977 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
978 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
979 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
980 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
981 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
982 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
983 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
984 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
985 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
986
987 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000988}
989
Shannon Nelson7b086392013-11-20 10:02:59 +0000990static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000991{
Shannon Nelson7b086392013-11-20 10:02:59 +0000992 struct i40e_netdev_priv *np = netdev_priv(netdev);
993 struct i40e_pf *pf = np->vsi->back;
994
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000995 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000996 if (i40e_get_link_status(&pf->hw))
997 *data = 0;
998 else
999 *data = 1;
1000
1001 return *data;
1002}
1003
Shannon Nelson7b086392013-11-20 10:02:59 +00001004static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001005{
Shannon Nelson7b086392013-11-20 10:02:59 +00001006 struct i40e_netdev_priv *np = netdev_priv(netdev);
1007 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001008
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001009 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001010 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001011
Shannon Nelson7b086392013-11-20 10:02:59 +00001012 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001013}
1014
Shannon Nelson7b086392013-11-20 10:02:59 +00001015static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001016{
Shannon Nelson7b086392013-11-20 10:02:59 +00001017 struct i40e_netdev_priv *np = netdev_priv(netdev);
1018 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001019
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001020 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001021 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001022
Shannon Nelson7b086392013-11-20 10:02:59 +00001023 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001024}
1025
Shannon Nelson7b086392013-11-20 10:02:59 +00001026static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001027{
Shannon Nelson7b086392013-11-20 10:02:59 +00001028 struct i40e_netdev_priv *np = netdev_priv(netdev);
1029 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001030 u16 swc_old = pf->sw_int_count;
1031
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001032 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001033 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1034 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
1035 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
1036 usleep_range(1000, 2000);
1037 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001038
1039 return *data;
1040}
1041
Shannon Nelson7b086392013-11-20 10:02:59 +00001042static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001043{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001044 struct i40e_netdev_priv *np = netdev_priv(netdev);
1045 struct i40e_pf *pf = np->vsi->back;
1046
1047 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001048 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001049
1050 return *data;
1051}
1052
1053static void i40e_diag_test(struct net_device *netdev,
1054 struct ethtool_test *eth_test, u64 *data)
1055{
1056 struct i40e_netdev_priv *np = netdev_priv(netdev);
1057 struct i40e_pf *pf = np->vsi->back;
1058
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001059 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1060 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001061 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001062
Shannon Nelsonf551b432013-11-26 10:49:12 +00001063 set_bit(__I40E_TESTING, &pf->state);
1064
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001065 /* Link test performed before hardware reset
1066 * so autoneg doesn't interfere with test result
1067 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001068 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001069 eth_test->flags |= ETH_TEST_FL_FAILED;
1070
Shannon Nelson7b086392013-11-20 10:02:59 +00001071 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001072 eth_test->flags |= ETH_TEST_FL_FAILED;
1073
Shannon Nelson7b086392013-11-20 10:02:59 +00001074 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001075 eth_test->flags |= ETH_TEST_FL_FAILED;
1076
Shannon Nelson7b086392013-11-20 10:02:59 +00001077 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001078 eth_test->flags |= ETH_TEST_FL_FAILED;
1079
Shannon Nelsonf551b432013-11-26 10:49:12 +00001080 /* run reg test last, a reset is required after it */
1081 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1082 eth_test->flags |= ETH_TEST_FL_FAILED;
1083
1084 clear_bit(__I40E_TESTING, &pf->state);
1085 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001086 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001087 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001088 netif_info(pf, drv, netdev, "online testing starting\n");
1089
Shannon Nelson7b086392013-11-20 10:02:59 +00001090 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001091 eth_test->flags |= ETH_TEST_FL_FAILED;
1092
1093 /* Offline only tests, not run in online; pass by default */
1094 data[I40E_ETH_TEST_REG] = 0;
1095 data[I40E_ETH_TEST_EEPROM] = 0;
1096 data[I40E_ETH_TEST_INTR] = 0;
1097 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001098 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001099
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001100 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001101}
1102
1103static void i40e_get_wol(struct net_device *netdev,
1104 struct ethtool_wolinfo *wol)
1105{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001106 struct i40e_netdev_priv *np = netdev_priv(netdev);
1107 struct i40e_pf *pf = np->vsi->back;
1108 struct i40e_hw *hw = &pf->hw;
1109 u16 wol_nvm_bits;
1110
1111 /* NVM bit on means WoL disabled for the port */
1112 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1113 if ((1 << hw->port) & wol_nvm_bits) {
1114 wol->supported = 0;
1115 wol->wolopts = 0;
1116 } else {
1117 wol->supported = WAKE_MAGIC;
1118 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1119 }
1120}
1121
1122static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1123{
1124 struct i40e_netdev_priv *np = netdev_priv(netdev);
1125 struct i40e_pf *pf = np->vsi->back;
1126 struct i40e_hw *hw = &pf->hw;
1127 u16 wol_nvm_bits;
1128
1129 /* NVM bit on means WoL disabled for the port */
1130 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1131 if (((1 << hw->port) & wol_nvm_bits))
1132 return -EOPNOTSUPP;
1133
1134 /* only magic packet is supported */
1135 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1136 return -EOPNOTSUPP;
1137
1138 /* is this a new value? */
1139 if (pf->wol_en != !!wol->wolopts) {
1140 pf->wol_en = !!wol->wolopts;
1141 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1142 }
1143
1144 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001145}
1146
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001147static 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}