blob: d34ff31fddd841af3af505641403fc185ed58c4c [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
Joseph Gasparakis17a73f62014-02-12 01:45:30 +000065static int i40e_add_del_fdir_ethtool(struct i40e_vsi *vsi,
66 struct ethtool_rxnfc *cmd, bool add);
67
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("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
116 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000117};
118
119#define I40E_QUEUE_STATS_LEN(n) \
120 ((((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs + \
121 ((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs) * 2)
122#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
123#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
124#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
125 I40E_QUEUE_STATS_LEN((n)))
126#define I40E_PFC_STATS_LEN ( \
127 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
128 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
129 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
130 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
131 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
132 / sizeof(u64))
133#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
134 I40E_PFC_STATS_LEN + \
135 I40E_VSI_STATS_LEN((n)))
136
137enum i40e_ethtool_test_id {
138 I40E_ETH_TEST_REG = 0,
139 I40E_ETH_TEST_EEPROM,
140 I40E_ETH_TEST_INTR,
141 I40E_ETH_TEST_LOOPBACK,
142 I40E_ETH_TEST_LINK,
143};
144
145static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
146 "Register test (offline)",
147 "Eeprom test (offline)",
148 "Interrupt test (offline)",
149 "Loopback test (offline)",
150 "Link test (on/offline)"
151};
152
153#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
154
155/**
156 * i40e_get_settings - Get Link Speed and Duplex settings
157 * @netdev: network interface device structure
158 * @ecmd: ethtool command
159 *
160 * Reports speed/duplex settings based on media_type
161 **/
162static int i40e_get_settings(struct net_device *netdev,
163 struct ethtool_cmd *ecmd)
164{
165 struct i40e_netdev_priv *np = netdev_priv(netdev);
166 struct i40e_pf *pf = np->vsi->back;
167 struct i40e_hw *hw = &pf->hw;
168 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
169 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
170 u32 link_speed = hw_link_info->link_speed;
171
172 /* hardware is either in 40G mode or 10G mode
173 * NOTE: this section initializes supported and advertising
174 */
175 switch (hw_link_info->phy_type) {
176 case I40E_PHY_TYPE_40GBASE_CR4:
177 case I40E_PHY_TYPE_40GBASE_CR4_CU:
178 ecmd->supported = SUPPORTED_40000baseCR4_Full;
179 ecmd->advertising = ADVERTISED_40000baseCR4_Full;
180 break;
181 case I40E_PHY_TYPE_40GBASE_KR4:
182 ecmd->supported = SUPPORTED_40000baseKR4_Full;
183 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
184 break;
185 case I40E_PHY_TYPE_40GBASE_SR4:
186 ecmd->supported = SUPPORTED_40000baseSR4_Full;
187 ecmd->advertising = ADVERTISED_40000baseSR4_Full;
188 break;
189 case I40E_PHY_TYPE_40GBASE_LR4:
190 ecmd->supported = SUPPORTED_40000baseLR4_Full;
191 ecmd->advertising = ADVERTISED_40000baseLR4_Full;
192 break;
193 case I40E_PHY_TYPE_10GBASE_KX4:
194 ecmd->supported = SUPPORTED_10000baseKX4_Full;
195 ecmd->advertising = ADVERTISED_10000baseKX4_Full;
196 break;
197 case I40E_PHY_TYPE_10GBASE_KR:
198 ecmd->supported = SUPPORTED_10000baseKR_Full;
199 ecmd->advertising = ADVERTISED_10000baseKR_Full;
200 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000201 default:
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000202 if (i40e_is_40G_device(hw->device_id)) {
203 ecmd->supported = SUPPORTED_40000baseSR4_Full;
204 ecmd->advertising = ADVERTISED_40000baseSR4_Full;
205 } else {
206 ecmd->supported = SUPPORTED_10000baseT_Full;
207 ecmd->advertising = ADVERTISED_10000baseT_Full;
208 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000209 break;
210 }
211
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000212 ecmd->supported |= SUPPORTED_Autoneg;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000213 ecmd->advertising |= ADVERTISED_Autoneg;
214 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
215 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000216
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000217 switch (hw->phy.media_type) {
218 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000219 ecmd->supported |= SUPPORTED_Backplane;
220 ecmd->advertising |= ADVERTISED_Backplane;
221 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000222 break;
223 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000224 ecmd->supported |= SUPPORTED_TP;
225 ecmd->advertising |= ADVERTISED_TP;
226 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000227 break;
228 case I40E_MEDIA_TYPE_DA:
229 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000230 ecmd->supported |= SUPPORTED_FIBRE;
231 ecmd->advertising |= ADVERTISED_FIBRE;
232 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000233 break;
234 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000235 ecmd->supported |= SUPPORTED_FIBRE;
236 ecmd->advertising |= ADVERTISED_FIBRE;
237 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000238 break;
239 case I40E_MEDIA_TYPE_UNKNOWN:
240 default:
241 ecmd->port = PORT_OTHER;
242 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000243 }
244
245 ecmd->transceiver = XCVR_EXTERNAL;
246
247 if (link_up) {
248 switch (link_speed) {
249 case I40E_LINK_SPEED_40GB:
250 /* need a SPEED_40000 in ethtool.h */
251 ethtool_cmd_speed_set(ecmd, 40000);
252 break;
253 case I40E_LINK_SPEED_10GB:
254 ethtool_cmd_speed_set(ecmd, SPEED_10000);
255 break;
256 default:
257 break;
258 }
259 ecmd->duplex = DUPLEX_FULL;
260 } else {
261 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
262 ecmd->duplex = DUPLEX_UNKNOWN;
263 }
264
265 return 0;
266}
267
268/**
269 * i40e_get_pauseparam - Get Flow Control status
270 * Return tx/rx-pause status
271 **/
272static void i40e_get_pauseparam(struct net_device *netdev,
273 struct ethtool_pauseparam *pause)
274{
275 struct i40e_netdev_priv *np = netdev_priv(netdev);
276 struct i40e_pf *pf = np->vsi->back;
277 struct i40e_hw *hw = &pf->hw;
278 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
279
280 pause->autoneg =
281 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
282 AUTONEG_ENABLE : AUTONEG_DISABLE);
283
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000284 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000285 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000286 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000287 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000288 } else if (hw->fc.current_mode == I40E_FC_FULL) {
289 pause->rx_pause = 1;
290 pause->tx_pause = 1;
291 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000292}
293
294static u32 i40e_get_msglevel(struct net_device *netdev)
295{
296 struct i40e_netdev_priv *np = netdev_priv(netdev);
297 struct i40e_pf *pf = np->vsi->back;
298
299 return pf->msg_enable;
300}
301
302static void i40e_set_msglevel(struct net_device *netdev, u32 data)
303{
304 struct i40e_netdev_priv *np = netdev_priv(netdev);
305 struct i40e_pf *pf = np->vsi->back;
306
307 if (I40E_DEBUG_USER & data)
308 pf->hw.debug_mask = data;
309 pf->msg_enable = data;
310}
311
312static int i40e_get_regs_len(struct net_device *netdev)
313{
314 int reg_count = 0;
315 int i;
316
317 for (i = 0; i40e_reg_list[i].offset != 0; i++)
318 reg_count += i40e_reg_list[i].elements;
319
320 return reg_count * sizeof(u32);
321}
322
323static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
324 void *p)
325{
326 struct i40e_netdev_priv *np = netdev_priv(netdev);
327 struct i40e_pf *pf = np->vsi->back;
328 struct i40e_hw *hw = &pf->hw;
329 u32 *reg_buf = p;
330 int i, j, ri;
331 u32 reg;
332
333 /* Tell ethtool which driver-version-specific regs output we have.
334 *
335 * At some point, if we have ethtool doing special formatting of
336 * this data, it will rely on this version number to know how to
337 * interpret things. Hence, this needs to be updated if/when the
338 * diags register table is changed.
339 */
340 regs->version = 1;
341
342 /* loop through the diags reg table for what to print */
343 ri = 0;
344 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
345 for (j = 0; j < i40e_reg_list[i].elements; j++) {
346 reg = i40e_reg_list[i].offset
347 + (j * i40e_reg_list[i].stride);
348 reg_buf[ri++] = rd32(hw, reg);
349 }
350 }
351
352}
353
354static int i40e_get_eeprom(struct net_device *netdev,
355 struct ethtool_eeprom *eeprom, u8 *bytes)
356{
357 struct i40e_netdev_priv *np = netdev_priv(netdev);
358 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000359 struct i40e_pf *pf = np->vsi->back;
360 int ret_val = 0, len;
361 u8 *eeprom_buff;
362 u16 i, sectors;
363 bool last;
364#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000365 if (eeprom->len == 0)
366 return -EINVAL;
367
368 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
369
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000370 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000371 if (!eeprom_buff)
372 return -ENOMEM;
373
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000374 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
375 if (ret_val) {
376 dev_info(&pf->pdev->dev,
377 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
378 ret_val, hw->aq.asq_last_status);
379 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000380 }
381
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000382 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
383 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
384 len = I40E_NVM_SECTOR_SIZE;
385 last = false;
386 for (i = 0; i < sectors; i++) {
387 if (i == (sectors - 1)) {
388 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
389 last = true;
390 }
391 ret_val = i40e_aq_read_nvm(hw, 0x0,
392 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
393 len,
394 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
395 last, NULL);
396 if (ret_val) {
397 dev_info(&pf->pdev->dev,
398 "read NVM failed err=%d status=0x%x\n",
399 ret_val, hw->aq.asq_last_status);
400 goto release_nvm;
401 }
402 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000403
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000404release_nvm:
405 i40e_release_nvm(hw);
406 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
407free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000408 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000409 return ret_val;
410}
411
412static int i40e_get_eeprom_len(struct net_device *netdev)
413{
414 struct i40e_netdev_priv *np = netdev_priv(netdev);
415 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000416 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000417
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000418 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
419 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
420 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
421 /* register returns value in power of 2, 64Kbyte chunks. */
422 val = (64 * 1024) * (1 << val);
423 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000424}
425
426static void i40e_get_drvinfo(struct net_device *netdev,
427 struct ethtool_drvinfo *drvinfo)
428{
429 struct i40e_netdev_priv *np = netdev_priv(netdev);
430 struct i40e_vsi *vsi = np->vsi;
431 struct i40e_pf *pf = vsi->back;
432
433 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
434 strlcpy(drvinfo->version, i40e_driver_version_str,
435 sizeof(drvinfo->version));
436 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
437 sizeof(drvinfo->fw_version));
438 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
439 sizeof(drvinfo->bus_info));
440}
441
442static void i40e_get_ringparam(struct net_device *netdev,
443 struct ethtool_ringparam *ring)
444{
445 struct i40e_netdev_priv *np = netdev_priv(netdev);
446 struct i40e_pf *pf = np->vsi->back;
447 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
448
449 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
450 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
451 ring->rx_mini_max_pending = 0;
452 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +0000453 ring->rx_pending = vsi->rx_rings[0]->count;
454 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000455 ring->rx_mini_pending = 0;
456 ring->rx_jumbo_pending = 0;
457}
458
459static int i40e_set_ringparam(struct net_device *netdev,
460 struct ethtool_ringparam *ring)
461{
462 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
463 struct i40e_netdev_priv *np = netdev_priv(netdev);
464 struct i40e_vsi *vsi = np->vsi;
465 struct i40e_pf *pf = vsi->back;
466 u32 new_rx_count, new_tx_count;
467 int i, err = 0;
468
469 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
470 return -EINVAL;
471
Shannon Nelson1fa18372013-11-20 10:03:08 +0000472 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
473 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
474 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
475 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
476 netdev_info(netdev,
477 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
478 ring->tx_pending, ring->rx_pending,
479 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
480 return -EINVAL;
481 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000482
Shannon Nelson1fa18372013-11-20 10:03:08 +0000483 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
484 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000485
486 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000487 if ((new_tx_count == vsi->tx_rings[0]->count) &&
488 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000489 return 0;
490
491 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
492 usleep_range(1000, 2000);
493
494 if (!netif_running(vsi->netdev)) {
495 /* simple case - set for the next time the netdev is started */
496 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000497 vsi->tx_rings[i]->count = new_tx_count;
498 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000499 }
500 goto done;
501 }
502
503 /* We can't just free everything and then setup again,
504 * because the ISRs in MSI-X mode get passed pointers
505 * to the Tx and Rx ring structs.
506 */
507
508 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000509 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000510 netdev_info(netdev,
511 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000512 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000513 tx_rings = kcalloc(vsi->alloc_queue_pairs,
514 sizeof(struct i40e_ring), GFP_KERNEL);
515 if (!tx_rings) {
516 err = -ENOMEM;
517 goto done;
518 }
519
520 for (i = 0; i < vsi->num_queue_pairs; i++) {
521 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000522 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000523 tx_rings[i].count = new_tx_count;
524 err = i40e_setup_tx_descriptors(&tx_rings[i]);
525 if (err) {
526 while (i) {
527 i--;
528 i40e_free_tx_resources(&tx_rings[i]);
529 }
530 kfree(tx_rings);
531 tx_rings = NULL;
532
533 goto done;
534 }
535 }
536 }
537
538 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000539 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000540 netdev_info(netdev,
541 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000542 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000543 rx_rings = kcalloc(vsi->alloc_queue_pairs,
544 sizeof(struct i40e_ring), GFP_KERNEL);
545 if (!rx_rings) {
546 err = -ENOMEM;
547 goto free_tx;
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 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000553 rx_rings[i].count = new_rx_count;
554 err = i40e_setup_rx_descriptors(&rx_rings[i]);
555 if (err) {
556 while (i) {
557 i--;
558 i40e_free_rx_resources(&rx_rings[i]);
559 }
560 kfree(rx_rings);
561 rx_rings = NULL;
562
563 goto free_tx;
564 }
565 }
566 }
567
568 /* Bring interface down, copy in the new ring info,
569 * then restore the interface
570 */
571 i40e_down(vsi);
572
573 if (tx_rings) {
574 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000575 i40e_free_tx_resources(vsi->tx_rings[i]);
576 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000577 }
578 kfree(tx_rings);
579 tx_rings = NULL;
580 }
581
582 if (rx_rings) {
583 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000584 i40e_free_rx_resources(vsi->rx_rings[i]);
585 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000586 }
587 kfree(rx_rings);
588 rx_rings = NULL;
589 }
590
591 i40e_up(vsi);
592
593free_tx:
594 /* error cleanup if the Rx allocations failed after getting Tx */
595 if (tx_rings) {
596 for (i = 0; i < vsi->num_queue_pairs; i++)
597 i40e_free_tx_resources(&tx_rings[i]);
598 kfree(tx_rings);
599 tx_rings = NULL;
600 }
601
602done:
603 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
604
605 return err;
606}
607
608static int i40e_get_sset_count(struct net_device *netdev, int sset)
609{
610 struct i40e_netdev_priv *np = netdev_priv(netdev);
611 struct i40e_vsi *vsi = np->vsi;
612 struct i40e_pf *pf = vsi->back;
613
614 switch (sset) {
615 case ETH_SS_TEST:
616 return I40E_TEST_LEN;
617 case ETH_SS_STATS:
618 if (vsi == pf->vsi[pf->lan_vsi])
619 return I40E_PF_STATS_LEN(netdev);
620 else
621 return I40E_VSI_STATS_LEN(netdev);
622 default:
623 return -EOPNOTSUPP;
624 }
625}
626
627static void i40e_get_ethtool_stats(struct net_device *netdev,
628 struct ethtool_stats *stats, u64 *data)
629{
630 struct i40e_netdev_priv *np = netdev_priv(netdev);
631 struct i40e_vsi *vsi = np->vsi;
632 struct i40e_pf *pf = vsi->back;
633 int i = 0;
634 char *p;
635 int j;
636 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000637 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000638
639 i40e_update_stats(vsi);
640
641 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
642 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
643 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
644 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
645 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000646 rcu_read_lock();
Alexander Duycka114d0a2013-09-28 06:00:43 +0000647 for (j = 0; j < vsi->num_queue_pairs; j++, i += 4) {
Alexander Duyck980e9b12013-09-28 06:01:03 +0000648 struct i40e_ring *tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
649 struct i40e_ring *rx_ring;
650
651 if (!tx_ring)
652 continue;
653
654 /* process Tx ring statistics */
655 do {
656 start = u64_stats_fetch_begin_bh(&tx_ring->syncp);
657 data[i] = tx_ring->stats.packets;
658 data[i + 1] = tx_ring->stats.bytes;
659 } while (u64_stats_fetch_retry_bh(&tx_ring->syncp, start));
660
661 /* Rx ring is the 2nd half of the queue pair */
662 rx_ring = &tx_ring[1];
663 do {
664 start = u64_stats_fetch_begin_bh(&rx_ring->syncp);
665 data[i + 2] = rx_ring->stats.packets;
666 data[i + 3] = rx_ring->stats.bytes;
667 } while (u64_stats_fetch_retry_bh(&rx_ring->syncp, start));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000668 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000669 rcu_read_unlock();
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000670 if (vsi == pf->vsi[pf->lan_vsi]) {
671 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
672 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
673 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
674 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
675 }
676 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
677 data[i++] = pf->stats.priority_xon_tx[j];
678 data[i++] = pf->stats.priority_xoff_tx[j];
679 }
680 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
681 data[i++] = pf->stats.priority_xon_rx[j];
682 data[i++] = pf->stats.priority_xoff_rx[j];
683 }
684 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
685 data[i++] = pf->stats.priority_xon_2_xoff[j];
686 }
687}
688
689static void i40e_get_strings(struct net_device *netdev, u32 stringset,
690 u8 *data)
691{
692 struct i40e_netdev_priv *np = netdev_priv(netdev);
693 struct i40e_vsi *vsi = np->vsi;
694 struct i40e_pf *pf = vsi->back;
695 char *p = (char *)data;
696 int i;
697
698 switch (stringset) {
699 case ETH_SS_TEST:
700 for (i = 0; i < I40E_TEST_LEN; i++) {
701 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
702 data += ETH_GSTRING_LEN;
703 }
704 break;
705 case ETH_SS_STATS:
706 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
707 snprintf(p, ETH_GSTRING_LEN, "%s",
708 i40e_gstrings_net_stats[i].stat_string);
709 p += ETH_GSTRING_LEN;
710 }
711 for (i = 0; i < vsi->num_queue_pairs; i++) {
712 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
713 p += ETH_GSTRING_LEN;
714 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
715 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000716 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
717 p += ETH_GSTRING_LEN;
718 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
719 p += ETH_GSTRING_LEN;
720 }
721 if (vsi == pf->vsi[pf->lan_vsi]) {
722 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
723 snprintf(p, ETH_GSTRING_LEN, "port.%s",
724 i40e_gstrings_stats[i].stat_string);
725 p += ETH_GSTRING_LEN;
726 }
727 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
728 snprintf(p, ETH_GSTRING_LEN,
729 "port.tx_priority_%u_xon", i);
730 p += ETH_GSTRING_LEN;
731 snprintf(p, ETH_GSTRING_LEN,
732 "port.tx_priority_%u_xoff", i);
733 p += ETH_GSTRING_LEN;
734 }
735 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
736 snprintf(p, ETH_GSTRING_LEN,
737 "port.rx_priority_%u_xon", i);
738 p += ETH_GSTRING_LEN;
739 snprintf(p, ETH_GSTRING_LEN,
740 "port.rx_priority_%u_xoff", i);
741 p += ETH_GSTRING_LEN;
742 }
743 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
744 snprintf(p, ETH_GSTRING_LEN,
745 "port.rx_priority_%u_xon_2_xoff", i);
746 p += ETH_GSTRING_LEN;
747 }
748 }
749 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
750 break;
751 }
752}
753
754static int i40e_get_ts_info(struct net_device *dev,
755 struct ethtool_ts_info *info)
756{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000757 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
758
759 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
760 SOF_TIMESTAMPING_RX_SOFTWARE |
761 SOF_TIMESTAMPING_SOFTWARE |
762 SOF_TIMESTAMPING_TX_HARDWARE |
763 SOF_TIMESTAMPING_RX_HARDWARE |
764 SOF_TIMESTAMPING_RAW_HARDWARE;
765
766 if (pf->ptp_clock)
767 info->phc_index = ptp_clock_index(pf->ptp_clock);
768 else
769 info->phc_index = -1;
770
771 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
772
773 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
774 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
775 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
776 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
777 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
778 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
779 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
780 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
781 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
782 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
783 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
784 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
785
786 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000787}
788
Shannon Nelson7b086392013-11-20 10:02:59 +0000789static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000790{
Shannon Nelson7b086392013-11-20 10:02:59 +0000791 struct i40e_netdev_priv *np = netdev_priv(netdev);
792 struct i40e_pf *pf = np->vsi->back;
793
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000794 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000795 if (i40e_get_link_status(&pf->hw))
796 *data = 0;
797 else
798 *data = 1;
799
800 return *data;
801}
802
Shannon Nelson7b086392013-11-20 10:02:59 +0000803static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000804{
Shannon Nelson7b086392013-11-20 10:02:59 +0000805 struct i40e_netdev_priv *np = netdev_priv(netdev);
806 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000807
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000808 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +0000809 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000810
Shannon Nelson7b086392013-11-20 10:02:59 +0000811 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000812}
813
Shannon Nelson7b086392013-11-20 10:02:59 +0000814static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000815{
Shannon Nelson7b086392013-11-20 10:02:59 +0000816 struct i40e_netdev_priv *np = netdev_priv(netdev);
817 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000818
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000819 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +0000820 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000821
Shannon Nelson7b086392013-11-20 10:02:59 +0000822 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000823}
824
Shannon Nelson7b086392013-11-20 10:02:59 +0000825static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000826{
Shannon Nelson7b086392013-11-20 10:02:59 +0000827 struct i40e_netdev_priv *np = netdev_priv(netdev);
828 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000829 u16 swc_old = pf->sw_int_count;
830
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000831 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000832 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
833 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
834 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
835 usleep_range(1000, 2000);
836 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000837
838 return *data;
839}
840
Shannon Nelson7b086392013-11-20 10:02:59 +0000841static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000842{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000843 struct i40e_netdev_priv *np = netdev_priv(netdev);
844 struct i40e_pf *pf = np->vsi->back;
845
846 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000847 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000848
849 return *data;
850}
851
852static void i40e_diag_test(struct net_device *netdev,
853 struct ethtool_test *eth_test, u64 *data)
854{
855 struct i40e_netdev_priv *np = netdev_priv(netdev);
856 struct i40e_pf *pf = np->vsi->back;
857
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000858 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
859 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000860 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000861
Shannon Nelsonf551b432013-11-26 10:49:12 +0000862 set_bit(__I40E_TESTING, &pf->state);
863
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000864 /* Link test performed before hardware reset
865 * so autoneg doesn't interfere with test result
866 */
Shannon Nelson7b086392013-11-20 10:02:59 +0000867 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000868 eth_test->flags |= ETH_TEST_FL_FAILED;
869
Shannon Nelson7b086392013-11-20 10:02:59 +0000870 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000871 eth_test->flags |= ETH_TEST_FL_FAILED;
872
Shannon Nelson7b086392013-11-20 10:02:59 +0000873 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000874 eth_test->flags |= ETH_TEST_FL_FAILED;
875
Shannon Nelson7b086392013-11-20 10:02:59 +0000876 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000877 eth_test->flags |= ETH_TEST_FL_FAILED;
878
Shannon Nelsonf551b432013-11-26 10:49:12 +0000879 /* run reg test last, a reset is required after it */
880 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
881 eth_test->flags |= ETH_TEST_FL_FAILED;
882
883 clear_bit(__I40E_TESTING, &pf->state);
884 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000885 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000886 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000887 netif_info(pf, drv, netdev, "online testing starting\n");
888
Shannon Nelson7b086392013-11-20 10:02:59 +0000889 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000890 eth_test->flags |= ETH_TEST_FL_FAILED;
891
892 /* Offline only tests, not run in online; pass by default */
893 data[I40E_ETH_TEST_REG] = 0;
894 data[I40E_ETH_TEST_EEPROM] = 0;
895 data[I40E_ETH_TEST_INTR] = 0;
896 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000897 }
Shannon Nelsonc140c172013-11-20 10:02:58 +0000898
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000899 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000900}
901
902static void i40e_get_wol(struct net_device *netdev,
903 struct ethtool_wolinfo *wol)
904{
Shannon Nelson8e2773a2013-11-28 06:39:22 +0000905 struct i40e_netdev_priv *np = netdev_priv(netdev);
906 struct i40e_pf *pf = np->vsi->back;
907 struct i40e_hw *hw = &pf->hw;
908 u16 wol_nvm_bits;
909
910 /* NVM bit on means WoL disabled for the port */
911 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
912 if ((1 << hw->port) & wol_nvm_bits) {
913 wol->supported = 0;
914 wol->wolopts = 0;
915 } else {
916 wol->supported = WAKE_MAGIC;
917 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
918 }
919}
920
921static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
922{
923 struct i40e_netdev_priv *np = netdev_priv(netdev);
924 struct i40e_pf *pf = np->vsi->back;
925 struct i40e_hw *hw = &pf->hw;
926 u16 wol_nvm_bits;
927
928 /* NVM bit on means WoL disabled for the port */
929 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
930 if (((1 << hw->port) & wol_nvm_bits))
931 return -EOPNOTSUPP;
932
933 /* only magic packet is supported */
934 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
935 return -EOPNOTSUPP;
936
937 /* is this a new value? */
938 if (pf->wol_en != !!wol->wolopts) {
939 pf->wol_en = !!wol->wolopts;
940 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
941 }
942
943 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000944}
945
946static int i40e_nway_reset(struct net_device *netdev)
947{
948 /* restart autonegotiation */
949 struct i40e_netdev_priv *np = netdev_priv(netdev);
950 struct i40e_pf *pf = np->vsi->back;
951 struct i40e_hw *hw = &pf->hw;
952 i40e_status ret = 0;
953
954 ret = i40e_aq_set_link_restart_an(hw, NULL);
955 if (ret) {
956 netdev_info(netdev, "link restart failed, aq_err=%d\n",
957 pf->hw.aq.asq_last_status);
958 return -EIO;
959 }
960
961 return 0;
962}
963
964static int i40e_set_phys_id(struct net_device *netdev,
965 enum ethtool_phys_id_state state)
966{
967 struct i40e_netdev_priv *np = netdev_priv(netdev);
968 struct i40e_pf *pf = np->vsi->back;
969 struct i40e_hw *hw = &pf->hw;
970 int blink_freq = 2;
971
972 switch (state) {
973 case ETHTOOL_ID_ACTIVE:
974 pf->led_status = i40e_led_get(hw);
975 return blink_freq;
976 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000977 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000978 break;
979 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000980 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000981 break;
982 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000983 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000984 break;
985 }
986
987 return 0;
988}
989
990/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
991 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
992 * 125us (8000 interrupts per second) == ITR(62)
993 */
994
995static int i40e_get_coalesce(struct net_device *netdev,
996 struct ethtool_coalesce *ec)
997{
998 struct i40e_netdev_priv *np = netdev_priv(netdev);
999 struct i40e_vsi *vsi = np->vsi;
1000
1001 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1002 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1003
1004 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
1005 ec->rx_coalesce_usecs = 1;
1006 else
1007 ec->rx_coalesce_usecs = vsi->rx_itr_setting;
1008
1009 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
1010 ec->tx_coalesce_usecs = 1;
1011 else
1012 ec->tx_coalesce_usecs = vsi->tx_itr_setting;
1013
1014 return 0;
1015}
1016
1017static int i40e_set_coalesce(struct net_device *netdev,
1018 struct ethtool_coalesce *ec)
1019{
1020 struct i40e_netdev_priv *np = netdev_priv(netdev);
1021 struct i40e_q_vector *q_vector;
1022 struct i40e_vsi *vsi = np->vsi;
1023 struct i40e_pf *pf = vsi->back;
1024 struct i40e_hw *hw = &pf->hw;
1025 u16 vector;
1026 int i;
1027
1028 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1029 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1030
1031 switch (ec->rx_coalesce_usecs) {
1032 case 0:
1033 vsi->rx_itr_setting = 0;
1034 break;
1035 case 1:
1036 vsi->rx_itr_setting = (I40E_ITR_DYNAMIC |
1037 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
1038 break;
1039 default:
1040 if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
1041 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)))
1042 return -EINVAL;
1043 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1044 break;
1045 }
1046
1047 switch (ec->tx_coalesce_usecs) {
1048 case 0:
1049 vsi->tx_itr_setting = 0;
1050 break;
1051 case 1:
1052 vsi->tx_itr_setting = (I40E_ITR_DYNAMIC |
1053 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
1054 break;
1055 default:
1056 if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
1057 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)))
1058 return -EINVAL;
1059 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1060 break;
1061 }
1062
1063 vector = vsi->base_vector;
Alexander Duyck493fb302013-09-28 07:01:44 +00001064 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1065 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001066 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1067 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1068 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1069 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1070 i40e_flush(hw);
1071 }
1072
1073 return 0;
1074}
1075
1076/**
1077 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1078 * @pf: pointer to the physical function struct
1079 * @cmd: ethtool rxnfc command
1080 *
1081 * Returns Success if the flow is supported, else Invalid Input.
1082 **/
1083static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1084{
1085 cmd->data = 0;
1086
1087 /* Report default options for RSS on i40e */
1088 switch (cmd->flow_type) {
1089 case TCP_V4_FLOW:
1090 case UDP_V4_FLOW:
1091 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1092 /* fall through to add IP fields */
1093 case SCTP_V4_FLOW:
1094 case AH_ESP_V4_FLOW:
1095 case AH_V4_FLOW:
1096 case ESP_V4_FLOW:
1097 case IPV4_FLOW:
1098 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1099 break;
1100 case TCP_V6_FLOW:
1101 case UDP_V6_FLOW:
1102 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1103 /* fall through to add IP fields */
1104 case SCTP_V6_FLOW:
1105 case AH_ESP_V6_FLOW:
1106 case AH_V6_FLOW:
1107 case ESP_V6_FLOW:
1108 case IPV6_FLOW:
1109 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1110 break;
1111 default:
1112 return -EINVAL;
1113 }
1114
1115 return 0;
1116}
1117
1118/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001119 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1120 * @pf: Pointer to the physical function struct
1121 * @cmd: The command to get or set Rx flow classification rules
1122 * @rule_locs: Array of used rule locations
1123 *
1124 * This function populates both the total and actual rule count of
1125 * the ethtool flow classification command
1126 *
1127 * Returns 0 on success or -EMSGSIZE if entry not found
1128 **/
1129static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1130 struct ethtool_rxnfc *cmd,
1131 u32 *rule_locs)
1132{
1133 struct i40e_fdir_filter *rule;
1134 struct hlist_node *node2;
1135 int cnt = 0;
1136
1137 /* report total rule count */
1138 cmd->data = pf->hw.fdir_shared_filter_count +
1139 pf->fdir_pf_filter_count;
1140
1141 hlist_for_each_entry_safe(rule, node2,
1142 &pf->fdir_filter_list, fdir_node) {
1143 if (cnt == cmd->rule_cnt)
1144 return -EMSGSIZE;
1145
1146 rule_locs[cnt] = rule->fd_id;
1147 cnt++;
1148 }
1149
1150 cmd->rule_cnt = cnt;
1151
1152 return 0;
1153}
1154
1155/**
1156 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1157 * @pf: Pointer to the physical function struct
1158 * @cmd: The command to get or set Rx flow classification rules
1159 *
1160 * This function looks up a filter based on the Rx flow classification
1161 * command and fills the flow spec info for it if found
1162 *
1163 * Returns 0 on success or -EINVAL if filter not found
1164 **/
1165static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1166 struct ethtool_rxnfc *cmd)
1167{
1168 struct ethtool_rx_flow_spec *fsp =
1169 (struct ethtool_rx_flow_spec *)&cmd->fs;
1170 struct i40e_fdir_filter *rule = NULL;
1171 struct hlist_node *node2;
1172
1173 /* report total rule count */
1174 cmd->data = pf->hw.fdir_shared_filter_count +
1175 pf->fdir_pf_filter_count;
1176
1177 hlist_for_each_entry_safe(rule, node2,
1178 &pf->fdir_filter_list, fdir_node) {
1179 if (fsp->location <= rule->fd_id)
1180 break;
1181 }
1182
1183 if (!rule || fsp->location != rule->fd_id)
1184 return -EINVAL;
1185
1186 fsp->flow_type = rule->flow_type;
1187 fsp->h_u.tcp_ip4_spec.psrc = rule->src_port;
1188 fsp->h_u.tcp_ip4_spec.pdst = rule->dst_port;
1189 fsp->h_u.tcp_ip4_spec.ip4src = rule->src_ip[0];
1190 fsp->h_u.tcp_ip4_spec.ip4dst = rule->dst_ip[0];
1191 fsp->ring_cookie = rule->q_index;
1192
1193 return 0;
1194}
1195
1196/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001197 * i40e_get_rxnfc - command to get RX flow classification rules
1198 * @netdev: network interface device structure
1199 * @cmd: ethtool rxnfc command
1200 *
1201 * Returns Success if the command is supported.
1202 **/
1203static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1204 u32 *rule_locs)
1205{
1206 struct i40e_netdev_priv *np = netdev_priv(netdev);
1207 struct i40e_vsi *vsi = np->vsi;
1208 struct i40e_pf *pf = vsi->back;
1209 int ret = -EOPNOTSUPP;
1210
1211 switch (cmd->cmd) {
1212 case ETHTOOL_GRXRINGS:
1213 cmd->data = vsi->alloc_queue_pairs;
1214 ret = 0;
1215 break;
1216 case ETHTOOL_GRXFH:
1217 ret = i40e_get_rss_hash_opts(pf, cmd);
1218 break;
1219 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001220 cmd->rule_cnt = pf->fdir_pf_active_filters;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001221 ret = 0;
1222 break;
1223 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001224 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001225 break;
1226 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001227 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1228 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001229 default:
1230 break;
1231 }
1232
1233 return ret;
1234}
1235
1236/**
1237 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1238 * @pf: pointer to the physical function struct
1239 * @cmd: ethtool rxnfc command
1240 *
1241 * Returns Success if the flow input set is supported.
1242 **/
1243static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1244{
1245 struct i40e_hw *hw = &pf->hw;
1246 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1247 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1248
1249 /* RSS does not support anything other than hashing
1250 * to queues on src and dst IPs and ports
1251 */
1252 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1253 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1254 return -EINVAL;
1255
1256 /* We need at least the IP SRC and DEST fields for hashing */
1257 if (!(nfc->data & RXH_IP_SRC) ||
1258 !(nfc->data & RXH_IP_DST))
1259 return -EINVAL;
1260
1261 switch (nfc->flow_type) {
1262 case TCP_V4_FLOW:
1263 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1264 case 0:
1265 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1266 break;
1267 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1268 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1269 break;
1270 default:
1271 return -EINVAL;
1272 }
1273 break;
1274 case TCP_V6_FLOW:
1275 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1276 case 0:
1277 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1278 break;
1279 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1280 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1281 break;
1282 default:
1283 return -EINVAL;
1284 }
1285 break;
1286 case UDP_V4_FLOW:
1287 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1288 case 0:
1289 hena &=
1290 ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
1291 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
1292 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1293 break;
1294 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1295 hena |=
1296 (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
1297 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
1298 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1299 break;
1300 default:
1301 return -EINVAL;
1302 }
1303 break;
1304 case UDP_V6_FLOW:
1305 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1306 case 0:
1307 hena &=
1308 ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
1309 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
1310 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1311 break;
1312 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1313 hena |=
1314 (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
1315 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
1316 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1317 break;
1318 default:
1319 return -EINVAL;
1320 }
1321 break;
1322 case AH_ESP_V4_FLOW:
1323 case AH_V4_FLOW:
1324 case ESP_V4_FLOW:
1325 case SCTP_V4_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_IPV4_OTHER);
1330 break;
1331 case AH_ESP_V6_FLOW:
1332 case AH_V6_FLOW:
1333 case ESP_V6_FLOW:
1334 case SCTP_V6_FLOW:
1335 if ((nfc->data & RXH_L4_B_0_1) ||
1336 (nfc->data & RXH_L4_B_2_3))
1337 return -EINVAL;
1338 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1339 break;
1340 case IPV4_FLOW:
1341 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1342 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1343 break;
1344 case IPV6_FLOW:
1345 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1346 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1347 break;
1348 default:
1349 return -EINVAL;
1350 }
1351
1352 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1353 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1354 i40e_flush(hw);
1355
1356 return 0;
1357}
1358
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001359/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001360 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1361 * @vsi: Pointer to the targeted VSI
1362 * @input: The filter to update or NULL to indicate deletion
1363 * @sw_idx: Software index to the filter
1364 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001365 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001366 * This function updates (or deletes) a Flow Director entry from
1367 * the hlist of the corresponding PF
1368 *
1369 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001370 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001371static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1372 struct i40e_fdir_filter *input,
1373 u16 sw_idx,
1374 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001375{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001376 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001377 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001378 struct hlist_node *node2;
1379 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001380
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001381 parent = NULL;
1382 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001383
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001384 hlist_for_each_entry_safe(rule, node2,
1385 &pf->fdir_filter_list, fdir_node) {
1386 /* hash found, or no matching entry */
1387 if (rule->fd_id >= sw_idx)
1388 break;
1389 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001390 }
1391
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001392 /* if there is an old rule occupying our place remove it */
1393 if (rule && (rule->fd_id == sw_idx)) {
1394 if (!input || (rule->fd_id != input->fd_id)) {
1395 cmd->fs.flow_type = rule->flow_type;
1396 err = i40e_add_del_fdir_ethtool(vsi, cmd, false);
1397 }
1398
1399 hlist_del(&rule->fdir_node);
1400 kfree(rule);
1401 pf->fdir_pf_active_filters--;
1402 }
1403
1404 /* If no input this was a delete, err should be 0 if a rule was
1405 * successfully found and removed from the list else -EINVAL
1406 */
1407 if (!input)
1408 return err;
1409
1410 /* initialize node and set software index */
1411 INIT_HLIST_NODE(&input->fdir_node);
1412
1413 /* add filter to the list */
1414 if (parent)
1415 hlist_add_after(&parent->fdir_node, &input->fdir_node);
1416 else
1417 hlist_add_head(&input->fdir_node,
1418 &pf->fdir_filter_list);
1419
1420 /* update counts */
1421 pf->fdir_pf_active_filters++;
1422
1423 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001424}
1425
1426/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001427 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
1428 * @vsi: Pointer to the targeted VSI
1429 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001430 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001431 * The function removes a Flow Director filter entry from the
1432 * hlist of the corresponding PF
1433 *
1434 * Returns 0 on success
1435 */
1436static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
1437 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001438{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001439 struct ethtool_rx_flow_spec *fsp =
1440 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001441 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001442 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001443
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001444 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001445
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001446 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001447}
1448
1449/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001450 * i40e_add_del_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001451 * @vsi: pointer to the targeted VSI
1452 * @cmd: command to get or set RX flow classification rules
1453 * @add: true adds a filter, false removes it
1454 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001455 * Add/Remove Flow Director filters for a specific flow spec based on their
1456 * protocol. Returns 0 if the filters were successfully added or removed.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001457 **/
1458static int i40e_add_del_fdir_ethtool(struct i40e_vsi *vsi,
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001459 struct ethtool_rxnfc *cmd, bool add)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001460{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001461 struct ethtool_rx_flow_spec *fsp;
1462 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001463 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001464 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001465
1466 if (!vsi)
1467 return -EINVAL;
1468
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001469 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001470 pf = vsi->back;
1471
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001472 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
1473 pf->hw.func_caps.fd_filters_guaranteed)) {
1474 return -EINVAL;
1475 }
1476
1477 if ((fsp->ring_cookie >= vsi->num_queue_pairs) && add)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001478 return -EINVAL;
1479
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001480 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001481
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001482 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001483 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001484
1485 input->fd_id = fsp->location;
1486
1487 input->q_index = fsp->ring_cookie;
1488 input->flex_off = 0;
1489 input->pctype = 0;
1490 input->dest_vsi = vsi->id;
1491 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
1492 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
1493 input->cnt_index = 0;
1494 input->flow_type = fsp->flow_type;
1495 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
1496 input->src_port = fsp->h_u.tcp_ip4_spec.psrc;
1497 input->dst_port = fsp->h_u.tcp_ip4_spec.pdst;
1498 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
1499 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
1500
1501 ret = i40e_add_del_fdir(vsi, input, add);
1502 if (ret) {
1503 kfree(input);
1504 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001505 }
1506
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001507 if (!ret && add)
1508 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
1509 else
1510 kfree(input);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001511
1512 return ret;
1513}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08001514
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001515/**
1516 * i40e_set_rxnfc - command to set RX flow classification rules
1517 * @netdev: network interface device structure
1518 * @cmd: ethtool rxnfc command
1519 *
1520 * Returns Success if the command is supported.
1521 **/
1522static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1523{
1524 struct i40e_netdev_priv *np = netdev_priv(netdev);
1525 struct i40e_vsi *vsi = np->vsi;
1526 struct i40e_pf *pf = vsi->back;
1527 int ret = -EOPNOTSUPP;
1528
1529 switch (cmd->cmd) {
1530 case ETHTOOL_SRXFH:
1531 ret = i40e_set_rss_hash_opt(pf, cmd);
1532 break;
1533 case ETHTOOL_SRXCLSRLINS:
1534 ret = i40e_add_del_fdir_ethtool(vsi, cmd, true);
1535 break;
1536 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001537 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001538 break;
1539 default:
1540 break;
1541 }
1542
1543 return ret;
1544}
1545
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001546/**
1547 * i40e_max_channels - get Max number of combined channels supported
1548 * @vsi: vsi pointer
1549 **/
1550static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
1551{
1552 /* TODO: This code assumes DCB and FD is disabled for now. */
1553 return vsi->alloc_queue_pairs;
1554}
1555
1556/**
1557 * i40e_get_channels - Get the current channels enabled and max supported etc.
1558 * @netdev: network interface device structure
1559 * @ch: ethtool channels structure
1560 *
1561 * We don't support separate tx and rx queues as channels. The other count
1562 * represents how many queues are being used for control. max_combined counts
1563 * how many queue pairs we can support. They may not be mapped 1 to 1 with
1564 * q_vectors since we support a lot more queue pairs than q_vectors.
1565 **/
1566static void i40e_get_channels(struct net_device *dev,
1567 struct ethtool_channels *ch)
1568{
1569 struct i40e_netdev_priv *np = netdev_priv(dev);
1570 struct i40e_vsi *vsi = np->vsi;
1571 struct i40e_pf *pf = vsi->back;
1572
1573 /* report maximum channels */
1574 ch->max_combined = i40e_max_channels(vsi);
1575
1576 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08001577 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001578 ch->max_other = ch->other_count;
1579
1580 /* Note: This code assumes DCB is disabled for now. */
1581 ch->combined_count = vsi->num_queue_pairs;
1582}
1583
1584/**
1585 * i40e_set_channels - Set the new channels count.
1586 * @netdev: network interface device structure
1587 * @ch: ethtool channels structure
1588 *
1589 * The new channels count may not be the same as requested by the user
1590 * since it gets rounded down to a power of 2 value.
1591 **/
1592static int i40e_set_channels(struct net_device *dev,
1593 struct ethtool_channels *ch)
1594{
1595 struct i40e_netdev_priv *np = netdev_priv(dev);
1596 unsigned int count = ch->combined_count;
1597 struct i40e_vsi *vsi = np->vsi;
1598 struct i40e_pf *pf = vsi->back;
1599 int new_count;
1600
1601 /* We do not support setting channels for any other VSI at present */
1602 if (vsi->type != I40E_VSI_MAIN)
1603 return -EINVAL;
1604
1605 /* verify they are not requesting separate vectors */
1606 if (!count || ch->rx_count || ch->tx_count)
1607 return -EINVAL;
1608
1609 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08001610 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001611 return -EINVAL;
1612
1613 /* verify the number of channels does not exceed hardware limits */
1614 if (count > i40e_max_channels(vsi))
1615 return -EINVAL;
1616
1617 /* update feature limits from largest to smallest supported values */
1618 /* TODO: Flow director limit, DCB etc */
1619
1620 /* cap RSS limit */
1621 if (count > pf->rss_size_max)
1622 count = pf->rss_size_max;
1623
1624 /* use rss_reconfig to rebuild with new queue count and update traffic
1625 * class queue mapping
1626 */
1627 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00001628 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001629 return 0;
1630 else
1631 return -EINVAL;
1632}
1633
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001634static const struct ethtool_ops i40e_ethtool_ops = {
1635 .get_settings = i40e_get_settings,
1636 .get_drvinfo = i40e_get_drvinfo,
1637 .get_regs_len = i40e_get_regs_len,
1638 .get_regs = i40e_get_regs,
1639 .nway_reset = i40e_nway_reset,
1640 .get_link = ethtool_op_get_link,
1641 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001642 .set_wol = i40e_set_wol,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001643 .get_eeprom_len = i40e_get_eeprom_len,
1644 .get_eeprom = i40e_get_eeprom,
1645 .get_ringparam = i40e_get_ringparam,
1646 .set_ringparam = i40e_set_ringparam,
1647 .get_pauseparam = i40e_get_pauseparam,
1648 .get_msglevel = i40e_get_msglevel,
1649 .set_msglevel = i40e_set_msglevel,
1650 .get_rxnfc = i40e_get_rxnfc,
1651 .set_rxnfc = i40e_set_rxnfc,
1652 .self_test = i40e_diag_test,
1653 .get_strings = i40e_get_strings,
1654 .set_phys_id = i40e_set_phys_id,
1655 .get_sset_count = i40e_get_sset_count,
1656 .get_ethtool_stats = i40e_get_ethtool_stats,
1657 .get_coalesce = i40e_get_coalesce,
1658 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001659 .get_channels = i40e_get_channels,
1660 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001661 .get_ts_info = i40e_get_ts_info,
1662};
1663
1664void i40e_set_ethtool_ops(struct net_device *netdev)
1665{
1666 SET_ETHTOOL_OPS(netdev, &i40e_ethtool_ops);
1667}