blob: 7f03b232975f4c8695450ad13cd03818211d4710 [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),
61 I40E_NETDEV_STAT(multicast),
62 I40E_NETDEV_STAT(collisions),
63 I40E_NETDEV_STAT(rx_length_errors),
64 I40E_NETDEV_STAT(rx_crc_errors),
65};
66
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000067static const struct i40e_stats i40e_gstrings_veb_stats[] = {
68 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
69 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
70 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
71 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
72 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
73 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
74 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
75 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
76 I40E_VEB_STAT("rx_discards", stats.rx_discards),
77 I40E_VEB_STAT("tx_discards", stats.tx_discards),
78 I40E_VEB_STAT("tx_errors", stats.tx_errors),
79 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
80};
81
Shannon Nelson41a9e552014-04-23 04:50:20 +000082static const struct i40e_stats i40e_gstrings_misc_stats[] = {
83 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
84 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
85 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
86};
87
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +000088static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
89 struct ethtool_rxnfc *cmd);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +000090
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000091/* These PF_STATs might look like duplicates of some NETDEV_STATs,
92 * but they are separate. This device supports Virtualization, and
93 * as such might have several netdevs supporting VMDq and FCoE going
94 * through a single port. The NETDEV_STATs are for individual netdevs
95 * seen at the top of the stack, and the PF_STATs are for the physical
96 * function at the bottom of the stack hosting those netdevs.
97 *
98 * The PF_STATs are appended to the netdev stats only when ethtool -S
99 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
100 */
101static struct i40e_stats i40e_gstrings_stats[] = {
102 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
103 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000104 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
105 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
106 I40E_PF_STAT("tx_dropped", stats.eth.tx_discards),
107 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
108 I40E_PF_STAT("crc_errors", stats.crc_errors),
109 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
110 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
111 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000112 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000113 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
114 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
115 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
116 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
117 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
118 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
119 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
120 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
121 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
122 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
123 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
124 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
125 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
126 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
127 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
128 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
129 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
130 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
131 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
132 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
133 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
134 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
135 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
136 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000137 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000138 /* LPI stats */
139 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
140 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
141 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
142 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000143};
144
145#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000146 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
147 * 2 /* Tx and Rx together */ \
148 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000149#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
150#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000151#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000152#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000153 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000154 I40E_QUEUE_STATS_LEN((n)))
155#define I40E_PFC_STATS_LEN ( \
156 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
157 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
158 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
159 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
160 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
161 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000162#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000163#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
164 I40E_PFC_STATS_LEN + \
165 I40E_VSI_STATS_LEN((n)))
166
167enum i40e_ethtool_test_id {
168 I40E_ETH_TEST_REG = 0,
169 I40E_ETH_TEST_EEPROM,
170 I40E_ETH_TEST_INTR,
171 I40E_ETH_TEST_LOOPBACK,
172 I40E_ETH_TEST_LINK,
173};
174
175static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
176 "Register test (offline)",
177 "Eeprom test (offline)",
178 "Interrupt test (offline)",
179 "Loopback test (offline)",
180 "Link test (on/offline)"
181};
182
183#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
184
185/**
186 * i40e_get_settings - Get Link Speed and Duplex settings
187 * @netdev: network interface device structure
188 * @ecmd: ethtool command
189 *
190 * Reports speed/duplex settings based on media_type
191 **/
192static int i40e_get_settings(struct net_device *netdev,
193 struct ethtool_cmd *ecmd)
194{
195 struct i40e_netdev_priv *np = netdev_priv(netdev);
196 struct i40e_pf *pf = np->vsi->back;
197 struct i40e_hw *hw = &pf->hw;
198 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
199 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
200 u32 link_speed = hw_link_info->link_speed;
201
202 /* hardware is either in 40G mode or 10G mode
203 * NOTE: this section initializes supported and advertising
204 */
205 switch (hw_link_info->phy_type) {
206 case I40E_PHY_TYPE_40GBASE_CR4:
207 case I40E_PHY_TYPE_40GBASE_CR4_CU:
208 ecmd->supported = SUPPORTED_40000baseCR4_Full;
209 ecmd->advertising = ADVERTISED_40000baseCR4_Full;
210 break;
211 case I40E_PHY_TYPE_40GBASE_KR4:
212 ecmd->supported = SUPPORTED_40000baseKR4_Full;
213 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
214 break;
215 case I40E_PHY_TYPE_40GBASE_SR4:
216 ecmd->supported = SUPPORTED_40000baseSR4_Full;
217 ecmd->advertising = ADVERTISED_40000baseSR4_Full;
218 break;
219 case I40E_PHY_TYPE_40GBASE_LR4:
220 ecmd->supported = SUPPORTED_40000baseLR4_Full;
221 ecmd->advertising = ADVERTISED_40000baseLR4_Full;
222 break;
223 case I40E_PHY_TYPE_10GBASE_KX4:
224 ecmd->supported = SUPPORTED_10000baseKX4_Full;
225 ecmd->advertising = ADVERTISED_10000baseKX4_Full;
226 break;
227 case I40E_PHY_TYPE_10GBASE_KR:
228 ecmd->supported = SUPPORTED_10000baseKR_Full;
229 ecmd->advertising = ADVERTISED_10000baseKR_Full;
230 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000231 default:
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000232 if (i40e_is_40G_device(hw->device_id)) {
233 ecmd->supported = SUPPORTED_40000baseSR4_Full;
234 ecmd->advertising = ADVERTISED_40000baseSR4_Full;
235 } else {
236 ecmd->supported = SUPPORTED_10000baseT_Full;
237 ecmd->advertising = ADVERTISED_10000baseT_Full;
238 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000239 break;
240 }
241
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000242 ecmd->supported |= SUPPORTED_Autoneg;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000243 ecmd->advertising |= ADVERTISED_Autoneg;
244 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
245 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000246
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000247 switch (hw->phy.media_type) {
248 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000249 ecmd->supported |= SUPPORTED_Backplane;
250 ecmd->advertising |= ADVERTISED_Backplane;
251 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000252 break;
253 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000254 ecmd->supported |= SUPPORTED_TP;
255 ecmd->advertising |= ADVERTISED_TP;
256 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000257 break;
258 case I40E_MEDIA_TYPE_DA:
259 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000260 ecmd->supported |= SUPPORTED_FIBRE;
261 ecmd->advertising |= ADVERTISED_FIBRE;
262 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000263 break;
264 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000265 ecmd->supported |= SUPPORTED_FIBRE;
266 ecmd->advertising |= ADVERTISED_FIBRE;
267 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000268 break;
269 case I40E_MEDIA_TYPE_UNKNOWN:
270 default:
271 ecmd->port = PORT_OTHER;
272 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000273 }
274
275 ecmd->transceiver = XCVR_EXTERNAL;
276
277 if (link_up) {
278 switch (link_speed) {
279 case I40E_LINK_SPEED_40GB:
280 /* need a SPEED_40000 in ethtool.h */
281 ethtool_cmd_speed_set(ecmd, 40000);
282 break;
283 case I40E_LINK_SPEED_10GB:
284 ethtool_cmd_speed_set(ecmd, SPEED_10000);
285 break;
286 default:
287 break;
288 }
289 ecmd->duplex = DUPLEX_FULL;
290 } else {
291 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
292 ecmd->duplex = DUPLEX_UNKNOWN;
293 }
294
295 return 0;
296}
297
298/**
299 * i40e_get_pauseparam - Get Flow Control status
300 * Return tx/rx-pause status
301 **/
302static void i40e_get_pauseparam(struct net_device *netdev,
303 struct ethtool_pauseparam *pause)
304{
305 struct i40e_netdev_priv *np = netdev_priv(netdev);
306 struct i40e_pf *pf = np->vsi->back;
307 struct i40e_hw *hw = &pf->hw;
308 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
309
310 pause->autoneg =
311 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
312 AUTONEG_ENABLE : AUTONEG_DISABLE);
313
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000314 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000315 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000316 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000317 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000318 } else if (hw->fc.current_mode == I40E_FC_FULL) {
319 pause->rx_pause = 1;
320 pause->tx_pause = 1;
321 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000322}
323
324static u32 i40e_get_msglevel(struct net_device *netdev)
325{
326 struct i40e_netdev_priv *np = netdev_priv(netdev);
327 struct i40e_pf *pf = np->vsi->back;
328
329 return pf->msg_enable;
330}
331
332static void i40e_set_msglevel(struct net_device *netdev, u32 data)
333{
334 struct i40e_netdev_priv *np = netdev_priv(netdev);
335 struct i40e_pf *pf = np->vsi->back;
336
337 if (I40E_DEBUG_USER & data)
338 pf->hw.debug_mask = data;
339 pf->msg_enable = data;
340}
341
342static int i40e_get_regs_len(struct net_device *netdev)
343{
344 int reg_count = 0;
345 int i;
346
347 for (i = 0; i40e_reg_list[i].offset != 0; i++)
348 reg_count += i40e_reg_list[i].elements;
349
350 return reg_count * sizeof(u32);
351}
352
353static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
354 void *p)
355{
356 struct i40e_netdev_priv *np = netdev_priv(netdev);
357 struct i40e_pf *pf = np->vsi->back;
358 struct i40e_hw *hw = &pf->hw;
359 u32 *reg_buf = p;
360 int i, j, ri;
361 u32 reg;
362
363 /* Tell ethtool which driver-version-specific regs output we have.
364 *
365 * At some point, if we have ethtool doing special formatting of
366 * this data, it will rely on this version number to know how to
367 * interpret things. Hence, this needs to be updated if/when the
368 * diags register table is changed.
369 */
370 regs->version = 1;
371
372 /* loop through the diags reg table for what to print */
373 ri = 0;
374 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
375 for (j = 0; j < i40e_reg_list[i].elements; j++) {
376 reg = i40e_reg_list[i].offset
377 + (j * i40e_reg_list[i].stride);
378 reg_buf[ri++] = rd32(hw, reg);
379 }
380 }
381
382}
383
384static int i40e_get_eeprom(struct net_device *netdev,
385 struct ethtool_eeprom *eeprom, u8 *bytes)
386{
387 struct i40e_netdev_priv *np = netdev_priv(netdev);
388 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000389 struct i40e_pf *pf = np->vsi->back;
390 int ret_val = 0, len;
391 u8 *eeprom_buff;
392 u16 i, sectors;
393 bool last;
394#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000395 if (eeprom->len == 0)
396 return -EINVAL;
397
398 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
399
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000400 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000401 if (!eeprom_buff)
402 return -ENOMEM;
403
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000404 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
405 if (ret_val) {
406 dev_info(&pf->pdev->dev,
407 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
408 ret_val, hw->aq.asq_last_status);
409 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000410 }
411
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000412 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
413 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
414 len = I40E_NVM_SECTOR_SIZE;
415 last = false;
416 for (i = 0; i < sectors; i++) {
417 if (i == (sectors - 1)) {
418 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
419 last = true;
420 }
421 ret_val = i40e_aq_read_nvm(hw, 0x0,
422 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
423 len,
Joe Perches3dbb7fd2014-03-25 04:30:38 +0000424 eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000425 last, NULL);
426 if (ret_val) {
427 dev_info(&pf->pdev->dev,
428 "read NVM failed err=%d status=0x%x\n",
429 ret_val, hw->aq.asq_last_status);
430 goto release_nvm;
431 }
432 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000433
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000434release_nvm:
435 i40e_release_nvm(hw);
Joe Perches3dbb7fd2014-03-25 04:30:38 +0000436 memcpy(bytes, eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000437free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000438 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000439 return ret_val;
440}
441
442static int i40e_get_eeprom_len(struct net_device *netdev)
443{
444 struct i40e_netdev_priv *np = netdev_priv(netdev);
445 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000446 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000447
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000448 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
449 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
450 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
451 /* register returns value in power of 2, 64Kbyte chunks. */
452 val = (64 * 1024) * (1 << val);
453 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000454}
455
456static void i40e_get_drvinfo(struct net_device *netdev,
457 struct ethtool_drvinfo *drvinfo)
458{
459 struct i40e_netdev_priv *np = netdev_priv(netdev);
460 struct i40e_vsi *vsi = np->vsi;
461 struct i40e_pf *pf = vsi->back;
462
463 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
464 strlcpy(drvinfo->version, i40e_driver_version_str,
465 sizeof(drvinfo->version));
466 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
467 sizeof(drvinfo->fw_version));
468 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
469 sizeof(drvinfo->bus_info));
470}
471
472static void i40e_get_ringparam(struct net_device *netdev,
473 struct ethtool_ringparam *ring)
474{
475 struct i40e_netdev_priv *np = netdev_priv(netdev);
476 struct i40e_pf *pf = np->vsi->back;
477 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
478
479 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
480 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
481 ring->rx_mini_max_pending = 0;
482 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +0000483 ring->rx_pending = vsi->rx_rings[0]->count;
484 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000485 ring->rx_mini_pending = 0;
486 ring->rx_jumbo_pending = 0;
487}
488
489static int i40e_set_ringparam(struct net_device *netdev,
490 struct ethtool_ringparam *ring)
491{
492 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
493 struct i40e_netdev_priv *np = netdev_priv(netdev);
494 struct i40e_vsi *vsi = np->vsi;
495 struct i40e_pf *pf = vsi->back;
496 u32 new_rx_count, new_tx_count;
497 int i, err = 0;
498
499 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
500 return -EINVAL;
501
Shannon Nelson1fa18372013-11-20 10:03:08 +0000502 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
503 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
504 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
505 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
506 netdev_info(netdev,
507 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
508 ring->tx_pending, ring->rx_pending,
509 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
510 return -EINVAL;
511 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000512
Shannon Nelson1fa18372013-11-20 10:03:08 +0000513 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
514 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000515
516 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000517 if ((new_tx_count == vsi->tx_rings[0]->count) &&
518 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000519 return 0;
520
521 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
522 usleep_range(1000, 2000);
523
524 if (!netif_running(vsi->netdev)) {
525 /* simple case - set for the next time the netdev is started */
526 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000527 vsi->tx_rings[i]->count = new_tx_count;
528 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000529 }
530 goto done;
531 }
532
533 /* We can't just free everything and then setup again,
534 * because the ISRs in MSI-X mode get passed pointers
535 * to the Tx and Rx ring structs.
536 */
537
538 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000539 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000540 netdev_info(netdev,
541 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000542 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000543 tx_rings = kcalloc(vsi->alloc_queue_pairs,
544 sizeof(struct i40e_ring), GFP_KERNEL);
545 if (!tx_rings) {
546 err = -ENOMEM;
547 goto done;
548 }
549
550 for (i = 0; i < vsi->num_queue_pairs; i++) {
551 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000552 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000553 tx_rings[i].count = new_tx_count;
554 err = i40e_setup_tx_descriptors(&tx_rings[i]);
555 if (err) {
556 while (i) {
557 i--;
558 i40e_free_tx_resources(&tx_rings[i]);
559 }
560 kfree(tx_rings);
561 tx_rings = NULL;
562
563 goto done;
564 }
565 }
566 }
567
568 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000569 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000570 netdev_info(netdev,
571 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000572 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000573 rx_rings = kcalloc(vsi->alloc_queue_pairs,
574 sizeof(struct i40e_ring), GFP_KERNEL);
575 if (!rx_rings) {
576 err = -ENOMEM;
577 goto free_tx;
578 }
579
580 for (i = 0; i < vsi->num_queue_pairs; i++) {
581 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000582 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000583 rx_rings[i].count = new_rx_count;
584 err = i40e_setup_rx_descriptors(&rx_rings[i]);
585 if (err) {
586 while (i) {
587 i--;
588 i40e_free_rx_resources(&rx_rings[i]);
589 }
590 kfree(rx_rings);
591 rx_rings = NULL;
592
593 goto free_tx;
594 }
595 }
596 }
597
598 /* Bring interface down, copy in the new ring info,
599 * then restore the interface
600 */
601 i40e_down(vsi);
602
603 if (tx_rings) {
604 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000605 i40e_free_tx_resources(vsi->tx_rings[i]);
606 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000607 }
608 kfree(tx_rings);
609 tx_rings = NULL;
610 }
611
612 if (rx_rings) {
613 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000614 i40e_free_rx_resources(vsi->rx_rings[i]);
615 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000616 }
617 kfree(rx_rings);
618 rx_rings = NULL;
619 }
620
621 i40e_up(vsi);
622
623free_tx:
624 /* error cleanup if the Rx allocations failed after getting Tx */
625 if (tx_rings) {
626 for (i = 0; i < vsi->num_queue_pairs; i++)
627 i40e_free_tx_resources(&tx_rings[i]);
628 kfree(tx_rings);
629 tx_rings = NULL;
630 }
631
632done:
633 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
634
635 return err;
636}
637
638static int i40e_get_sset_count(struct net_device *netdev, int sset)
639{
640 struct i40e_netdev_priv *np = netdev_priv(netdev);
641 struct i40e_vsi *vsi = np->vsi;
642 struct i40e_pf *pf = vsi->back;
643
644 switch (sset) {
645 case ETH_SS_TEST:
646 return I40E_TEST_LEN;
647 case ETH_SS_STATS:
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000648 if (vsi == pf->vsi[pf->lan_vsi]) {
649 int len = I40E_PF_STATS_LEN(netdev);
650
651 if (pf->lan_veb != I40E_NO_VEB)
652 len += I40E_VEB_STATS_LEN;
653 return len;
654 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000655 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000656 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000657 default:
658 return -EOPNOTSUPP;
659 }
660}
661
662static void i40e_get_ethtool_stats(struct net_device *netdev,
663 struct ethtool_stats *stats, u64 *data)
664{
665 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +0000666 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000667 struct i40e_vsi *vsi = np->vsi;
668 struct i40e_pf *pf = vsi->back;
669 int i = 0;
670 char *p;
671 int j;
672 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000673 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000674
675 i40e_update_stats(vsi);
676
677 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
678 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
679 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
680 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
681 }
Shannon Nelson41a9e552014-04-23 04:50:20 +0000682 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
683 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
684 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
685 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
686 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000687 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000688 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +0000689 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000690
691 if (!tx_ring)
692 continue;
693
694 /* process Tx ring statistics */
695 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700696 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000697 data[i] = tx_ring->stats.packets;
698 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700699 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000700 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000701
702 /* Rx ring is the 2nd half of the queue pair */
703 rx_ring = &tx_ring[1];
704 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700705 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000706 data[i] = rx_ring->stats.packets;
707 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700708 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000709 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000710 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000711 rcu_read_unlock();
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000712 if (vsi != pf->vsi[pf->lan_vsi])
713 return;
714
715 if (pf->lan_veb != I40E_NO_VEB) {
716 struct i40e_veb *veb = pf->veb[pf->lan_veb];
717 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
718 p = (char *)veb;
719 p += i40e_gstrings_veb_stats[j].stat_offset;
720 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
721 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000722 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000723 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000724 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
725 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
726 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
727 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
728 }
729 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
730 data[i++] = pf->stats.priority_xon_tx[j];
731 data[i++] = pf->stats.priority_xoff_tx[j];
732 }
733 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
734 data[i++] = pf->stats.priority_xon_rx[j];
735 data[i++] = pf->stats.priority_xoff_rx[j];
736 }
737 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
738 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000739}
740
741static void i40e_get_strings(struct net_device *netdev, u32 stringset,
742 u8 *data)
743{
744 struct i40e_netdev_priv *np = netdev_priv(netdev);
745 struct i40e_vsi *vsi = np->vsi;
746 struct i40e_pf *pf = vsi->back;
747 char *p = (char *)data;
748 int i;
749
750 switch (stringset) {
751 case ETH_SS_TEST:
752 for (i = 0; i < I40E_TEST_LEN; i++) {
753 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
754 data += ETH_GSTRING_LEN;
755 }
756 break;
757 case ETH_SS_STATS:
758 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
759 snprintf(p, ETH_GSTRING_LEN, "%s",
760 i40e_gstrings_net_stats[i].stat_string);
761 p += ETH_GSTRING_LEN;
762 }
Shannon Nelson41a9e552014-04-23 04:50:20 +0000763 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
764 snprintf(p, ETH_GSTRING_LEN, "%s",
765 i40e_gstrings_misc_stats[i].stat_string);
766 p += ETH_GSTRING_LEN;
767 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000768 for (i = 0; i < vsi->num_queue_pairs; i++) {
769 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
770 p += ETH_GSTRING_LEN;
771 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
772 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000773 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
774 p += ETH_GSTRING_LEN;
775 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
776 p += ETH_GSTRING_LEN;
777 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000778 if (vsi != pf->vsi[pf->lan_vsi])
779 return;
780
781 if (pf->lan_veb != I40E_NO_VEB) {
782 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
783 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
784 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000785 p += ETH_GSTRING_LEN;
786 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000787 }
788 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
789 snprintf(p, ETH_GSTRING_LEN, "port.%s",
790 i40e_gstrings_stats[i].stat_string);
791 p += ETH_GSTRING_LEN;
792 }
793 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
794 snprintf(p, ETH_GSTRING_LEN,
795 "port.tx_priority_%u_xon", i);
796 p += ETH_GSTRING_LEN;
797 snprintf(p, ETH_GSTRING_LEN,
798 "port.tx_priority_%u_xoff", i);
799 p += ETH_GSTRING_LEN;
800 }
801 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
802 snprintf(p, ETH_GSTRING_LEN,
803 "port.rx_priority_%u_xon", i);
804 p += ETH_GSTRING_LEN;
805 snprintf(p, ETH_GSTRING_LEN,
806 "port.rx_priority_%u_xoff", i);
807 p += ETH_GSTRING_LEN;
808 }
809 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
810 snprintf(p, ETH_GSTRING_LEN,
811 "port.rx_priority_%u_xon_2_xoff", i);
812 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000813 }
814 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
815 break;
816 }
817}
818
819static int i40e_get_ts_info(struct net_device *dev,
820 struct ethtool_ts_info *info)
821{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000822 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
823
824 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
825 SOF_TIMESTAMPING_RX_SOFTWARE |
826 SOF_TIMESTAMPING_SOFTWARE |
827 SOF_TIMESTAMPING_TX_HARDWARE |
828 SOF_TIMESTAMPING_RX_HARDWARE |
829 SOF_TIMESTAMPING_RAW_HARDWARE;
830
831 if (pf->ptp_clock)
832 info->phc_index = ptp_clock_index(pf->ptp_clock);
833 else
834 info->phc_index = -1;
835
836 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
837
838 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
839 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
840 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
841 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
842 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
843 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
844 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
845 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
846 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
847 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
848 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
849 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
850
851 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000852}
853
Shannon Nelson7b086392013-11-20 10:02:59 +0000854static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000855{
Shannon Nelson7b086392013-11-20 10:02:59 +0000856 struct i40e_netdev_priv *np = netdev_priv(netdev);
857 struct i40e_pf *pf = np->vsi->back;
858
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000859 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000860 if (i40e_get_link_status(&pf->hw))
861 *data = 0;
862 else
863 *data = 1;
864
865 return *data;
866}
867
Shannon Nelson7b086392013-11-20 10:02:59 +0000868static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000869{
Shannon Nelson7b086392013-11-20 10:02:59 +0000870 struct i40e_netdev_priv *np = netdev_priv(netdev);
871 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000872
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000873 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +0000874 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000875
Shannon Nelson7b086392013-11-20 10:02:59 +0000876 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000877}
878
Shannon Nelson7b086392013-11-20 10:02:59 +0000879static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000880{
Shannon Nelson7b086392013-11-20 10:02:59 +0000881 struct i40e_netdev_priv *np = netdev_priv(netdev);
882 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000883
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000884 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +0000885 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000886
Shannon Nelson7b086392013-11-20 10:02:59 +0000887 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000888}
889
Shannon Nelson7b086392013-11-20 10:02:59 +0000890static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000891{
Shannon Nelson7b086392013-11-20 10:02:59 +0000892 struct i40e_netdev_priv *np = netdev_priv(netdev);
893 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000894 u16 swc_old = pf->sw_int_count;
895
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000896 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000897 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
898 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
899 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
900 usleep_range(1000, 2000);
901 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000902
903 return *data;
904}
905
Shannon Nelson7b086392013-11-20 10:02:59 +0000906static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000907{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000908 struct i40e_netdev_priv *np = netdev_priv(netdev);
909 struct i40e_pf *pf = np->vsi->back;
910
911 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000912 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000913
914 return *data;
915}
916
917static void i40e_diag_test(struct net_device *netdev,
918 struct ethtool_test *eth_test, u64 *data)
919{
920 struct i40e_netdev_priv *np = netdev_priv(netdev);
921 struct i40e_pf *pf = np->vsi->back;
922
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000923 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
924 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000925 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000926
Shannon Nelsonf551b432013-11-26 10:49:12 +0000927 set_bit(__I40E_TESTING, &pf->state);
928
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000929 /* Link test performed before hardware reset
930 * so autoneg doesn't interfere with test result
931 */
Shannon Nelson7b086392013-11-20 10:02:59 +0000932 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000933 eth_test->flags |= ETH_TEST_FL_FAILED;
934
Shannon Nelson7b086392013-11-20 10:02:59 +0000935 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000936 eth_test->flags |= ETH_TEST_FL_FAILED;
937
Shannon Nelson7b086392013-11-20 10:02:59 +0000938 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000939 eth_test->flags |= ETH_TEST_FL_FAILED;
940
Shannon Nelson7b086392013-11-20 10:02:59 +0000941 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000942 eth_test->flags |= ETH_TEST_FL_FAILED;
943
Shannon Nelsonf551b432013-11-26 10:49:12 +0000944 /* run reg test last, a reset is required after it */
945 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
946 eth_test->flags |= ETH_TEST_FL_FAILED;
947
948 clear_bit(__I40E_TESTING, &pf->state);
949 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000950 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000951 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000952 netif_info(pf, drv, netdev, "online testing starting\n");
953
Shannon Nelson7b086392013-11-20 10:02:59 +0000954 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000955 eth_test->flags |= ETH_TEST_FL_FAILED;
956
957 /* Offline only tests, not run in online; pass by default */
958 data[I40E_ETH_TEST_REG] = 0;
959 data[I40E_ETH_TEST_EEPROM] = 0;
960 data[I40E_ETH_TEST_INTR] = 0;
961 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000962 }
Shannon Nelsonc140c172013-11-20 10:02:58 +0000963
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000964 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000965}
966
967static void i40e_get_wol(struct net_device *netdev,
968 struct ethtool_wolinfo *wol)
969{
Shannon Nelson8e2773a2013-11-28 06:39:22 +0000970 struct i40e_netdev_priv *np = netdev_priv(netdev);
971 struct i40e_pf *pf = np->vsi->back;
972 struct i40e_hw *hw = &pf->hw;
973 u16 wol_nvm_bits;
974
975 /* NVM bit on means WoL disabled for the port */
976 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
977 if ((1 << hw->port) & wol_nvm_bits) {
978 wol->supported = 0;
979 wol->wolopts = 0;
980 } else {
981 wol->supported = WAKE_MAGIC;
982 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
983 }
984}
985
986static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
987{
988 struct i40e_netdev_priv *np = netdev_priv(netdev);
989 struct i40e_pf *pf = np->vsi->back;
990 struct i40e_hw *hw = &pf->hw;
991 u16 wol_nvm_bits;
992
993 /* NVM bit on means WoL disabled for the port */
994 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
995 if (((1 << hw->port) & wol_nvm_bits))
996 return -EOPNOTSUPP;
997
998 /* only magic packet is supported */
999 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1000 return -EOPNOTSUPP;
1001
1002 /* is this a new value? */
1003 if (pf->wol_en != !!wol->wolopts) {
1004 pf->wol_en = !!wol->wolopts;
1005 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1006 }
1007
1008 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001009}
1010
1011static int i40e_nway_reset(struct net_device *netdev)
1012{
1013 /* restart autonegotiation */
1014 struct i40e_netdev_priv *np = netdev_priv(netdev);
1015 struct i40e_pf *pf = np->vsi->back;
1016 struct i40e_hw *hw = &pf->hw;
1017 i40e_status ret = 0;
1018
1019 ret = i40e_aq_set_link_restart_an(hw, NULL);
1020 if (ret) {
1021 netdev_info(netdev, "link restart failed, aq_err=%d\n",
1022 pf->hw.aq.asq_last_status);
1023 return -EIO;
1024 }
1025
1026 return 0;
1027}
1028
1029static int i40e_set_phys_id(struct net_device *netdev,
1030 enum ethtool_phys_id_state state)
1031{
1032 struct i40e_netdev_priv *np = netdev_priv(netdev);
1033 struct i40e_pf *pf = np->vsi->back;
1034 struct i40e_hw *hw = &pf->hw;
1035 int blink_freq = 2;
1036
1037 switch (state) {
1038 case ETHTOOL_ID_ACTIVE:
1039 pf->led_status = i40e_led_get(hw);
1040 return blink_freq;
1041 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001042 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001043 break;
1044 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001045 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001046 break;
1047 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001048 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001049 break;
1050 }
1051
1052 return 0;
1053}
1054
1055/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1056 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1057 * 125us (8000 interrupts per second) == ITR(62)
1058 */
1059
1060static int i40e_get_coalesce(struct net_device *netdev,
1061 struct ethtool_coalesce *ec)
1062{
1063 struct i40e_netdev_priv *np = netdev_priv(netdev);
1064 struct i40e_vsi *vsi = np->vsi;
1065
1066 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1067 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1068
1069 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001070 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001071
1072 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001073 ec->use_adaptive_tx_coalesce = 1;
1074
1075 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1076 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001077
1078 return 0;
1079}
1080
1081static int i40e_set_coalesce(struct net_device *netdev,
1082 struct ethtool_coalesce *ec)
1083{
1084 struct i40e_netdev_priv *np = netdev_priv(netdev);
1085 struct i40e_q_vector *q_vector;
1086 struct i40e_vsi *vsi = np->vsi;
1087 struct i40e_pf *pf = vsi->back;
1088 struct i40e_hw *hw = &pf->hw;
1089 u16 vector;
1090 int i;
1091
1092 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1093 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1094
Mitch Williams32f5f542014-04-04 04:43:10 +00001095 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1096 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001097 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Mitch Williams32f5f542014-04-04 04:43:10 +00001098 else
1099 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001100
Mitch Williams32f5f542014-04-04 04:43:10 +00001101 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1102 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001103 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Mitch Williams32f5f542014-04-04 04:43:10 +00001104 else
1105 return -EINVAL;
1106
1107 if (ec->use_adaptive_rx_coalesce)
1108 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1109 else
1110 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1111
1112 if (ec->use_adaptive_tx_coalesce)
1113 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1114 else
1115 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001116
1117 vector = vsi->base_vector;
Alexander Duyck493fb302013-09-28 07:01:44 +00001118 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1119 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001120 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1121 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1122 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1123 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1124 i40e_flush(hw);
1125 }
1126
1127 return 0;
1128}
1129
1130/**
1131 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1132 * @pf: pointer to the physical function struct
1133 * @cmd: ethtool rxnfc command
1134 *
1135 * Returns Success if the flow is supported, else Invalid Input.
1136 **/
1137static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1138{
1139 cmd->data = 0;
1140
1141 /* Report default options for RSS on i40e */
1142 switch (cmd->flow_type) {
1143 case TCP_V4_FLOW:
1144 case UDP_V4_FLOW:
1145 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1146 /* fall through to add IP fields */
1147 case SCTP_V4_FLOW:
1148 case AH_ESP_V4_FLOW:
1149 case AH_V4_FLOW:
1150 case ESP_V4_FLOW:
1151 case IPV4_FLOW:
1152 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1153 break;
1154 case TCP_V6_FLOW:
1155 case UDP_V6_FLOW:
1156 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1157 /* fall through to add IP fields */
1158 case SCTP_V6_FLOW:
1159 case AH_ESP_V6_FLOW:
1160 case AH_V6_FLOW:
1161 case ESP_V6_FLOW:
1162 case IPV6_FLOW:
1163 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1164 break;
1165 default:
1166 return -EINVAL;
1167 }
1168
1169 return 0;
1170}
1171
1172/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001173 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1174 * @pf: Pointer to the physical function struct
1175 * @cmd: The command to get or set Rx flow classification rules
1176 * @rule_locs: Array of used rule locations
1177 *
1178 * This function populates both the total and actual rule count of
1179 * the ethtool flow classification command
1180 *
1181 * Returns 0 on success or -EMSGSIZE if entry not found
1182 **/
1183static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1184 struct ethtool_rxnfc *cmd,
1185 u32 *rule_locs)
1186{
1187 struct i40e_fdir_filter *rule;
1188 struct hlist_node *node2;
1189 int cnt = 0;
1190
1191 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001192 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001193
1194 hlist_for_each_entry_safe(rule, node2,
1195 &pf->fdir_filter_list, fdir_node) {
1196 if (cnt == cmd->rule_cnt)
1197 return -EMSGSIZE;
1198
1199 rule_locs[cnt] = rule->fd_id;
1200 cnt++;
1201 }
1202
1203 cmd->rule_cnt = cnt;
1204
1205 return 0;
1206}
1207
1208/**
1209 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1210 * @pf: Pointer to the physical function struct
1211 * @cmd: The command to get or set Rx flow classification rules
1212 *
1213 * This function looks up a filter based on the Rx flow classification
1214 * command and fills the flow spec info for it if found
1215 *
1216 * Returns 0 on success or -EINVAL if filter not found
1217 **/
1218static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1219 struct ethtool_rxnfc *cmd)
1220{
1221 struct ethtool_rx_flow_spec *fsp =
1222 (struct ethtool_rx_flow_spec *)&cmd->fs;
1223 struct i40e_fdir_filter *rule = NULL;
1224 struct hlist_node *node2;
1225
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001226 hlist_for_each_entry_safe(rule, node2,
1227 &pf->fdir_filter_list, fdir_node) {
1228 if (fsp->location <= rule->fd_id)
1229 break;
1230 }
1231
1232 if (!rule || fsp->location != rule->fd_id)
1233 return -EINVAL;
1234
1235 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001236 if (fsp->flow_type == IP_USER_FLOW) {
1237 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1238 fsp->h_u.usr_ip4_spec.proto = 0;
1239 fsp->m_u.usr_ip4_spec.proto = 0;
1240 }
1241
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001242 fsp->h_u.tcp_ip4_spec.psrc = rule->src_port;
1243 fsp->h_u.tcp_ip4_spec.pdst = rule->dst_port;
1244 fsp->h_u.tcp_ip4_spec.ip4src = rule->src_ip[0];
1245 fsp->h_u.tcp_ip4_spec.ip4dst = rule->dst_ip[0];
1246 fsp->ring_cookie = rule->q_index;
1247
1248 return 0;
1249}
1250
1251/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001252 * i40e_get_rxnfc - command to get RX flow classification rules
1253 * @netdev: network interface device structure
1254 * @cmd: ethtool rxnfc command
1255 *
1256 * Returns Success if the command is supported.
1257 **/
1258static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1259 u32 *rule_locs)
1260{
1261 struct i40e_netdev_priv *np = netdev_priv(netdev);
1262 struct i40e_vsi *vsi = np->vsi;
1263 struct i40e_pf *pf = vsi->back;
1264 int ret = -EOPNOTSUPP;
1265
1266 switch (cmd->cmd) {
1267 case ETHTOOL_GRXRINGS:
1268 cmd->data = vsi->alloc_queue_pairs;
1269 ret = 0;
1270 break;
1271 case ETHTOOL_GRXFH:
1272 ret = i40e_get_rss_hash_opts(pf, cmd);
1273 break;
1274 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001275 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001276 /* report total rule count */
1277 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001278 ret = 0;
1279 break;
1280 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001281 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001282 break;
1283 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001284 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1285 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001286 default:
1287 break;
1288 }
1289
1290 return ret;
1291}
1292
1293/**
1294 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1295 * @pf: pointer to the physical function struct
1296 * @cmd: ethtool rxnfc command
1297 *
1298 * Returns Success if the flow input set is supported.
1299 **/
1300static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1301{
1302 struct i40e_hw *hw = &pf->hw;
1303 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1304 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1305
1306 /* RSS does not support anything other than hashing
1307 * to queues on src and dst IPs and ports
1308 */
1309 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1310 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1311 return -EINVAL;
1312
1313 /* We need at least the IP SRC and DEST fields for hashing */
1314 if (!(nfc->data & RXH_IP_SRC) ||
1315 !(nfc->data & RXH_IP_DST))
1316 return -EINVAL;
1317
1318 switch (nfc->flow_type) {
1319 case TCP_V4_FLOW:
1320 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1321 case 0:
1322 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1323 break;
1324 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1325 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1326 break;
1327 default:
1328 return -EINVAL;
1329 }
1330 break;
1331 case TCP_V6_FLOW:
1332 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1333 case 0:
1334 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1335 break;
1336 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1337 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1338 break;
1339 default:
1340 return -EINVAL;
1341 }
1342 break;
1343 case UDP_V4_FLOW:
1344 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1345 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001346 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1347 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001348 break;
1349 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001350 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1351 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001352 break;
1353 default:
1354 return -EINVAL;
1355 }
1356 break;
1357 case UDP_V6_FLOW:
1358 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1359 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001360 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1361 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001362 break;
1363 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001364 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1365 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001366 break;
1367 default:
1368 return -EINVAL;
1369 }
1370 break;
1371 case AH_ESP_V4_FLOW:
1372 case AH_V4_FLOW:
1373 case ESP_V4_FLOW:
1374 case SCTP_V4_FLOW:
1375 if ((nfc->data & RXH_L4_B_0_1) ||
1376 (nfc->data & RXH_L4_B_2_3))
1377 return -EINVAL;
1378 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1379 break;
1380 case AH_ESP_V6_FLOW:
1381 case AH_V6_FLOW:
1382 case ESP_V6_FLOW:
1383 case SCTP_V6_FLOW:
1384 if ((nfc->data & RXH_L4_B_0_1) ||
1385 (nfc->data & RXH_L4_B_2_3))
1386 return -EINVAL;
1387 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1388 break;
1389 case IPV4_FLOW:
1390 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1391 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1392 break;
1393 case IPV6_FLOW:
1394 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1395 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1396 break;
1397 default:
1398 return -EINVAL;
1399 }
1400
1401 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1402 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1403 i40e_flush(hw);
1404
1405 return 0;
1406}
1407
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001408/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001409 * i40e_match_fdir_input_set - Match a new filter against an existing one
1410 * @rule: The filter already added
1411 * @input: The new filter to comapre against
1412 *
1413 * Returns true if the two input set match
1414 **/
1415static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1416 struct i40e_fdir_filter *input)
1417{
1418 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1419 (rule->src_ip[0] != input->src_ip[0]) ||
1420 (rule->dst_port != input->dst_port) ||
1421 (rule->src_port != input->src_port))
1422 return false;
1423 return true;
1424}
1425
1426/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001427 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1428 * @vsi: Pointer to the targeted VSI
1429 * @input: The filter to update or NULL to indicate deletion
1430 * @sw_idx: Software index to the filter
1431 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001432 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001433 * This function updates (or deletes) a Flow Director entry from
1434 * the hlist of the corresponding PF
1435 *
1436 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001437 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001438static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1439 struct i40e_fdir_filter *input,
1440 u16 sw_idx,
1441 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001442{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001443 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001444 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001445 struct hlist_node *node2;
1446 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001447
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001448 parent = NULL;
1449 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001450
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001451 hlist_for_each_entry_safe(rule, node2,
1452 &pf->fdir_filter_list, fdir_node) {
1453 /* hash found, or no matching entry */
1454 if (rule->fd_id >= sw_idx)
1455 break;
1456 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001457 }
1458
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001459 /* if there is an old rule occupying our place remove it */
1460 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001461 if (input && !i40e_match_fdir_input_set(rule, input))
1462 err = i40e_add_del_fdir(vsi, rule, false);
1463 else if (!input)
1464 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001465 hlist_del(&rule->fdir_node);
1466 kfree(rule);
1467 pf->fdir_pf_active_filters--;
1468 }
1469
1470 /* If no input this was a delete, err should be 0 if a rule was
1471 * successfully found and removed from the list else -EINVAL
1472 */
1473 if (!input)
1474 return err;
1475
1476 /* initialize node and set software index */
1477 INIT_HLIST_NODE(&input->fdir_node);
1478
1479 /* add filter to the list */
1480 if (parent)
1481 hlist_add_after(&parent->fdir_node, &input->fdir_node);
1482 else
1483 hlist_add_head(&input->fdir_node,
1484 &pf->fdir_filter_list);
1485
1486 /* update counts */
1487 pf->fdir_pf_active_filters++;
1488
1489 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001490}
1491
1492/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001493 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
1494 * @vsi: Pointer to the targeted VSI
1495 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001496 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001497 * The function removes a Flow Director filter entry from the
1498 * hlist of the corresponding PF
1499 *
1500 * Returns 0 on success
1501 */
1502static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
1503 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001504{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001505 struct ethtool_rx_flow_spec *fsp =
1506 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001507 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001508 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001509
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001510 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001511
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001512 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001513 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001514}
1515
1516/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001517 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001518 * @vsi: pointer to the targeted VSI
1519 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001520 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001521 * Add Flow Director filters for a specific flow spec based on their
1522 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001523 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001524static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
1525 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001526{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001527 struct ethtool_rx_flow_spec *fsp;
1528 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001529 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001530 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001531
1532 if (!vsi)
1533 return -EINVAL;
1534
1535 pf = vsi->back;
1536
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001537 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
1538 return -EOPNOTSUPP;
1539
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001540 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001541 return -ENOSPC;
1542
1543 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
1544
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001545 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
1546 pf->hw.func_caps.fd_filters_guaranteed)) {
1547 return -EINVAL;
1548 }
1549
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001550 if (fsp->ring_cookie >= vsi->num_queue_pairs)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001551 return -EINVAL;
1552
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001553 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001554
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001555 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001556 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001557
1558 input->fd_id = fsp->location;
1559
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00001560 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
1561 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
1562 else
1563 input->dest_ctl =
1564 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
1565
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001566 input->q_index = fsp->ring_cookie;
1567 input->flex_off = 0;
1568 input->pctype = 0;
1569 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001570 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
1571 input->cnt_index = 0;
1572 input->flow_type = fsp->flow_type;
1573 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
1574 input->src_port = fsp->h_u.tcp_ip4_spec.psrc;
1575 input->dst_port = fsp->h_u.tcp_ip4_spec.pdst;
1576 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
1577 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
1578
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001579 ret = i40e_add_del_fdir(vsi, input, true);
1580 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001581 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001582 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001583 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001584
1585 return ret;
1586}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08001587
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001588/**
1589 * i40e_set_rxnfc - command to set RX flow classification rules
1590 * @netdev: network interface device structure
1591 * @cmd: ethtool rxnfc command
1592 *
1593 * Returns Success if the command is supported.
1594 **/
1595static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1596{
1597 struct i40e_netdev_priv *np = netdev_priv(netdev);
1598 struct i40e_vsi *vsi = np->vsi;
1599 struct i40e_pf *pf = vsi->back;
1600 int ret = -EOPNOTSUPP;
1601
1602 switch (cmd->cmd) {
1603 case ETHTOOL_SRXFH:
1604 ret = i40e_set_rss_hash_opt(pf, cmd);
1605 break;
1606 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001607 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001608 break;
1609 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001610 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001611 break;
1612 default:
1613 break;
1614 }
1615
1616 return ret;
1617}
1618
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001619/**
1620 * i40e_max_channels - get Max number of combined channels supported
1621 * @vsi: vsi pointer
1622 **/
1623static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
1624{
1625 /* TODO: This code assumes DCB and FD is disabled for now. */
1626 return vsi->alloc_queue_pairs;
1627}
1628
1629/**
1630 * i40e_get_channels - Get the current channels enabled and max supported etc.
1631 * @netdev: network interface device structure
1632 * @ch: ethtool channels structure
1633 *
1634 * We don't support separate tx and rx queues as channels. The other count
1635 * represents how many queues are being used for control. max_combined counts
1636 * how many queue pairs we can support. They may not be mapped 1 to 1 with
1637 * q_vectors since we support a lot more queue pairs than q_vectors.
1638 **/
1639static void i40e_get_channels(struct net_device *dev,
1640 struct ethtool_channels *ch)
1641{
1642 struct i40e_netdev_priv *np = netdev_priv(dev);
1643 struct i40e_vsi *vsi = np->vsi;
1644 struct i40e_pf *pf = vsi->back;
1645
1646 /* report maximum channels */
1647 ch->max_combined = i40e_max_channels(vsi);
1648
1649 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08001650 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001651 ch->max_other = ch->other_count;
1652
1653 /* Note: This code assumes DCB is disabled for now. */
1654 ch->combined_count = vsi->num_queue_pairs;
1655}
1656
1657/**
1658 * i40e_set_channels - Set the new channels count.
1659 * @netdev: network interface device structure
1660 * @ch: ethtool channels structure
1661 *
1662 * The new channels count may not be the same as requested by the user
1663 * since it gets rounded down to a power of 2 value.
1664 **/
1665static int i40e_set_channels(struct net_device *dev,
1666 struct ethtool_channels *ch)
1667{
1668 struct i40e_netdev_priv *np = netdev_priv(dev);
1669 unsigned int count = ch->combined_count;
1670 struct i40e_vsi *vsi = np->vsi;
1671 struct i40e_pf *pf = vsi->back;
1672 int new_count;
1673
1674 /* We do not support setting channels for any other VSI at present */
1675 if (vsi->type != I40E_VSI_MAIN)
1676 return -EINVAL;
1677
1678 /* verify they are not requesting separate vectors */
1679 if (!count || ch->rx_count || ch->tx_count)
1680 return -EINVAL;
1681
1682 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08001683 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001684 return -EINVAL;
1685
1686 /* verify the number of channels does not exceed hardware limits */
1687 if (count > i40e_max_channels(vsi))
1688 return -EINVAL;
1689
1690 /* update feature limits from largest to smallest supported values */
1691 /* TODO: Flow director limit, DCB etc */
1692
1693 /* cap RSS limit */
1694 if (count > pf->rss_size_max)
1695 count = pf->rss_size_max;
1696
1697 /* use rss_reconfig to rebuild with new queue count and update traffic
1698 * class queue mapping
1699 */
1700 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00001701 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001702 return 0;
1703 else
1704 return -EINVAL;
1705}
1706
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001707static const struct ethtool_ops i40e_ethtool_ops = {
1708 .get_settings = i40e_get_settings,
1709 .get_drvinfo = i40e_get_drvinfo,
1710 .get_regs_len = i40e_get_regs_len,
1711 .get_regs = i40e_get_regs,
1712 .nway_reset = i40e_nway_reset,
1713 .get_link = ethtool_op_get_link,
1714 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001715 .set_wol = i40e_set_wol,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001716 .get_eeprom_len = i40e_get_eeprom_len,
1717 .get_eeprom = i40e_get_eeprom,
1718 .get_ringparam = i40e_get_ringparam,
1719 .set_ringparam = i40e_set_ringparam,
1720 .get_pauseparam = i40e_get_pauseparam,
1721 .get_msglevel = i40e_get_msglevel,
1722 .set_msglevel = i40e_set_msglevel,
1723 .get_rxnfc = i40e_get_rxnfc,
1724 .set_rxnfc = i40e_set_rxnfc,
1725 .self_test = i40e_diag_test,
1726 .get_strings = i40e_get_strings,
1727 .set_phys_id = i40e_set_phys_id,
1728 .get_sset_count = i40e_get_sset_count,
1729 .get_ethtool_stats = i40e_get_ethtool_stats,
1730 .get_coalesce = i40e_get_coalesce,
1731 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001732 .get_channels = i40e_get_channels,
1733 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001734 .get_ts_info = i40e_get_ts_info,
1735};
1736
1737void i40e_set_ethtool_ops(struct net_device *netdev)
1738{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00001739 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001740}