blob: 8d46c6ee4cdd95e830e4f562788e3015b80a5073 [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),
90 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
91 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
92 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
93 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
94 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
95 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
96 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
97 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
98 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
99 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
100 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
101 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
102 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
103 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
104 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
105 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
106 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
107 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
108 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
109 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
110 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
111 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
112 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
113 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000114 I40E_PF_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
115 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000116};
117
118#define I40E_QUEUE_STATS_LEN(n) \
119 ((((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs + \
120 ((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs) * 2)
121#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
122#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
123#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
124 I40E_QUEUE_STATS_LEN((n)))
125#define I40E_PFC_STATS_LEN ( \
126 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
127 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
128 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
129 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
130 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
131 / sizeof(u64))
132#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
133 I40E_PFC_STATS_LEN + \
134 I40E_VSI_STATS_LEN((n)))
135
136enum i40e_ethtool_test_id {
137 I40E_ETH_TEST_REG = 0,
138 I40E_ETH_TEST_EEPROM,
139 I40E_ETH_TEST_INTR,
140 I40E_ETH_TEST_LOOPBACK,
141 I40E_ETH_TEST_LINK,
142};
143
144static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
145 "Register test (offline)",
146 "Eeprom test (offline)",
147 "Interrupt test (offline)",
148 "Loopback test (offline)",
149 "Link test (on/offline)"
150};
151
152#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
153
154/**
155 * i40e_get_settings - Get Link Speed and Duplex settings
156 * @netdev: network interface device structure
157 * @ecmd: ethtool command
158 *
159 * Reports speed/duplex settings based on media_type
160 **/
161static int i40e_get_settings(struct net_device *netdev,
162 struct ethtool_cmd *ecmd)
163{
164 struct i40e_netdev_priv *np = netdev_priv(netdev);
165 struct i40e_pf *pf = np->vsi->back;
166 struct i40e_hw *hw = &pf->hw;
167 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
168 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
169 u32 link_speed = hw_link_info->link_speed;
170
171 /* hardware is either in 40G mode or 10G mode
172 * NOTE: this section initializes supported and advertising
173 */
174 switch (hw_link_info->phy_type) {
175 case I40E_PHY_TYPE_40GBASE_CR4:
176 case I40E_PHY_TYPE_40GBASE_CR4_CU:
177 ecmd->supported = SUPPORTED_40000baseCR4_Full;
178 ecmd->advertising = ADVERTISED_40000baseCR4_Full;
179 break;
180 case I40E_PHY_TYPE_40GBASE_KR4:
181 ecmd->supported = SUPPORTED_40000baseKR4_Full;
182 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
183 break;
184 case I40E_PHY_TYPE_40GBASE_SR4:
185 ecmd->supported = SUPPORTED_40000baseSR4_Full;
186 ecmd->advertising = ADVERTISED_40000baseSR4_Full;
187 break;
188 case I40E_PHY_TYPE_40GBASE_LR4:
189 ecmd->supported = SUPPORTED_40000baseLR4_Full;
190 ecmd->advertising = ADVERTISED_40000baseLR4_Full;
191 break;
192 case I40E_PHY_TYPE_10GBASE_KX4:
193 ecmd->supported = SUPPORTED_10000baseKX4_Full;
194 ecmd->advertising = ADVERTISED_10000baseKX4_Full;
195 break;
196 case I40E_PHY_TYPE_10GBASE_KR:
197 ecmd->supported = SUPPORTED_10000baseKR_Full;
198 ecmd->advertising = ADVERTISED_10000baseKR_Full;
199 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000200 default:
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000201 if (i40e_is_40G_device(hw->device_id)) {
202 ecmd->supported = SUPPORTED_40000baseSR4_Full;
203 ecmd->advertising = ADVERTISED_40000baseSR4_Full;
204 } else {
205 ecmd->supported = SUPPORTED_10000baseT_Full;
206 ecmd->advertising = ADVERTISED_10000baseT_Full;
207 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000208 break;
209 }
210
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000211 ecmd->supported |= SUPPORTED_Autoneg;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000212 ecmd->advertising |= ADVERTISED_Autoneg;
213 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
214 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000215
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000216 switch (hw->phy.media_type) {
217 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000218 ecmd->supported |= SUPPORTED_Backplane;
219 ecmd->advertising |= ADVERTISED_Backplane;
220 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000221 break;
222 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000223 ecmd->supported |= SUPPORTED_TP;
224 ecmd->advertising |= ADVERTISED_TP;
225 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000226 break;
227 case I40E_MEDIA_TYPE_DA:
228 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000229 ecmd->supported |= SUPPORTED_FIBRE;
230 ecmd->advertising |= ADVERTISED_FIBRE;
231 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000232 break;
233 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000234 ecmd->supported |= SUPPORTED_FIBRE;
235 ecmd->advertising |= ADVERTISED_FIBRE;
236 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000237 break;
238 case I40E_MEDIA_TYPE_UNKNOWN:
239 default:
240 ecmd->port = PORT_OTHER;
241 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000242 }
243
244 ecmd->transceiver = XCVR_EXTERNAL;
245
246 if (link_up) {
247 switch (link_speed) {
248 case I40E_LINK_SPEED_40GB:
249 /* need a SPEED_40000 in ethtool.h */
250 ethtool_cmd_speed_set(ecmd, 40000);
251 break;
252 case I40E_LINK_SPEED_10GB:
253 ethtool_cmd_speed_set(ecmd, SPEED_10000);
254 break;
255 default:
256 break;
257 }
258 ecmd->duplex = DUPLEX_FULL;
259 } else {
260 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
261 ecmd->duplex = DUPLEX_UNKNOWN;
262 }
263
264 return 0;
265}
266
267/**
268 * i40e_get_pauseparam - Get Flow Control status
269 * Return tx/rx-pause status
270 **/
271static void i40e_get_pauseparam(struct net_device *netdev,
272 struct ethtool_pauseparam *pause)
273{
274 struct i40e_netdev_priv *np = netdev_priv(netdev);
275 struct i40e_pf *pf = np->vsi->back;
276 struct i40e_hw *hw = &pf->hw;
277 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
278
279 pause->autoneg =
280 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
281 AUTONEG_ENABLE : AUTONEG_DISABLE);
282
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000283 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000284 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000285 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000286 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000287 } else if (hw->fc.current_mode == I40E_FC_FULL) {
288 pause->rx_pause = 1;
289 pause->tx_pause = 1;
290 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000291}
292
293static u32 i40e_get_msglevel(struct net_device *netdev)
294{
295 struct i40e_netdev_priv *np = netdev_priv(netdev);
296 struct i40e_pf *pf = np->vsi->back;
297
298 return pf->msg_enable;
299}
300
301static void i40e_set_msglevel(struct net_device *netdev, u32 data)
302{
303 struct i40e_netdev_priv *np = netdev_priv(netdev);
304 struct i40e_pf *pf = np->vsi->back;
305
306 if (I40E_DEBUG_USER & data)
307 pf->hw.debug_mask = data;
308 pf->msg_enable = data;
309}
310
311static int i40e_get_regs_len(struct net_device *netdev)
312{
313 int reg_count = 0;
314 int i;
315
316 for (i = 0; i40e_reg_list[i].offset != 0; i++)
317 reg_count += i40e_reg_list[i].elements;
318
319 return reg_count * sizeof(u32);
320}
321
322static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
323 void *p)
324{
325 struct i40e_netdev_priv *np = netdev_priv(netdev);
326 struct i40e_pf *pf = np->vsi->back;
327 struct i40e_hw *hw = &pf->hw;
328 u32 *reg_buf = p;
329 int i, j, ri;
330 u32 reg;
331
332 /* Tell ethtool which driver-version-specific regs output we have.
333 *
334 * At some point, if we have ethtool doing special formatting of
335 * this data, it will rely on this version number to know how to
336 * interpret things. Hence, this needs to be updated if/when the
337 * diags register table is changed.
338 */
339 regs->version = 1;
340
341 /* loop through the diags reg table for what to print */
342 ri = 0;
343 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
344 for (j = 0; j < i40e_reg_list[i].elements; j++) {
345 reg = i40e_reg_list[i].offset
346 + (j * i40e_reg_list[i].stride);
347 reg_buf[ri++] = rd32(hw, reg);
348 }
349 }
350
351}
352
353static int i40e_get_eeprom(struct net_device *netdev,
354 struct ethtool_eeprom *eeprom, u8 *bytes)
355{
356 struct i40e_netdev_priv *np = netdev_priv(netdev);
357 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000358 struct i40e_pf *pf = np->vsi->back;
359 int ret_val = 0, len;
360 u8 *eeprom_buff;
361 u16 i, sectors;
362 bool last;
363#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000364 if (eeprom->len == 0)
365 return -EINVAL;
366
367 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
368
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000369 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000370 if (!eeprom_buff)
371 return -ENOMEM;
372
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000373 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
374 if (ret_val) {
375 dev_info(&pf->pdev->dev,
376 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
377 ret_val, hw->aq.asq_last_status);
378 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000379 }
380
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000381 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
382 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
383 len = I40E_NVM_SECTOR_SIZE;
384 last = false;
385 for (i = 0; i < sectors; i++) {
386 if (i == (sectors - 1)) {
387 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
388 last = true;
389 }
390 ret_val = i40e_aq_read_nvm(hw, 0x0,
391 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
392 len,
393 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
394 last, NULL);
395 if (ret_val) {
396 dev_info(&pf->pdev->dev,
397 "read NVM failed err=%d status=0x%x\n",
398 ret_val, hw->aq.asq_last_status);
399 goto release_nvm;
400 }
401 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000402
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000403release_nvm:
404 i40e_release_nvm(hw);
405 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
406free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000407 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000408 return ret_val;
409}
410
411static int i40e_get_eeprom_len(struct net_device *netdev)
412{
413 struct i40e_netdev_priv *np = netdev_priv(netdev);
414 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000415 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000416
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000417 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
418 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
419 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
420 /* register returns value in power of 2, 64Kbyte chunks. */
421 val = (64 * 1024) * (1 << val);
422 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000423}
424
425static void i40e_get_drvinfo(struct net_device *netdev,
426 struct ethtool_drvinfo *drvinfo)
427{
428 struct i40e_netdev_priv *np = netdev_priv(netdev);
429 struct i40e_vsi *vsi = np->vsi;
430 struct i40e_pf *pf = vsi->back;
431
432 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
433 strlcpy(drvinfo->version, i40e_driver_version_str,
434 sizeof(drvinfo->version));
435 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
436 sizeof(drvinfo->fw_version));
437 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
438 sizeof(drvinfo->bus_info));
439}
440
441static void i40e_get_ringparam(struct net_device *netdev,
442 struct ethtool_ringparam *ring)
443{
444 struct i40e_netdev_priv *np = netdev_priv(netdev);
445 struct i40e_pf *pf = np->vsi->back;
446 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
447
448 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
449 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
450 ring->rx_mini_max_pending = 0;
451 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +0000452 ring->rx_pending = vsi->rx_rings[0]->count;
453 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000454 ring->rx_mini_pending = 0;
455 ring->rx_jumbo_pending = 0;
456}
457
458static int i40e_set_ringparam(struct net_device *netdev,
459 struct ethtool_ringparam *ring)
460{
461 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
462 struct i40e_netdev_priv *np = netdev_priv(netdev);
463 struct i40e_vsi *vsi = np->vsi;
464 struct i40e_pf *pf = vsi->back;
465 u32 new_rx_count, new_tx_count;
466 int i, err = 0;
467
468 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
469 return -EINVAL;
470
Shannon Nelson1fa18372013-11-20 10:03:08 +0000471 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
472 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
473 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
474 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
475 netdev_info(netdev,
476 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
477 ring->tx_pending, ring->rx_pending,
478 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
479 return -EINVAL;
480 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000481
Shannon Nelson1fa18372013-11-20 10:03:08 +0000482 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
483 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000484
485 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000486 if ((new_tx_count == vsi->tx_rings[0]->count) &&
487 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000488 return 0;
489
490 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
491 usleep_range(1000, 2000);
492
493 if (!netif_running(vsi->netdev)) {
494 /* simple case - set for the next time the netdev is started */
495 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000496 vsi->tx_rings[i]->count = new_tx_count;
497 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000498 }
499 goto done;
500 }
501
502 /* We can't just free everything and then setup again,
503 * because the ISRs in MSI-X mode get passed pointers
504 * to the Tx and Rx ring structs.
505 */
506
507 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000508 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000509 netdev_info(netdev,
510 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000511 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000512 tx_rings = kcalloc(vsi->alloc_queue_pairs,
513 sizeof(struct i40e_ring), GFP_KERNEL);
514 if (!tx_rings) {
515 err = -ENOMEM;
516 goto done;
517 }
518
519 for (i = 0; i < vsi->num_queue_pairs; i++) {
520 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000521 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000522 tx_rings[i].count = new_tx_count;
523 err = i40e_setup_tx_descriptors(&tx_rings[i]);
524 if (err) {
525 while (i) {
526 i--;
527 i40e_free_tx_resources(&tx_rings[i]);
528 }
529 kfree(tx_rings);
530 tx_rings = NULL;
531
532 goto done;
533 }
534 }
535 }
536
537 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000538 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000539 netdev_info(netdev,
540 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000541 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000542 rx_rings = kcalloc(vsi->alloc_queue_pairs,
543 sizeof(struct i40e_ring), GFP_KERNEL);
544 if (!rx_rings) {
545 err = -ENOMEM;
546 goto free_tx;
547 }
548
549 for (i = 0; i < vsi->num_queue_pairs; i++) {
550 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000551 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000552 rx_rings[i].count = new_rx_count;
553 err = i40e_setup_rx_descriptors(&rx_rings[i]);
554 if (err) {
555 while (i) {
556 i--;
557 i40e_free_rx_resources(&rx_rings[i]);
558 }
559 kfree(rx_rings);
560 rx_rings = NULL;
561
562 goto free_tx;
563 }
564 }
565 }
566
567 /* Bring interface down, copy in the new ring info,
568 * then restore the interface
569 */
570 i40e_down(vsi);
571
572 if (tx_rings) {
573 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000574 i40e_free_tx_resources(vsi->tx_rings[i]);
575 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000576 }
577 kfree(tx_rings);
578 tx_rings = NULL;
579 }
580
581 if (rx_rings) {
582 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000583 i40e_free_rx_resources(vsi->rx_rings[i]);
584 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000585 }
586 kfree(rx_rings);
587 rx_rings = NULL;
588 }
589
590 i40e_up(vsi);
591
592free_tx:
593 /* error cleanup if the Rx allocations failed after getting Tx */
594 if (tx_rings) {
595 for (i = 0; i < vsi->num_queue_pairs; i++)
596 i40e_free_tx_resources(&tx_rings[i]);
597 kfree(tx_rings);
598 tx_rings = NULL;
599 }
600
601done:
602 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
603
604 return err;
605}
606
607static int i40e_get_sset_count(struct net_device *netdev, int sset)
608{
609 struct i40e_netdev_priv *np = netdev_priv(netdev);
610 struct i40e_vsi *vsi = np->vsi;
611 struct i40e_pf *pf = vsi->back;
612
613 switch (sset) {
614 case ETH_SS_TEST:
615 return I40E_TEST_LEN;
616 case ETH_SS_STATS:
617 if (vsi == pf->vsi[pf->lan_vsi])
618 return I40E_PF_STATS_LEN(netdev);
619 else
620 return I40E_VSI_STATS_LEN(netdev);
621 default:
622 return -EOPNOTSUPP;
623 }
624}
625
626static void i40e_get_ethtool_stats(struct net_device *netdev,
627 struct ethtool_stats *stats, u64 *data)
628{
629 struct i40e_netdev_priv *np = netdev_priv(netdev);
630 struct i40e_vsi *vsi = np->vsi;
631 struct i40e_pf *pf = vsi->back;
632 int i = 0;
633 char *p;
634 int j;
635 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000636 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000637
638 i40e_update_stats(vsi);
639
640 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
641 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
642 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
643 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
644 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000645 rcu_read_lock();
Alexander Duycka114d0a2013-09-28 06:00:43 +0000646 for (j = 0; j < vsi->num_queue_pairs; j++, i += 4) {
Alexander Duyck980e9b12013-09-28 06:01:03 +0000647 struct i40e_ring *tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
648 struct i40e_ring *rx_ring;
649
650 if (!tx_ring)
651 continue;
652
653 /* process Tx ring statistics */
654 do {
655 start = u64_stats_fetch_begin_bh(&tx_ring->syncp);
656 data[i] = tx_ring->stats.packets;
657 data[i + 1] = tx_ring->stats.bytes;
658 } while (u64_stats_fetch_retry_bh(&tx_ring->syncp, start));
659
660 /* Rx ring is the 2nd half of the queue pair */
661 rx_ring = &tx_ring[1];
662 do {
663 start = u64_stats_fetch_begin_bh(&rx_ring->syncp);
664 data[i + 2] = rx_ring->stats.packets;
665 data[i + 3] = rx_ring->stats.bytes;
666 } while (u64_stats_fetch_retry_bh(&rx_ring->syncp, start));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000667 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000668 rcu_read_unlock();
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000669 if (vsi == pf->vsi[pf->lan_vsi]) {
670 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
671 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
672 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
673 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
674 }
675 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
676 data[i++] = pf->stats.priority_xon_tx[j];
677 data[i++] = pf->stats.priority_xoff_tx[j];
678 }
679 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
680 data[i++] = pf->stats.priority_xon_rx[j];
681 data[i++] = pf->stats.priority_xoff_rx[j];
682 }
683 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
684 data[i++] = pf->stats.priority_xon_2_xoff[j];
685 }
686}
687
688static void i40e_get_strings(struct net_device *netdev, u32 stringset,
689 u8 *data)
690{
691 struct i40e_netdev_priv *np = netdev_priv(netdev);
692 struct i40e_vsi *vsi = np->vsi;
693 struct i40e_pf *pf = vsi->back;
694 char *p = (char *)data;
695 int i;
696
697 switch (stringset) {
698 case ETH_SS_TEST:
699 for (i = 0; i < I40E_TEST_LEN; i++) {
700 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
701 data += ETH_GSTRING_LEN;
702 }
703 break;
704 case ETH_SS_STATS:
705 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
706 snprintf(p, ETH_GSTRING_LEN, "%s",
707 i40e_gstrings_net_stats[i].stat_string);
708 p += ETH_GSTRING_LEN;
709 }
710 for (i = 0; i < vsi->num_queue_pairs; i++) {
711 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
712 p += ETH_GSTRING_LEN;
713 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
714 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000715 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
716 p += ETH_GSTRING_LEN;
717 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
718 p += ETH_GSTRING_LEN;
719 }
720 if (vsi == pf->vsi[pf->lan_vsi]) {
721 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
722 snprintf(p, ETH_GSTRING_LEN, "port.%s",
723 i40e_gstrings_stats[i].stat_string);
724 p += ETH_GSTRING_LEN;
725 }
726 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
727 snprintf(p, ETH_GSTRING_LEN,
728 "port.tx_priority_%u_xon", i);
729 p += ETH_GSTRING_LEN;
730 snprintf(p, ETH_GSTRING_LEN,
731 "port.tx_priority_%u_xoff", i);
732 p += ETH_GSTRING_LEN;
733 }
734 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
735 snprintf(p, ETH_GSTRING_LEN,
736 "port.rx_priority_%u_xon", i);
737 p += ETH_GSTRING_LEN;
738 snprintf(p, ETH_GSTRING_LEN,
739 "port.rx_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_2_xoff", i);
745 p += ETH_GSTRING_LEN;
746 }
747 }
748 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
749 break;
750 }
751}
752
753static int i40e_get_ts_info(struct net_device *dev,
754 struct ethtool_ts_info *info)
755{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000756 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
757
758 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
759 SOF_TIMESTAMPING_RX_SOFTWARE |
760 SOF_TIMESTAMPING_SOFTWARE |
761 SOF_TIMESTAMPING_TX_HARDWARE |
762 SOF_TIMESTAMPING_RX_HARDWARE |
763 SOF_TIMESTAMPING_RAW_HARDWARE;
764
765 if (pf->ptp_clock)
766 info->phc_index = ptp_clock_index(pf->ptp_clock);
767 else
768 info->phc_index = -1;
769
770 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
771
772 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
773 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
774 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
775 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
776 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
777 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
778 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
779 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
780 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
781 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
782 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
783 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
784
785 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000786}
787
Shannon Nelson7b086392013-11-20 10:02:59 +0000788static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000789{
Shannon Nelson7b086392013-11-20 10:02:59 +0000790 struct i40e_netdev_priv *np = netdev_priv(netdev);
791 struct i40e_pf *pf = np->vsi->back;
792
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000793 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000794 if (i40e_get_link_status(&pf->hw))
795 *data = 0;
796 else
797 *data = 1;
798
799 return *data;
800}
801
Shannon Nelson7b086392013-11-20 10:02:59 +0000802static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000803{
Shannon Nelson7b086392013-11-20 10:02:59 +0000804 struct i40e_netdev_priv *np = netdev_priv(netdev);
805 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000806
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000807 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +0000808 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000809
Shannon Nelson7b086392013-11-20 10:02:59 +0000810 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000811}
812
Shannon Nelson7b086392013-11-20 10:02:59 +0000813static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000814{
Shannon Nelson7b086392013-11-20 10:02:59 +0000815 struct i40e_netdev_priv *np = netdev_priv(netdev);
816 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000817
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000818 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +0000819 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000820
Shannon Nelson7b086392013-11-20 10:02:59 +0000821 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000822}
823
Shannon Nelson7b086392013-11-20 10:02:59 +0000824static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000825{
Shannon Nelson7b086392013-11-20 10:02:59 +0000826 struct i40e_netdev_priv *np = netdev_priv(netdev);
827 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000828 u16 swc_old = pf->sw_int_count;
829
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000830 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000831 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
832 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
833 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
834 usleep_range(1000, 2000);
835 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000836
837 return *data;
838}
839
Shannon Nelson7b086392013-11-20 10:02:59 +0000840static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000841{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000842 struct i40e_netdev_priv *np = netdev_priv(netdev);
843 struct i40e_pf *pf = np->vsi->back;
844
845 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000846 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000847
848 return *data;
849}
850
851static void i40e_diag_test(struct net_device *netdev,
852 struct ethtool_test *eth_test, u64 *data)
853{
854 struct i40e_netdev_priv *np = netdev_priv(netdev);
855 struct i40e_pf *pf = np->vsi->back;
856
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000857 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
858 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000859 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000860
Shannon Nelsonf551b432013-11-26 10:49:12 +0000861 set_bit(__I40E_TESTING, &pf->state);
862
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000863 /* Link test performed before hardware reset
864 * so autoneg doesn't interfere with test result
865 */
Shannon Nelson7b086392013-11-20 10:02:59 +0000866 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000867 eth_test->flags |= ETH_TEST_FL_FAILED;
868
Shannon Nelson7b086392013-11-20 10:02:59 +0000869 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000870 eth_test->flags |= ETH_TEST_FL_FAILED;
871
Shannon Nelson7b086392013-11-20 10:02:59 +0000872 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000873 eth_test->flags |= ETH_TEST_FL_FAILED;
874
Shannon Nelson7b086392013-11-20 10:02:59 +0000875 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000876 eth_test->flags |= ETH_TEST_FL_FAILED;
877
Shannon Nelsonf551b432013-11-26 10:49:12 +0000878 /* run reg test last, a reset is required after it */
879 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
880 eth_test->flags |= ETH_TEST_FL_FAILED;
881
882 clear_bit(__I40E_TESTING, &pf->state);
883 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000884 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000885 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000886 netif_info(pf, drv, netdev, "online testing starting\n");
887
Shannon Nelson7b086392013-11-20 10:02:59 +0000888 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000889 eth_test->flags |= ETH_TEST_FL_FAILED;
890
891 /* Offline only tests, not run in online; pass by default */
892 data[I40E_ETH_TEST_REG] = 0;
893 data[I40E_ETH_TEST_EEPROM] = 0;
894 data[I40E_ETH_TEST_INTR] = 0;
895 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000896 }
Shannon Nelsonc140c172013-11-20 10:02:58 +0000897
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000898 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000899}
900
901static void i40e_get_wol(struct net_device *netdev,
902 struct ethtool_wolinfo *wol)
903{
Shannon Nelson8e2773a2013-11-28 06:39:22 +0000904 struct i40e_netdev_priv *np = netdev_priv(netdev);
905 struct i40e_pf *pf = np->vsi->back;
906 struct i40e_hw *hw = &pf->hw;
907 u16 wol_nvm_bits;
908
909 /* NVM bit on means WoL disabled for the port */
910 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
911 if ((1 << hw->port) & wol_nvm_bits) {
912 wol->supported = 0;
913 wol->wolopts = 0;
914 } else {
915 wol->supported = WAKE_MAGIC;
916 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
917 }
918}
919
920static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
921{
922 struct i40e_netdev_priv *np = netdev_priv(netdev);
923 struct i40e_pf *pf = np->vsi->back;
924 struct i40e_hw *hw = &pf->hw;
925 u16 wol_nvm_bits;
926
927 /* NVM bit on means WoL disabled for the port */
928 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
929 if (((1 << hw->port) & wol_nvm_bits))
930 return -EOPNOTSUPP;
931
932 /* only magic packet is supported */
933 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
934 return -EOPNOTSUPP;
935
936 /* is this a new value? */
937 if (pf->wol_en != !!wol->wolopts) {
938 pf->wol_en = !!wol->wolopts;
939 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
940 }
941
942 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000943}
944
945static int i40e_nway_reset(struct net_device *netdev)
946{
947 /* restart autonegotiation */
948 struct i40e_netdev_priv *np = netdev_priv(netdev);
949 struct i40e_pf *pf = np->vsi->back;
950 struct i40e_hw *hw = &pf->hw;
951 i40e_status ret = 0;
952
953 ret = i40e_aq_set_link_restart_an(hw, NULL);
954 if (ret) {
955 netdev_info(netdev, "link restart failed, aq_err=%d\n",
956 pf->hw.aq.asq_last_status);
957 return -EIO;
958 }
959
960 return 0;
961}
962
963static int i40e_set_phys_id(struct net_device *netdev,
964 enum ethtool_phys_id_state state)
965{
966 struct i40e_netdev_priv *np = netdev_priv(netdev);
967 struct i40e_pf *pf = np->vsi->back;
968 struct i40e_hw *hw = &pf->hw;
969 int blink_freq = 2;
970
971 switch (state) {
972 case ETHTOOL_ID_ACTIVE:
973 pf->led_status = i40e_led_get(hw);
974 return blink_freq;
975 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000976 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000977 break;
978 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000979 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000980 break;
981 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000982 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000983 break;
984 }
985
986 return 0;
987}
988
989/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
990 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
991 * 125us (8000 interrupts per second) == ITR(62)
992 */
993
994static int i40e_get_coalesce(struct net_device *netdev,
995 struct ethtool_coalesce *ec)
996{
997 struct i40e_netdev_priv *np = netdev_priv(netdev);
998 struct i40e_vsi *vsi = np->vsi;
999
1000 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1001 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1002
1003 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
1004 ec->rx_coalesce_usecs = 1;
1005 else
1006 ec->rx_coalesce_usecs = vsi->rx_itr_setting;
1007
1008 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
1009 ec->tx_coalesce_usecs = 1;
1010 else
1011 ec->tx_coalesce_usecs = vsi->tx_itr_setting;
1012
1013 return 0;
1014}
1015
1016static int i40e_set_coalesce(struct net_device *netdev,
1017 struct ethtool_coalesce *ec)
1018{
1019 struct i40e_netdev_priv *np = netdev_priv(netdev);
1020 struct i40e_q_vector *q_vector;
1021 struct i40e_vsi *vsi = np->vsi;
1022 struct i40e_pf *pf = vsi->back;
1023 struct i40e_hw *hw = &pf->hw;
1024 u16 vector;
1025 int i;
1026
1027 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1028 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1029
1030 switch (ec->rx_coalesce_usecs) {
1031 case 0:
1032 vsi->rx_itr_setting = 0;
1033 break;
1034 case 1:
1035 vsi->rx_itr_setting = (I40E_ITR_DYNAMIC |
1036 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
1037 break;
1038 default:
1039 if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
1040 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)))
1041 return -EINVAL;
1042 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1043 break;
1044 }
1045
1046 switch (ec->tx_coalesce_usecs) {
1047 case 0:
1048 vsi->tx_itr_setting = 0;
1049 break;
1050 case 1:
1051 vsi->tx_itr_setting = (I40E_ITR_DYNAMIC |
1052 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
1053 break;
1054 default:
1055 if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
1056 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)))
1057 return -EINVAL;
1058 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1059 break;
1060 }
1061
1062 vector = vsi->base_vector;
Alexander Duyck493fb302013-09-28 07:01:44 +00001063 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1064 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001065 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1066 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1067 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1068 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1069 i40e_flush(hw);
1070 }
1071
1072 return 0;
1073}
1074
1075/**
1076 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1077 * @pf: pointer to the physical function struct
1078 * @cmd: ethtool rxnfc command
1079 *
1080 * Returns Success if the flow is supported, else Invalid Input.
1081 **/
1082static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1083{
1084 cmd->data = 0;
1085
1086 /* Report default options for RSS on i40e */
1087 switch (cmd->flow_type) {
1088 case TCP_V4_FLOW:
1089 case UDP_V4_FLOW:
1090 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1091 /* fall through to add IP fields */
1092 case SCTP_V4_FLOW:
1093 case AH_ESP_V4_FLOW:
1094 case AH_V4_FLOW:
1095 case ESP_V4_FLOW:
1096 case IPV4_FLOW:
1097 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1098 break;
1099 case TCP_V6_FLOW:
1100 case UDP_V6_FLOW:
1101 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1102 /* fall through to add IP fields */
1103 case SCTP_V6_FLOW:
1104 case AH_ESP_V6_FLOW:
1105 case AH_V6_FLOW:
1106 case ESP_V6_FLOW:
1107 case IPV6_FLOW:
1108 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1109 break;
1110 default:
1111 return -EINVAL;
1112 }
1113
1114 return 0;
1115}
1116
1117/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001118 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1119 * @pf: Pointer to the physical function struct
1120 * @cmd: The command to get or set Rx flow classification rules
1121 * @rule_locs: Array of used rule locations
1122 *
1123 * This function populates both the total and actual rule count of
1124 * the ethtool flow classification command
1125 *
1126 * Returns 0 on success or -EMSGSIZE if entry not found
1127 **/
1128static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1129 struct ethtool_rxnfc *cmd,
1130 u32 *rule_locs)
1131{
1132 struct i40e_fdir_filter *rule;
1133 struct hlist_node *node2;
1134 int cnt = 0;
1135
1136 /* report total rule count */
1137 cmd->data = pf->hw.fdir_shared_filter_count +
1138 pf->fdir_pf_filter_count;
1139
1140 hlist_for_each_entry_safe(rule, node2,
1141 &pf->fdir_filter_list, fdir_node) {
1142 if (cnt == cmd->rule_cnt)
1143 return -EMSGSIZE;
1144
1145 rule_locs[cnt] = rule->fd_id;
1146 cnt++;
1147 }
1148
1149 cmd->rule_cnt = cnt;
1150
1151 return 0;
1152}
1153
1154/**
1155 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1156 * @pf: Pointer to the physical function struct
1157 * @cmd: The command to get or set Rx flow classification rules
1158 *
1159 * This function looks up a filter based on the Rx flow classification
1160 * command and fills the flow spec info for it if found
1161 *
1162 * Returns 0 on success or -EINVAL if filter not found
1163 **/
1164static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1165 struct ethtool_rxnfc *cmd)
1166{
1167 struct ethtool_rx_flow_spec *fsp =
1168 (struct ethtool_rx_flow_spec *)&cmd->fs;
1169 struct i40e_fdir_filter *rule = NULL;
1170 struct hlist_node *node2;
1171
1172 /* report total rule count */
1173 cmd->data = pf->hw.fdir_shared_filter_count +
1174 pf->fdir_pf_filter_count;
1175
1176 hlist_for_each_entry_safe(rule, node2,
1177 &pf->fdir_filter_list, fdir_node) {
1178 if (fsp->location <= rule->fd_id)
1179 break;
1180 }
1181
1182 if (!rule || fsp->location != rule->fd_id)
1183 return -EINVAL;
1184
1185 fsp->flow_type = rule->flow_type;
1186 fsp->h_u.tcp_ip4_spec.psrc = rule->src_port;
1187 fsp->h_u.tcp_ip4_spec.pdst = rule->dst_port;
1188 fsp->h_u.tcp_ip4_spec.ip4src = rule->src_ip[0];
1189 fsp->h_u.tcp_ip4_spec.ip4dst = rule->dst_ip[0];
1190 fsp->ring_cookie = rule->q_index;
1191
1192 return 0;
1193}
1194
1195/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001196 * i40e_get_rxnfc - command to get RX flow classification rules
1197 * @netdev: network interface device structure
1198 * @cmd: ethtool rxnfc command
1199 *
1200 * Returns Success if the command is supported.
1201 **/
1202static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1203 u32 *rule_locs)
1204{
1205 struct i40e_netdev_priv *np = netdev_priv(netdev);
1206 struct i40e_vsi *vsi = np->vsi;
1207 struct i40e_pf *pf = vsi->back;
1208 int ret = -EOPNOTSUPP;
1209
1210 switch (cmd->cmd) {
1211 case ETHTOOL_GRXRINGS:
1212 cmd->data = vsi->alloc_queue_pairs;
1213 ret = 0;
1214 break;
1215 case ETHTOOL_GRXFH:
1216 ret = i40e_get_rss_hash_opts(pf, cmd);
1217 break;
1218 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001219 cmd->rule_cnt = pf->fdir_pf_active_filters;
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:
1288 hena &=
1289 ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
1290 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
1291 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1292 break;
1293 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1294 hena |=
1295 (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
1296 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
1297 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1298 break;
1299 default:
1300 return -EINVAL;
1301 }
1302 break;
1303 case UDP_V6_FLOW:
1304 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1305 case 0:
1306 hena &=
1307 ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
1308 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
1309 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1310 break;
1311 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1312 hena |=
1313 (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
1314 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
1315 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1316 break;
1317 default:
1318 return -EINVAL;
1319 }
1320 break;
1321 case AH_ESP_V4_FLOW:
1322 case AH_V4_FLOW:
1323 case ESP_V4_FLOW:
1324 case SCTP_V4_FLOW:
1325 if ((nfc->data & RXH_L4_B_0_1) ||
1326 (nfc->data & RXH_L4_B_2_3))
1327 return -EINVAL;
1328 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1329 break;
1330 case AH_ESP_V6_FLOW:
1331 case AH_V6_FLOW:
1332 case ESP_V6_FLOW:
1333 case SCTP_V6_FLOW:
1334 if ((nfc->data & RXH_L4_B_0_1) ||
1335 (nfc->data & RXH_L4_B_2_3))
1336 return -EINVAL;
1337 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1338 break;
1339 case IPV4_FLOW:
1340 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1341 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1342 break;
1343 case IPV6_FLOW:
1344 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1345 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1346 break;
1347 default:
1348 return -EINVAL;
1349 }
1350
1351 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1352 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1353 i40e_flush(hw);
1354
1355 return 0;
1356}
1357
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001358/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001359 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1360 * @vsi: Pointer to the targeted VSI
1361 * @input: The filter to update or NULL to indicate deletion
1362 * @sw_idx: Software index to the filter
1363 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001364 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001365 * This function updates (or deletes) a Flow Director entry from
1366 * the hlist of the corresponding PF
1367 *
1368 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001369 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001370static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1371 struct i40e_fdir_filter *input,
1372 u16 sw_idx,
1373 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001374{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001375 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001376 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001377 struct hlist_node *node2;
1378 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001379
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001380 parent = NULL;
1381 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001382
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001383 hlist_for_each_entry_safe(rule, node2,
1384 &pf->fdir_filter_list, fdir_node) {
1385 /* hash found, or no matching entry */
1386 if (rule->fd_id >= sw_idx)
1387 break;
1388 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001389 }
1390
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001391 /* if there is an old rule occupying our place remove it */
1392 if (rule && (rule->fd_id == sw_idx)) {
1393 if (!input || (rule->fd_id != input->fd_id)) {
1394 cmd->fs.flow_type = rule->flow_type;
1395 err = i40e_add_del_fdir_ethtool(vsi, cmd, false);
1396 }
1397
1398 hlist_del(&rule->fdir_node);
1399 kfree(rule);
1400 pf->fdir_pf_active_filters--;
1401 }
1402
1403 /* If no input this was a delete, err should be 0 if a rule was
1404 * successfully found and removed from the list else -EINVAL
1405 */
1406 if (!input)
1407 return err;
1408
1409 /* initialize node and set software index */
1410 INIT_HLIST_NODE(&input->fdir_node);
1411
1412 /* add filter to the list */
1413 if (parent)
1414 hlist_add_after(&parent->fdir_node, &input->fdir_node);
1415 else
1416 hlist_add_head(&input->fdir_node,
1417 &pf->fdir_filter_list);
1418
1419 /* update counts */
1420 pf->fdir_pf_active_filters++;
1421
1422 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001423}
1424
1425/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001426 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
1427 * @vsi: Pointer to the targeted VSI
1428 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001429 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001430 * The function removes a Flow Director filter entry from the
1431 * hlist of the corresponding PF
1432 *
1433 * Returns 0 on success
1434 */
1435static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
1436 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001437{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001438 struct ethtool_rx_flow_spec *fsp =
1439 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001440 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001441 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00001442
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001443 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001444
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001445 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001446}
1447
1448/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001449 * i40e_add_del_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001450 * @vsi: pointer to the targeted VSI
1451 * @cmd: command to get or set RX flow classification rules
1452 * @add: true adds a filter, false removes it
1453 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001454 * Add/Remove Flow Director filters for a specific flow spec based on their
1455 * protocol. Returns 0 if the filters were successfully added or removed.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001456 **/
1457static int i40e_add_del_fdir_ethtool(struct i40e_vsi *vsi,
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001458 struct ethtool_rxnfc *cmd, bool add)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001459{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001460 struct ethtool_rx_flow_spec *fsp;
1461 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001462 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001463 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001464
1465 if (!vsi)
1466 return -EINVAL;
1467
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001468 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001469 pf = vsi->back;
1470
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001471 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
1472 pf->hw.func_caps.fd_filters_guaranteed)) {
1473 return -EINVAL;
1474 }
1475
1476 if ((fsp->ring_cookie >= vsi->num_queue_pairs) && add)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001477 return -EINVAL;
1478
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001479 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001480
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001481 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001482 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001483
1484 input->fd_id = fsp->location;
1485
1486 input->q_index = fsp->ring_cookie;
1487 input->flex_off = 0;
1488 input->pctype = 0;
1489 input->dest_vsi = vsi->id;
1490 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
1491 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
1492 input->cnt_index = 0;
1493 input->flow_type = fsp->flow_type;
1494 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
1495 input->src_port = fsp->h_u.tcp_ip4_spec.psrc;
1496 input->dst_port = fsp->h_u.tcp_ip4_spec.pdst;
1497 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
1498 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
1499
1500 ret = i40e_add_del_fdir(vsi, input, add);
1501 if (ret) {
1502 kfree(input);
1503 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001504 }
1505
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001506 if (!ret && add)
1507 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
1508 else
1509 kfree(input);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001510
1511 return ret;
1512}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08001513
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001514/**
1515 * i40e_set_rxnfc - command to set RX flow classification rules
1516 * @netdev: network interface device structure
1517 * @cmd: ethtool rxnfc command
1518 *
1519 * Returns Success if the command is supported.
1520 **/
1521static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1522{
1523 struct i40e_netdev_priv *np = netdev_priv(netdev);
1524 struct i40e_vsi *vsi = np->vsi;
1525 struct i40e_pf *pf = vsi->back;
1526 int ret = -EOPNOTSUPP;
1527
1528 switch (cmd->cmd) {
1529 case ETHTOOL_SRXFH:
1530 ret = i40e_set_rss_hash_opt(pf, cmd);
1531 break;
1532 case ETHTOOL_SRXCLSRLINS:
1533 ret = i40e_add_del_fdir_ethtool(vsi, cmd, true);
1534 break;
1535 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001536 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001537 break;
1538 default:
1539 break;
1540 }
1541
1542 return ret;
1543}
1544
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001545/**
1546 * i40e_max_channels - get Max number of combined channels supported
1547 * @vsi: vsi pointer
1548 **/
1549static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
1550{
1551 /* TODO: This code assumes DCB and FD is disabled for now. */
1552 return vsi->alloc_queue_pairs;
1553}
1554
1555/**
1556 * i40e_get_channels - Get the current channels enabled and max supported etc.
1557 * @netdev: network interface device structure
1558 * @ch: ethtool channels structure
1559 *
1560 * We don't support separate tx and rx queues as channels. The other count
1561 * represents how many queues are being used for control. max_combined counts
1562 * how many queue pairs we can support. They may not be mapped 1 to 1 with
1563 * q_vectors since we support a lot more queue pairs than q_vectors.
1564 **/
1565static void i40e_get_channels(struct net_device *dev,
1566 struct ethtool_channels *ch)
1567{
1568 struct i40e_netdev_priv *np = netdev_priv(dev);
1569 struct i40e_vsi *vsi = np->vsi;
1570 struct i40e_pf *pf = vsi->back;
1571
1572 /* report maximum channels */
1573 ch->max_combined = i40e_max_channels(vsi);
1574
1575 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08001576 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001577 ch->max_other = ch->other_count;
1578
1579 /* Note: This code assumes DCB is disabled for now. */
1580 ch->combined_count = vsi->num_queue_pairs;
1581}
1582
1583/**
1584 * i40e_set_channels - Set the new channels count.
1585 * @netdev: network interface device structure
1586 * @ch: ethtool channels structure
1587 *
1588 * The new channels count may not be the same as requested by the user
1589 * since it gets rounded down to a power of 2 value.
1590 **/
1591static int i40e_set_channels(struct net_device *dev,
1592 struct ethtool_channels *ch)
1593{
1594 struct i40e_netdev_priv *np = netdev_priv(dev);
1595 unsigned int count = ch->combined_count;
1596 struct i40e_vsi *vsi = np->vsi;
1597 struct i40e_pf *pf = vsi->back;
1598 int new_count;
1599
1600 /* We do not support setting channels for any other VSI at present */
1601 if (vsi->type != I40E_VSI_MAIN)
1602 return -EINVAL;
1603
1604 /* verify they are not requesting separate vectors */
1605 if (!count || ch->rx_count || ch->tx_count)
1606 return -EINVAL;
1607
1608 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08001609 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001610 return -EINVAL;
1611
1612 /* verify the number of channels does not exceed hardware limits */
1613 if (count > i40e_max_channels(vsi))
1614 return -EINVAL;
1615
1616 /* update feature limits from largest to smallest supported values */
1617 /* TODO: Flow director limit, DCB etc */
1618
1619 /* cap RSS limit */
1620 if (count > pf->rss_size_max)
1621 count = pf->rss_size_max;
1622
1623 /* use rss_reconfig to rebuild with new queue count and update traffic
1624 * class queue mapping
1625 */
1626 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00001627 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001628 return 0;
1629 else
1630 return -EINVAL;
1631}
1632
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001633static const struct ethtool_ops i40e_ethtool_ops = {
1634 .get_settings = i40e_get_settings,
1635 .get_drvinfo = i40e_get_drvinfo,
1636 .get_regs_len = i40e_get_regs_len,
1637 .get_regs = i40e_get_regs,
1638 .nway_reset = i40e_nway_reset,
1639 .get_link = ethtool_op_get_link,
1640 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001641 .set_wol = i40e_set_wol,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001642 .get_eeprom_len = i40e_get_eeprom_len,
1643 .get_eeprom = i40e_get_eeprom,
1644 .get_ringparam = i40e_get_ringparam,
1645 .set_ringparam = i40e_set_ringparam,
1646 .get_pauseparam = i40e_get_pauseparam,
1647 .get_msglevel = i40e_get_msglevel,
1648 .set_msglevel = i40e_set_msglevel,
1649 .get_rxnfc = i40e_get_rxnfc,
1650 .set_rxnfc = i40e_set_rxnfc,
1651 .self_test = i40e_diag_test,
1652 .get_strings = i40e_get_strings,
1653 .set_phys_id = i40e_set_phys_id,
1654 .get_sset_count = i40e_get_sset_count,
1655 .get_ethtool_stats = i40e_get_ethtool_stats,
1656 .get_coalesce = i40e_get_coalesce,
1657 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001658 .get_channels = i40e_get_channels,
1659 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001660 .get_ts_info = i40e_get_ts_info,
1661};
1662
1663void i40e_set_ethtool_ops(struct net_device *netdev)
1664{
1665 SET_ETHTOOL_OPS(netdev, &i40e_ethtool_ops);
1666}