blob: 354181d1761226136b15f4a41080127c4b8f4494 [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)
49
50static const struct i40e_stats i40e_gstrings_net_stats[] = {
51 I40E_NETDEV_STAT(rx_packets),
52 I40E_NETDEV_STAT(tx_packets),
53 I40E_NETDEV_STAT(rx_bytes),
54 I40E_NETDEV_STAT(tx_bytes),
55 I40E_NETDEV_STAT(rx_errors),
56 I40E_NETDEV_STAT(tx_errors),
57 I40E_NETDEV_STAT(rx_dropped),
58 I40E_NETDEV_STAT(tx_dropped),
59 I40E_NETDEV_STAT(multicast),
60 I40E_NETDEV_STAT(collisions),
61 I40E_NETDEV_STAT(rx_length_errors),
62 I40E_NETDEV_STAT(rx_crc_errors),
63};
64
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +000065static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
66 struct ethtool_rxnfc *cmd);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +000067
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000068/* These PF_STATs might look like duplicates of some NETDEV_STATs,
69 * but they are separate. This device supports Virtualization, and
70 * as such might have several netdevs supporting VMDq and FCoE going
71 * through a single port. The NETDEV_STATs are for individual netdevs
72 * seen at the top of the stack, and the PF_STATs are for the physical
73 * function at the bottom of the stack hosting those netdevs.
74 *
75 * The PF_STATs are appended to the netdev stats only when ethtool -S
76 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
77 */
78static struct i40e_stats i40e_gstrings_stats[] = {
79 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
80 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
81 I40E_PF_STAT("rx_errors", stats.eth.rx_errors),
82 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
83 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
84 I40E_PF_STAT("tx_dropped", stats.eth.tx_discards),
85 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
86 I40E_PF_STAT("crc_errors", stats.crc_errors),
87 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
88 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
89 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +000090 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000091 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
92 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
93 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
94 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
95 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
96 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
97 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
98 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
99 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
100 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
101 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
102 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
103 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
104 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
105 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
106 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
107 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
108 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
109 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
110 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
111 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
112 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
113 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
114 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000115 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000116 /* LPI stats */
117 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
118 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
119 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
120 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000121};
122
123#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000124 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
125 * 2 /* Tx and Rx together */ \
126 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000127#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
128#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
129#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
130 I40E_QUEUE_STATS_LEN((n)))
131#define I40E_PFC_STATS_LEN ( \
132 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
133 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
134 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
135 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
136 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
137 / sizeof(u64))
138#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
139 I40E_PFC_STATS_LEN + \
140 I40E_VSI_STATS_LEN((n)))
141
142enum i40e_ethtool_test_id {
143 I40E_ETH_TEST_REG = 0,
144 I40E_ETH_TEST_EEPROM,
145 I40E_ETH_TEST_INTR,
146 I40E_ETH_TEST_LOOPBACK,
147 I40E_ETH_TEST_LINK,
148};
149
150static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
151 "Register test (offline)",
152 "Eeprom test (offline)",
153 "Interrupt test (offline)",
154 "Loopback test (offline)",
155 "Link test (on/offline)"
156};
157
158#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
159
160/**
161 * i40e_get_settings - Get Link Speed and Duplex settings
162 * @netdev: network interface device structure
163 * @ecmd: ethtool command
164 *
165 * Reports speed/duplex settings based on media_type
166 **/
167static int i40e_get_settings(struct net_device *netdev,
168 struct ethtool_cmd *ecmd)
169{
170 struct i40e_netdev_priv *np = netdev_priv(netdev);
171 struct i40e_pf *pf = np->vsi->back;
172 struct i40e_hw *hw = &pf->hw;
173 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
174 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
175 u32 link_speed = hw_link_info->link_speed;
176
177 /* hardware is either in 40G mode or 10G mode
178 * NOTE: this section initializes supported and advertising
179 */
180 switch (hw_link_info->phy_type) {
181 case I40E_PHY_TYPE_40GBASE_CR4:
182 case I40E_PHY_TYPE_40GBASE_CR4_CU:
183 ecmd->supported = SUPPORTED_40000baseCR4_Full;
184 ecmd->advertising = ADVERTISED_40000baseCR4_Full;
185 break;
186 case I40E_PHY_TYPE_40GBASE_KR4:
187 ecmd->supported = SUPPORTED_40000baseKR4_Full;
188 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
189 break;
190 case I40E_PHY_TYPE_40GBASE_SR4:
191 ecmd->supported = SUPPORTED_40000baseSR4_Full;
192 ecmd->advertising = ADVERTISED_40000baseSR4_Full;
193 break;
194 case I40E_PHY_TYPE_40GBASE_LR4:
195 ecmd->supported = SUPPORTED_40000baseLR4_Full;
196 ecmd->advertising = ADVERTISED_40000baseLR4_Full;
197 break;
198 case I40E_PHY_TYPE_10GBASE_KX4:
199 ecmd->supported = SUPPORTED_10000baseKX4_Full;
200 ecmd->advertising = ADVERTISED_10000baseKX4_Full;
201 break;
202 case I40E_PHY_TYPE_10GBASE_KR:
203 ecmd->supported = SUPPORTED_10000baseKR_Full;
204 ecmd->advertising = ADVERTISED_10000baseKR_Full;
205 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000206 default:
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000207 if (i40e_is_40G_device(hw->device_id)) {
208 ecmd->supported = SUPPORTED_40000baseSR4_Full;
209 ecmd->advertising = ADVERTISED_40000baseSR4_Full;
210 } else {
211 ecmd->supported = SUPPORTED_10000baseT_Full;
212 ecmd->advertising = ADVERTISED_10000baseT_Full;
213 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000214 break;
215 }
216
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000217 ecmd->supported |= SUPPORTED_Autoneg;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000218 ecmd->advertising |= ADVERTISED_Autoneg;
219 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
220 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000221
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000222 switch (hw->phy.media_type) {
223 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000224 ecmd->supported |= SUPPORTED_Backplane;
225 ecmd->advertising |= ADVERTISED_Backplane;
226 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000227 break;
228 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000229 ecmd->supported |= SUPPORTED_TP;
230 ecmd->advertising |= ADVERTISED_TP;
231 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000232 break;
233 case I40E_MEDIA_TYPE_DA:
234 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000235 ecmd->supported |= SUPPORTED_FIBRE;
236 ecmd->advertising |= ADVERTISED_FIBRE;
237 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000238 break;
239 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000240 ecmd->supported |= SUPPORTED_FIBRE;
241 ecmd->advertising |= ADVERTISED_FIBRE;
242 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000243 break;
244 case I40E_MEDIA_TYPE_UNKNOWN:
245 default:
246 ecmd->port = PORT_OTHER;
247 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000248 }
249
250 ecmd->transceiver = XCVR_EXTERNAL;
251
252 if (link_up) {
253 switch (link_speed) {
254 case I40E_LINK_SPEED_40GB:
255 /* need a SPEED_40000 in ethtool.h */
256 ethtool_cmd_speed_set(ecmd, 40000);
257 break;
258 case I40E_LINK_SPEED_10GB:
259 ethtool_cmd_speed_set(ecmd, SPEED_10000);
260 break;
261 default:
262 break;
263 }
264 ecmd->duplex = DUPLEX_FULL;
265 } else {
266 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
267 ecmd->duplex = DUPLEX_UNKNOWN;
268 }
269
270 return 0;
271}
272
273/**
274 * i40e_get_pauseparam - Get Flow Control status
275 * Return tx/rx-pause status
276 **/
277static void i40e_get_pauseparam(struct net_device *netdev,
278 struct ethtool_pauseparam *pause)
279{
280 struct i40e_netdev_priv *np = netdev_priv(netdev);
281 struct i40e_pf *pf = np->vsi->back;
282 struct i40e_hw *hw = &pf->hw;
283 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
284
285 pause->autoneg =
286 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
287 AUTONEG_ENABLE : AUTONEG_DISABLE);
288
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000289 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000290 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000291 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000292 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000293 } else if (hw->fc.current_mode == I40E_FC_FULL) {
294 pause->rx_pause = 1;
295 pause->tx_pause = 1;
296 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000297}
298
299static u32 i40e_get_msglevel(struct net_device *netdev)
300{
301 struct i40e_netdev_priv *np = netdev_priv(netdev);
302 struct i40e_pf *pf = np->vsi->back;
303
304 return pf->msg_enable;
305}
306
307static void i40e_set_msglevel(struct net_device *netdev, u32 data)
308{
309 struct i40e_netdev_priv *np = netdev_priv(netdev);
310 struct i40e_pf *pf = np->vsi->back;
311
312 if (I40E_DEBUG_USER & data)
313 pf->hw.debug_mask = data;
314 pf->msg_enable = data;
315}
316
317static int i40e_get_regs_len(struct net_device *netdev)
318{
319 int reg_count = 0;
320 int i;
321
322 for (i = 0; i40e_reg_list[i].offset != 0; i++)
323 reg_count += i40e_reg_list[i].elements;
324
325 return reg_count * sizeof(u32);
326}
327
328static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
329 void *p)
330{
331 struct i40e_netdev_priv *np = netdev_priv(netdev);
332 struct i40e_pf *pf = np->vsi->back;
333 struct i40e_hw *hw = &pf->hw;
334 u32 *reg_buf = p;
335 int i, j, ri;
336 u32 reg;
337
338 /* Tell ethtool which driver-version-specific regs output we have.
339 *
340 * At some point, if we have ethtool doing special formatting of
341 * this data, it will rely on this version number to know how to
342 * interpret things. Hence, this needs to be updated if/when the
343 * diags register table is changed.
344 */
345 regs->version = 1;
346
347 /* loop through the diags reg table for what to print */
348 ri = 0;
349 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
350 for (j = 0; j < i40e_reg_list[i].elements; j++) {
351 reg = i40e_reg_list[i].offset
352 + (j * i40e_reg_list[i].stride);
353 reg_buf[ri++] = rd32(hw, reg);
354 }
355 }
356
357}
358
359static int i40e_get_eeprom(struct net_device *netdev,
360 struct ethtool_eeprom *eeprom, u8 *bytes)
361{
362 struct i40e_netdev_priv *np = netdev_priv(netdev);
363 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000364 struct i40e_pf *pf = np->vsi->back;
365 int ret_val = 0, len;
366 u8 *eeprom_buff;
367 u16 i, sectors;
368 bool last;
369#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000370 if (eeprom->len == 0)
371 return -EINVAL;
372
373 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
374
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000375 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000376 if (!eeprom_buff)
377 return -ENOMEM;
378
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000379 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
380 if (ret_val) {
381 dev_info(&pf->pdev->dev,
382 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
383 ret_val, hw->aq.asq_last_status);
384 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000385 }
386
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000387 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
388 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
389 len = I40E_NVM_SECTOR_SIZE;
390 last = false;
391 for (i = 0; i < sectors; i++) {
392 if (i == (sectors - 1)) {
393 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
394 last = true;
395 }
396 ret_val = i40e_aq_read_nvm(hw, 0x0,
397 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
398 len,
Joe Perches3dbb7fd2014-03-25 04:30:38 +0000399 eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000400 last, NULL);
401 if (ret_val) {
402 dev_info(&pf->pdev->dev,
403 "read NVM failed err=%d status=0x%x\n",
404 ret_val, hw->aq.asq_last_status);
405 goto release_nvm;
406 }
407 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000408
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000409release_nvm:
410 i40e_release_nvm(hw);
Joe Perches3dbb7fd2014-03-25 04:30:38 +0000411 memcpy(bytes, eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000412free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000413 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000414 return ret_val;
415}
416
417static int i40e_get_eeprom_len(struct net_device *netdev)
418{
419 struct i40e_netdev_priv *np = netdev_priv(netdev);
420 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000421 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000422
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000423 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
424 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
425 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
426 /* register returns value in power of 2, 64Kbyte chunks. */
427 val = (64 * 1024) * (1 << val);
428 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000429}
430
431static void i40e_get_drvinfo(struct net_device *netdev,
432 struct ethtool_drvinfo *drvinfo)
433{
434 struct i40e_netdev_priv *np = netdev_priv(netdev);
435 struct i40e_vsi *vsi = np->vsi;
436 struct i40e_pf *pf = vsi->back;
437
438 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
439 strlcpy(drvinfo->version, i40e_driver_version_str,
440 sizeof(drvinfo->version));
441 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
442 sizeof(drvinfo->fw_version));
443 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
444 sizeof(drvinfo->bus_info));
445}
446
447static void i40e_get_ringparam(struct net_device *netdev,
448 struct ethtool_ringparam *ring)
449{
450 struct i40e_netdev_priv *np = netdev_priv(netdev);
451 struct i40e_pf *pf = np->vsi->back;
452 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
453
454 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
455 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
456 ring->rx_mini_max_pending = 0;
457 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +0000458 ring->rx_pending = vsi->rx_rings[0]->count;
459 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000460 ring->rx_mini_pending = 0;
461 ring->rx_jumbo_pending = 0;
462}
463
464static int i40e_set_ringparam(struct net_device *netdev,
465 struct ethtool_ringparam *ring)
466{
467 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
468 struct i40e_netdev_priv *np = netdev_priv(netdev);
469 struct i40e_vsi *vsi = np->vsi;
470 struct i40e_pf *pf = vsi->back;
471 u32 new_rx_count, new_tx_count;
472 int i, err = 0;
473
474 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
475 return -EINVAL;
476
Shannon Nelson1fa18372013-11-20 10:03:08 +0000477 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
478 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
479 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
480 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
481 netdev_info(netdev,
482 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
483 ring->tx_pending, ring->rx_pending,
484 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
485 return -EINVAL;
486 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000487
Shannon Nelson1fa18372013-11-20 10:03:08 +0000488 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
489 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000490
491 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000492 if ((new_tx_count == vsi->tx_rings[0]->count) &&
493 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000494 return 0;
495
496 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
497 usleep_range(1000, 2000);
498
499 if (!netif_running(vsi->netdev)) {
500 /* simple case - set for the next time the netdev is started */
501 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000502 vsi->tx_rings[i]->count = new_tx_count;
503 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000504 }
505 goto done;
506 }
507
508 /* We can't just free everything and then setup again,
509 * because the ISRs in MSI-X mode get passed pointers
510 * to the Tx and Rx ring structs.
511 */
512
513 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000514 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000515 netdev_info(netdev,
516 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000517 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000518 tx_rings = kcalloc(vsi->alloc_queue_pairs,
519 sizeof(struct i40e_ring), GFP_KERNEL);
520 if (!tx_rings) {
521 err = -ENOMEM;
522 goto done;
523 }
524
525 for (i = 0; i < vsi->num_queue_pairs; i++) {
526 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000527 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000528 tx_rings[i].count = new_tx_count;
529 err = i40e_setup_tx_descriptors(&tx_rings[i]);
530 if (err) {
531 while (i) {
532 i--;
533 i40e_free_tx_resources(&tx_rings[i]);
534 }
535 kfree(tx_rings);
536 tx_rings = NULL;
537
538 goto done;
539 }
540 }
541 }
542
543 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000544 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000545 netdev_info(netdev,
546 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000547 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000548 rx_rings = kcalloc(vsi->alloc_queue_pairs,
549 sizeof(struct i40e_ring), GFP_KERNEL);
550 if (!rx_rings) {
551 err = -ENOMEM;
552 goto free_tx;
553 }
554
555 for (i = 0; i < vsi->num_queue_pairs; i++) {
556 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000557 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000558 rx_rings[i].count = new_rx_count;
559 err = i40e_setup_rx_descriptors(&rx_rings[i]);
560 if (err) {
561 while (i) {
562 i--;
563 i40e_free_rx_resources(&rx_rings[i]);
564 }
565 kfree(rx_rings);
566 rx_rings = NULL;
567
568 goto free_tx;
569 }
570 }
571 }
572
573 /* Bring interface down, copy in the new ring info,
574 * then restore the interface
575 */
576 i40e_down(vsi);
577
578 if (tx_rings) {
579 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000580 i40e_free_tx_resources(vsi->tx_rings[i]);
581 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000582 }
583 kfree(tx_rings);
584 tx_rings = NULL;
585 }
586
587 if (rx_rings) {
588 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000589 i40e_free_rx_resources(vsi->rx_rings[i]);
590 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000591 }
592 kfree(rx_rings);
593 rx_rings = NULL;
594 }
595
596 i40e_up(vsi);
597
598free_tx:
599 /* error cleanup if the Rx allocations failed after getting Tx */
600 if (tx_rings) {
601 for (i = 0; i < vsi->num_queue_pairs; i++)
602 i40e_free_tx_resources(&tx_rings[i]);
603 kfree(tx_rings);
604 tx_rings = NULL;
605 }
606
607done:
608 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
609
610 return err;
611}
612
613static int i40e_get_sset_count(struct net_device *netdev, int sset)
614{
615 struct i40e_netdev_priv *np = netdev_priv(netdev);
616 struct i40e_vsi *vsi = np->vsi;
617 struct i40e_pf *pf = vsi->back;
618
619 switch (sset) {
620 case ETH_SS_TEST:
621 return I40E_TEST_LEN;
622 case ETH_SS_STATS:
623 if (vsi == pf->vsi[pf->lan_vsi])
624 return I40E_PF_STATS_LEN(netdev);
625 else
626 return I40E_VSI_STATS_LEN(netdev);
627 default:
628 return -EOPNOTSUPP;
629 }
630}
631
632static void i40e_get_ethtool_stats(struct net_device *netdev,
633 struct ethtool_stats *stats, u64 *data)
634{
635 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +0000636 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000637 struct i40e_vsi *vsi = np->vsi;
638 struct i40e_pf *pf = vsi->back;
639 int i = 0;
640 char *p;
641 int j;
642 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000643 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000644
645 i40e_update_stats(vsi);
646
647 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
648 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
649 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
650 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
651 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000652 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000653 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +0000654 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000655
656 if (!tx_ring)
657 continue;
658
659 /* process Tx ring statistics */
660 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700661 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000662 data[i] = tx_ring->stats.packets;
663 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700664 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000665 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +0000666
667 /* Rx ring is the 2nd half of the queue pair */
668 rx_ring = &tx_ring[1];
669 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700670 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000671 data[i] = rx_ring->stats.packets;
672 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700673 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +0000674 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000675 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000676 rcu_read_unlock();
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000677 if (vsi == pf->vsi[pf->lan_vsi]) {
678 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
679 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
680 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
681 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
682 }
683 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
684 data[i++] = pf->stats.priority_xon_tx[j];
685 data[i++] = pf->stats.priority_xoff_tx[j];
686 }
687 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
688 data[i++] = pf->stats.priority_xon_rx[j];
689 data[i++] = pf->stats.priority_xoff_rx[j];
690 }
691 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
692 data[i++] = pf->stats.priority_xon_2_xoff[j];
693 }
694}
695
696static void i40e_get_strings(struct net_device *netdev, u32 stringset,
697 u8 *data)
698{
699 struct i40e_netdev_priv *np = netdev_priv(netdev);
700 struct i40e_vsi *vsi = np->vsi;
701 struct i40e_pf *pf = vsi->back;
702 char *p = (char *)data;
703 int i;
704
705 switch (stringset) {
706 case ETH_SS_TEST:
707 for (i = 0; i < I40E_TEST_LEN; i++) {
708 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
709 data += ETH_GSTRING_LEN;
710 }
711 break;
712 case ETH_SS_STATS:
713 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
714 snprintf(p, ETH_GSTRING_LEN, "%s",
715 i40e_gstrings_net_stats[i].stat_string);
716 p += ETH_GSTRING_LEN;
717 }
718 for (i = 0; i < vsi->num_queue_pairs; i++) {
719 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
720 p += ETH_GSTRING_LEN;
721 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
722 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000723 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
724 p += ETH_GSTRING_LEN;
725 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
726 p += ETH_GSTRING_LEN;
727 }
728 if (vsi == pf->vsi[pf->lan_vsi]) {
729 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
730 snprintf(p, ETH_GSTRING_LEN, "port.%s",
731 i40e_gstrings_stats[i].stat_string);
732 p += ETH_GSTRING_LEN;
733 }
734 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
735 snprintf(p, ETH_GSTRING_LEN,
736 "port.tx_priority_%u_xon", i);
737 p += ETH_GSTRING_LEN;
738 snprintf(p, ETH_GSTRING_LEN,
739 "port.tx_priority_%u_xoff", i);
740 p += ETH_GSTRING_LEN;
741 }
742 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
743 snprintf(p, ETH_GSTRING_LEN,
744 "port.rx_priority_%u_xon", i);
745 p += ETH_GSTRING_LEN;
746 snprintf(p, ETH_GSTRING_LEN,
747 "port.rx_priority_%u_xoff", i);
748 p += ETH_GSTRING_LEN;
749 }
750 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
751 snprintf(p, ETH_GSTRING_LEN,
752 "port.rx_priority_%u_xon_2_xoff", i);
753 p += ETH_GSTRING_LEN;
754 }
755 }
756 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
757 break;
758 }
759}
760
761static int i40e_get_ts_info(struct net_device *dev,
762 struct ethtool_ts_info *info)
763{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000764 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
765
766 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
767 SOF_TIMESTAMPING_RX_SOFTWARE |
768 SOF_TIMESTAMPING_SOFTWARE |
769 SOF_TIMESTAMPING_TX_HARDWARE |
770 SOF_TIMESTAMPING_RX_HARDWARE |
771 SOF_TIMESTAMPING_RAW_HARDWARE;
772
773 if (pf->ptp_clock)
774 info->phc_index = ptp_clock_index(pf->ptp_clock);
775 else
776 info->phc_index = -1;
777
778 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
779
780 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
781 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
782 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
783 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
784 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
785 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
786 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
787 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
788 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
789 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
790 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
791 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
792
793 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000794}
795
Shannon Nelson7b086392013-11-20 10:02:59 +0000796static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000797{
Shannon Nelson7b086392013-11-20 10:02:59 +0000798 struct i40e_netdev_priv *np = netdev_priv(netdev);
799 struct i40e_pf *pf = np->vsi->back;
800
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000801 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000802 if (i40e_get_link_status(&pf->hw))
803 *data = 0;
804 else
805 *data = 1;
806
807 return *data;
808}
809
Shannon Nelson7b086392013-11-20 10:02:59 +0000810static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000811{
Shannon Nelson7b086392013-11-20 10:02:59 +0000812 struct i40e_netdev_priv *np = netdev_priv(netdev);
813 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000814
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000815 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +0000816 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000817
Shannon Nelson7b086392013-11-20 10:02:59 +0000818 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000819}
820
Shannon Nelson7b086392013-11-20 10:02:59 +0000821static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000822{
Shannon Nelson7b086392013-11-20 10:02:59 +0000823 struct i40e_netdev_priv *np = netdev_priv(netdev);
824 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000825
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000826 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +0000827 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000828
Shannon Nelson7b086392013-11-20 10:02:59 +0000829 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000830}
831
Shannon Nelson7b086392013-11-20 10:02:59 +0000832static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000833{
Shannon Nelson7b086392013-11-20 10:02:59 +0000834 struct i40e_netdev_priv *np = netdev_priv(netdev);
835 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000836 u16 swc_old = pf->sw_int_count;
837
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000838 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000839 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
840 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
841 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
842 usleep_range(1000, 2000);
843 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000844
845 return *data;
846}
847
Shannon Nelson7b086392013-11-20 10:02:59 +0000848static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000849{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000850 struct i40e_netdev_priv *np = netdev_priv(netdev);
851 struct i40e_pf *pf = np->vsi->back;
852
853 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000854 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000855
856 return *data;
857}
858
859static void i40e_diag_test(struct net_device *netdev,
860 struct ethtool_test *eth_test, u64 *data)
861{
862 struct i40e_netdev_priv *np = netdev_priv(netdev);
863 struct i40e_pf *pf = np->vsi->back;
864
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000865 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
866 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000867 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000868
Shannon Nelsonf551b432013-11-26 10:49:12 +0000869 set_bit(__I40E_TESTING, &pf->state);
870
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000871 /* Link test performed before hardware reset
872 * so autoneg doesn't interfere with test result
873 */
Shannon Nelson7b086392013-11-20 10:02:59 +0000874 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000875 eth_test->flags |= ETH_TEST_FL_FAILED;
876
Shannon Nelson7b086392013-11-20 10:02:59 +0000877 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000878 eth_test->flags |= ETH_TEST_FL_FAILED;
879
Shannon Nelson7b086392013-11-20 10:02:59 +0000880 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000881 eth_test->flags |= ETH_TEST_FL_FAILED;
882
Shannon Nelson7b086392013-11-20 10:02:59 +0000883 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000884 eth_test->flags |= ETH_TEST_FL_FAILED;
885
Shannon Nelsonf551b432013-11-26 10:49:12 +0000886 /* run reg test last, a reset is required after it */
887 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
888 eth_test->flags |= ETH_TEST_FL_FAILED;
889
890 clear_bit(__I40E_TESTING, &pf->state);
891 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000892 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000893 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000894 netif_info(pf, drv, netdev, "online testing starting\n");
895
Shannon Nelson7b086392013-11-20 10:02:59 +0000896 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000897 eth_test->flags |= ETH_TEST_FL_FAILED;
898
899 /* Offline only tests, not run in online; pass by default */
900 data[I40E_ETH_TEST_REG] = 0;
901 data[I40E_ETH_TEST_EEPROM] = 0;
902 data[I40E_ETH_TEST_INTR] = 0;
903 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000904 }
Shannon Nelsonc140c172013-11-20 10:02:58 +0000905
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000906 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000907}
908
909static void i40e_get_wol(struct net_device *netdev,
910 struct ethtool_wolinfo *wol)
911{
Shannon Nelson8e2773a2013-11-28 06:39:22 +0000912 struct i40e_netdev_priv *np = netdev_priv(netdev);
913 struct i40e_pf *pf = np->vsi->back;
914 struct i40e_hw *hw = &pf->hw;
915 u16 wol_nvm_bits;
916
917 /* NVM bit on means WoL disabled for the port */
918 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
919 if ((1 << hw->port) & wol_nvm_bits) {
920 wol->supported = 0;
921 wol->wolopts = 0;
922 } else {
923 wol->supported = WAKE_MAGIC;
924 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
925 }
926}
927
928static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
929{
930 struct i40e_netdev_priv *np = netdev_priv(netdev);
931 struct i40e_pf *pf = np->vsi->back;
932 struct i40e_hw *hw = &pf->hw;
933 u16 wol_nvm_bits;
934
935 /* NVM bit on means WoL disabled for the port */
936 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
937 if (((1 << hw->port) & wol_nvm_bits))
938 return -EOPNOTSUPP;
939
940 /* only magic packet is supported */
941 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
942 return -EOPNOTSUPP;
943
944 /* is this a new value? */
945 if (pf->wol_en != !!wol->wolopts) {
946 pf->wol_en = !!wol->wolopts;
947 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
948 }
949
950 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000951}
952
953static int i40e_nway_reset(struct net_device *netdev)
954{
955 /* restart autonegotiation */
956 struct i40e_netdev_priv *np = netdev_priv(netdev);
957 struct i40e_pf *pf = np->vsi->back;
958 struct i40e_hw *hw = &pf->hw;
959 i40e_status ret = 0;
960
961 ret = i40e_aq_set_link_restart_an(hw, NULL);
962 if (ret) {
963 netdev_info(netdev, "link restart failed, aq_err=%d\n",
964 pf->hw.aq.asq_last_status);
965 return -EIO;
966 }
967
968 return 0;
969}
970
971static int i40e_set_phys_id(struct net_device *netdev,
972 enum ethtool_phys_id_state state)
973{
974 struct i40e_netdev_priv *np = netdev_priv(netdev);
975 struct i40e_pf *pf = np->vsi->back;
976 struct i40e_hw *hw = &pf->hw;
977 int blink_freq = 2;
978
979 switch (state) {
980 case ETHTOOL_ID_ACTIVE:
981 pf->led_status = i40e_led_get(hw);
982 return blink_freq;
983 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000984 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000985 break;
986 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000987 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000988 break;
989 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000990 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000991 break;
992 }
993
994 return 0;
995}
996
997/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
998 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
999 * 125us (8000 interrupts per second) == ITR(62)
1000 */
1001
1002static int i40e_get_coalesce(struct net_device *netdev,
1003 struct ethtool_coalesce *ec)
1004{
1005 struct i40e_netdev_priv *np = netdev_priv(netdev);
1006 struct i40e_vsi *vsi = np->vsi;
1007
1008 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1009 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1010
1011 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001012 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001013
1014 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001015 ec->use_adaptive_tx_coalesce = 1;
1016
1017 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1018 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001019
1020 return 0;
1021}
1022
1023static int i40e_set_coalesce(struct net_device *netdev,
1024 struct ethtool_coalesce *ec)
1025{
1026 struct i40e_netdev_priv *np = netdev_priv(netdev);
1027 struct i40e_q_vector *q_vector;
1028 struct i40e_vsi *vsi = np->vsi;
1029 struct i40e_pf *pf = vsi->back;
1030 struct i40e_hw *hw = &pf->hw;
1031 u16 vector;
1032 int i;
1033
1034 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1035 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1036
Mitch Williams32f5f542014-04-04 04:43:10 +00001037 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1038 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001039 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Mitch Williams32f5f542014-04-04 04:43:10 +00001040 else
1041 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001042
Mitch Williams32f5f542014-04-04 04:43:10 +00001043 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1044 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001045 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Mitch Williams32f5f542014-04-04 04:43:10 +00001046 else
1047 return -EINVAL;
1048
1049 if (ec->use_adaptive_rx_coalesce)
1050 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1051 else
1052 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1053
1054 if (ec->use_adaptive_tx_coalesce)
1055 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1056 else
1057 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001058
1059 vector = vsi->base_vector;
Alexander Duyck493fb302013-09-28 07:01:44 +00001060 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1061 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001062 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1063 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1064 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1065 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1066 i40e_flush(hw);
1067 }
1068
1069 return 0;
1070}
1071
1072/**
1073 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1074 * @pf: pointer to the physical function struct
1075 * @cmd: ethtool rxnfc command
1076 *
1077 * Returns Success if the flow is supported, else Invalid Input.
1078 **/
1079static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1080{
1081 cmd->data = 0;
1082
1083 /* Report default options for RSS on i40e */
1084 switch (cmd->flow_type) {
1085 case TCP_V4_FLOW:
1086 case UDP_V4_FLOW:
1087 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1088 /* fall through to add IP fields */
1089 case SCTP_V4_FLOW:
1090 case AH_ESP_V4_FLOW:
1091 case AH_V4_FLOW:
1092 case ESP_V4_FLOW:
1093 case IPV4_FLOW:
1094 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1095 break;
1096 case TCP_V6_FLOW:
1097 case UDP_V6_FLOW:
1098 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1099 /* fall through to add IP fields */
1100 case SCTP_V6_FLOW:
1101 case AH_ESP_V6_FLOW:
1102 case AH_V6_FLOW:
1103 case ESP_V6_FLOW:
1104 case IPV6_FLOW:
1105 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1106 break;
1107 default:
1108 return -EINVAL;
1109 }
1110
1111 return 0;
1112}
1113
1114/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001115 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1116 * @pf: Pointer to the physical function struct
1117 * @cmd: The command to get or set Rx flow classification rules
1118 * @rule_locs: Array of used rule locations
1119 *
1120 * This function populates both the total and actual rule count of
1121 * the ethtool flow classification command
1122 *
1123 * Returns 0 on success or -EMSGSIZE if entry not found
1124 **/
1125static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1126 struct ethtool_rxnfc *cmd,
1127 u32 *rule_locs)
1128{
1129 struct i40e_fdir_filter *rule;
1130 struct hlist_node *node2;
1131 int cnt = 0;
1132
1133 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001134 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001135
1136 hlist_for_each_entry_safe(rule, node2,
1137 &pf->fdir_filter_list, fdir_node) {
1138 if (cnt == cmd->rule_cnt)
1139 return -EMSGSIZE;
1140
1141 rule_locs[cnt] = rule->fd_id;
1142 cnt++;
1143 }
1144
1145 cmd->rule_cnt = cnt;
1146
1147 return 0;
1148}
1149
1150/**
1151 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1152 * @pf: Pointer to the physical function struct
1153 * @cmd: The command to get or set Rx flow classification rules
1154 *
1155 * This function looks up a filter based on the Rx flow classification
1156 * command and fills the flow spec info for it if found
1157 *
1158 * Returns 0 on success or -EINVAL if filter not found
1159 **/
1160static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1161 struct ethtool_rxnfc *cmd)
1162{
1163 struct ethtool_rx_flow_spec *fsp =
1164 (struct ethtool_rx_flow_spec *)&cmd->fs;
1165 struct i40e_fdir_filter *rule = NULL;
1166 struct hlist_node *node2;
1167
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001168 hlist_for_each_entry_safe(rule, node2,
1169 &pf->fdir_filter_list, fdir_node) {
1170 if (fsp->location <= rule->fd_id)
1171 break;
1172 }
1173
1174 if (!rule || fsp->location != rule->fd_id)
1175 return -EINVAL;
1176
1177 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001178 if (fsp->flow_type == IP_USER_FLOW) {
1179 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1180 fsp->h_u.usr_ip4_spec.proto = 0;
1181 fsp->m_u.usr_ip4_spec.proto = 0;
1182 }
1183
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001184 fsp->h_u.tcp_ip4_spec.psrc = rule->src_port;
1185 fsp->h_u.tcp_ip4_spec.pdst = rule->dst_port;
1186 fsp->h_u.tcp_ip4_spec.ip4src = rule->src_ip[0];
1187 fsp->h_u.tcp_ip4_spec.ip4dst = rule->dst_ip[0];
1188 fsp->ring_cookie = rule->q_index;
1189
1190 return 0;
1191}
1192
1193/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001194 * i40e_get_rxnfc - command to get RX flow classification rules
1195 * @netdev: network interface device structure
1196 * @cmd: ethtool rxnfc command
1197 *
1198 * Returns Success if the command is supported.
1199 **/
1200static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1201 u32 *rule_locs)
1202{
1203 struct i40e_netdev_priv *np = netdev_priv(netdev);
1204 struct i40e_vsi *vsi = np->vsi;
1205 struct i40e_pf *pf = vsi->back;
1206 int ret = -EOPNOTSUPP;
1207
1208 switch (cmd->cmd) {
1209 case ETHTOOL_GRXRINGS:
1210 cmd->data = vsi->alloc_queue_pairs;
1211 ret = 0;
1212 break;
1213 case ETHTOOL_GRXFH:
1214 ret = i40e_get_rss_hash_opts(pf, cmd);
1215 break;
1216 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001217 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001218 /* report total rule count */
1219 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001220 ret = 0;
1221 break;
1222 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001223 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001224 break;
1225 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001226 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1227 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001228 default:
1229 break;
1230 }
1231
1232 return ret;
1233}
1234
1235/**
1236 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1237 * @pf: pointer to the physical function struct
1238 * @cmd: ethtool rxnfc command
1239 *
1240 * Returns Success if the flow input set is supported.
1241 **/
1242static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1243{
1244 struct i40e_hw *hw = &pf->hw;
1245 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1246 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1247
1248 /* RSS does not support anything other than hashing
1249 * to queues on src and dst IPs and ports
1250 */
1251 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1252 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1253 return -EINVAL;
1254
1255 /* We need at least the IP SRC and DEST fields for hashing */
1256 if (!(nfc->data & RXH_IP_SRC) ||
1257 !(nfc->data & RXH_IP_DST))
1258 return -EINVAL;
1259
1260 switch (nfc->flow_type) {
1261 case TCP_V4_FLOW:
1262 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1263 case 0:
1264 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1265 break;
1266 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1267 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1268 break;
1269 default:
1270 return -EINVAL;
1271 }
1272 break;
1273 case TCP_V6_FLOW:
1274 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1275 case 0:
1276 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1277 break;
1278 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1279 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1280 break;
1281 default:
1282 return -EINVAL;
1283 }
1284 break;
1285 case UDP_V4_FLOW:
1286 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1287 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001288 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1289 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001290 break;
1291 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001292 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1293 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001294 break;
1295 default:
1296 return -EINVAL;
1297 }
1298 break;
1299 case UDP_V6_FLOW:
1300 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1301 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001302 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1303 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001304 break;
1305 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001306 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1307 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001308 break;
1309 default:
1310 return -EINVAL;
1311 }
1312 break;
1313 case AH_ESP_V4_FLOW:
1314 case AH_V4_FLOW:
1315 case ESP_V4_FLOW:
1316 case SCTP_V4_FLOW:
1317 if ((nfc->data & RXH_L4_B_0_1) ||
1318 (nfc->data & RXH_L4_B_2_3))
1319 return -EINVAL;
1320 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1321 break;
1322 case AH_ESP_V6_FLOW:
1323 case AH_V6_FLOW:
1324 case ESP_V6_FLOW:
1325 case SCTP_V6_FLOW:
1326 if ((nfc->data & RXH_L4_B_0_1) ||
1327 (nfc->data & RXH_L4_B_2_3))
1328 return -EINVAL;
1329 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1330 break;
1331 case IPV4_FLOW:
1332 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1333 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1334 break;
1335 case IPV6_FLOW:
1336 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1337 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1338 break;
1339 default:
1340 return -EINVAL;
1341 }
1342
1343 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1344 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1345 i40e_flush(hw);
1346
1347 return 0;
1348}
1349
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001350/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001351 * i40e_match_fdir_input_set - Match a new filter against an existing one
1352 * @rule: The filter already added
1353 * @input: The new filter to comapre against
1354 *
1355 * Returns true if the two input set match
1356 **/
1357static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1358 struct i40e_fdir_filter *input)
1359{
1360 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1361 (rule->src_ip[0] != input->src_ip[0]) ||
1362 (rule->dst_port != input->dst_port) ||
1363 (rule->src_port != input->src_port))
1364 return false;
1365 return true;
1366}
1367
1368/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001369 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1370 * @vsi: Pointer to the targeted VSI
1371 * @input: The filter to update or NULL to indicate deletion
1372 * @sw_idx: Software index to the filter
1373 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001374 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001375 * This function updates (or deletes) a Flow Director entry from
1376 * the hlist of the corresponding PF
1377 *
1378 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001379 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001380static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1381 struct i40e_fdir_filter *input,
1382 u16 sw_idx,
1383 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001384{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001385 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001386 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001387 struct hlist_node *node2;
1388 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001389
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001390 parent = NULL;
1391 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001392
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001393 hlist_for_each_entry_safe(rule, node2,
1394 &pf->fdir_filter_list, fdir_node) {
1395 /* hash found, or no matching entry */
1396 if (rule->fd_id >= sw_idx)
1397 break;
1398 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001399 }
1400
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001401 /* if there is an old rule occupying our place remove it */
1402 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00001403 if (input && !i40e_match_fdir_input_set(rule, input))
1404 err = i40e_add_del_fdir(vsi, rule, false);
1405 else if (!input)
1406 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001407 hlist_del(&rule->fdir_node);
1408 kfree(rule);
1409 pf->fdir_pf_active_filters--;
1410 }
1411
1412 /* If no input this was a delete, err should be 0 if a rule was
1413 * successfully found and removed from the list else -EINVAL
1414 */
1415 if (!input)
1416 return err;
1417
1418 /* initialize node and set software index */
1419 INIT_HLIST_NODE(&input->fdir_node);
1420
1421 /* add filter to the list */
1422 if (parent)
1423 hlist_add_after(&parent->fdir_node, &input->fdir_node);
1424 else
1425 hlist_add_head(&input->fdir_node,
1426 &pf->fdir_filter_list);
1427
1428 /* update counts */
1429 pf->fdir_pf_active_filters++;
1430
1431 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001432}
1433
1434/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001435 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
1436 * @vsi: Pointer to the targeted VSI
1437 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001438 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001439 * The function removes a Flow Director filter entry from the
1440 * hlist of the corresponding PF
1441 *
1442 * Returns 0 on success
1443 */
1444static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
1445 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001446{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001447 struct ethtool_rx_flow_spec *fsp =
1448 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001449 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001450 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001451
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001452 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001453
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001454 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001455 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001456}
1457
1458/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001459 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001460 * @vsi: pointer to the targeted VSI
1461 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001462 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001463 * Add Flow Director filters for a specific flow spec based on their
1464 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001465 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001466static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
1467 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001468{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001469 struct ethtool_rx_flow_spec *fsp;
1470 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001471 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001472 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001473
1474 if (!vsi)
1475 return -EINVAL;
1476
1477 pf = vsi->back;
1478
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001479 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
1480 return -EOPNOTSUPP;
1481
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001482 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00001483 return -ENOSPC;
1484
1485 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
1486
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001487 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
1488 pf->hw.func_caps.fd_filters_guaranteed)) {
1489 return -EINVAL;
1490 }
1491
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001492 if (fsp->ring_cookie >= vsi->num_queue_pairs)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001493 return -EINVAL;
1494
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001495 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001496
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001497 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001498 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001499
1500 input->fd_id = fsp->location;
1501
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00001502 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
1503 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
1504 else
1505 input->dest_ctl =
1506 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
1507
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001508 input->q_index = fsp->ring_cookie;
1509 input->flex_off = 0;
1510 input->pctype = 0;
1511 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001512 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
1513 input->cnt_index = 0;
1514 input->flow_type = fsp->flow_type;
1515 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
1516 input->src_port = fsp->h_u.tcp_ip4_spec.psrc;
1517 input->dst_port = fsp->h_u.tcp_ip4_spec.pdst;
1518 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
1519 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
1520
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001521 ret = i40e_add_del_fdir(vsi, input, true);
1522 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001523 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001524 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001525 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001526
1527 return ret;
1528}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08001529
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001530/**
1531 * i40e_set_rxnfc - command to set RX flow classification rules
1532 * @netdev: network interface device structure
1533 * @cmd: ethtool rxnfc command
1534 *
1535 * Returns Success if the command is supported.
1536 **/
1537static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1538{
1539 struct i40e_netdev_priv *np = netdev_priv(netdev);
1540 struct i40e_vsi *vsi = np->vsi;
1541 struct i40e_pf *pf = vsi->back;
1542 int ret = -EOPNOTSUPP;
1543
1544 switch (cmd->cmd) {
1545 case ETHTOOL_SRXFH:
1546 ret = i40e_set_rss_hash_opt(pf, cmd);
1547 break;
1548 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00001549 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001550 break;
1551 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001552 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001553 break;
1554 default:
1555 break;
1556 }
1557
1558 return ret;
1559}
1560
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001561/**
1562 * i40e_max_channels - get Max number of combined channels supported
1563 * @vsi: vsi pointer
1564 **/
1565static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
1566{
1567 /* TODO: This code assumes DCB and FD is disabled for now. */
1568 return vsi->alloc_queue_pairs;
1569}
1570
1571/**
1572 * i40e_get_channels - Get the current channels enabled and max supported etc.
1573 * @netdev: network interface device structure
1574 * @ch: ethtool channels structure
1575 *
1576 * We don't support separate tx and rx queues as channels. The other count
1577 * represents how many queues are being used for control. max_combined counts
1578 * how many queue pairs we can support. They may not be mapped 1 to 1 with
1579 * q_vectors since we support a lot more queue pairs than q_vectors.
1580 **/
1581static void i40e_get_channels(struct net_device *dev,
1582 struct ethtool_channels *ch)
1583{
1584 struct i40e_netdev_priv *np = netdev_priv(dev);
1585 struct i40e_vsi *vsi = np->vsi;
1586 struct i40e_pf *pf = vsi->back;
1587
1588 /* report maximum channels */
1589 ch->max_combined = i40e_max_channels(vsi);
1590
1591 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08001592 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001593 ch->max_other = ch->other_count;
1594
1595 /* Note: This code assumes DCB is disabled for now. */
1596 ch->combined_count = vsi->num_queue_pairs;
1597}
1598
1599/**
1600 * i40e_set_channels - Set the new channels count.
1601 * @netdev: network interface device structure
1602 * @ch: ethtool channels structure
1603 *
1604 * The new channels count may not be the same as requested by the user
1605 * since it gets rounded down to a power of 2 value.
1606 **/
1607static int i40e_set_channels(struct net_device *dev,
1608 struct ethtool_channels *ch)
1609{
1610 struct i40e_netdev_priv *np = netdev_priv(dev);
1611 unsigned int count = ch->combined_count;
1612 struct i40e_vsi *vsi = np->vsi;
1613 struct i40e_pf *pf = vsi->back;
1614 int new_count;
1615
1616 /* We do not support setting channels for any other VSI at present */
1617 if (vsi->type != I40E_VSI_MAIN)
1618 return -EINVAL;
1619
1620 /* verify they are not requesting separate vectors */
1621 if (!count || ch->rx_count || ch->tx_count)
1622 return -EINVAL;
1623
1624 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08001625 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001626 return -EINVAL;
1627
1628 /* verify the number of channels does not exceed hardware limits */
1629 if (count > i40e_max_channels(vsi))
1630 return -EINVAL;
1631
1632 /* update feature limits from largest to smallest supported values */
1633 /* TODO: Flow director limit, DCB etc */
1634
1635 /* cap RSS limit */
1636 if (count > pf->rss_size_max)
1637 count = pf->rss_size_max;
1638
1639 /* use rss_reconfig to rebuild with new queue count and update traffic
1640 * class queue mapping
1641 */
1642 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00001643 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001644 return 0;
1645 else
1646 return -EINVAL;
1647}
1648
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001649static const struct ethtool_ops i40e_ethtool_ops = {
1650 .get_settings = i40e_get_settings,
1651 .get_drvinfo = i40e_get_drvinfo,
1652 .get_regs_len = i40e_get_regs_len,
1653 .get_regs = i40e_get_regs,
1654 .nway_reset = i40e_nway_reset,
1655 .get_link = ethtool_op_get_link,
1656 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001657 .set_wol = i40e_set_wol,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001658 .get_eeprom_len = i40e_get_eeprom_len,
1659 .get_eeprom = i40e_get_eeprom,
1660 .get_ringparam = i40e_get_ringparam,
1661 .set_ringparam = i40e_set_ringparam,
1662 .get_pauseparam = i40e_get_pauseparam,
1663 .get_msglevel = i40e_get_msglevel,
1664 .set_msglevel = i40e_set_msglevel,
1665 .get_rxnfc = i40e_get_rxnfc,
1666 .set_rxnfc = i40e_set_rxnfc,
1667 .self_test = i40e_diag_test,
1668 .get_strings = i40e_get_strings,
1669 .set_phys_id = i40e_set_phys_id,
1670 .get_sset_count = i40e_get_sset_count,
1671 .get_ethtool_stats = i40e_get_ethtool_stats,
1672 .get_coalesce = i40e_get_coalesce,
1673 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001674 .get_channels = i40e_get_channels,
1675 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001676 .get_ts_info = i40e_get_ts_info,
1677};
1678
1679void i40e_set_ethtool_ops(struct net_device *netdev)
1680{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00001681 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001682}