blob: bf607dabe2363ea666898e100c5e9b2ad56d97bb [file] [log] [blame]
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 Intel Corporation.
5 *
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 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * The full GNU General Public License is included in this distribution in
20 * the file called "COPYING".
21 *
22 * Contact Information:
23 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 *
26 ******************************************************************************/
27
28/* ethtool support for i40e */
29
30#include "i40e.h"
31#include "i40e_diag.h"
32
33struct i40e_stats {
34 char stat_string[ETH_GSTRING_LEN];
35 int sizeof_stat;
36 int stat_offset;
37};
38
39#define I40E_STAT(_type, _name, _stat) { \
40 .stat_string = _name, \
41 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
42 .stat_offset = offsetof(_type, _stat) \
43}
44#define I40E_NETDEV_STAT(_net_stat) \
45 I40E_STAT(struct net_device_stats, #_net_stat, _net_stat)
46#define I40E_PF_STAT(_name, _stat) \
47 I40E_STAT(struct i40e_pf, _name, _stat)
48#define I40E_VSI_STAT(_name, _stat) \
49 I40E_STAT(struct i40e_vsi, _name, _stat)
50
51static const struct i40e_stats i40e_gstrings_net_stats[] = {
52 I40E_NETDEV_STAT(rx_packets),
53 I40E_NETDEV_STAT(tx_packets),
54 I40E_NETDEV_STAT(rx_bytes),
55 I40E_NETDEV_STAT(tx_bytes),
56 I40E_NETDEV_STAT(rx_errors),
57 I40E_NETDEV_STAT(tx_errors),
58 I40E_NETDEV_STAT(rx_dropped),
59 I40E_NETDEV_STAT(tx_dropped),
60 I40E_NETDEV_STAT(multicast),
61 I40E_NETDEV_STAT(collisions),
62 I40E_NETDEV_STAT(rx_length_errors),
63 I40E_NETDEV_STAT(rx_crc_errors),
64};
65
66/* These PF_STATs might look like duplicates of some NETDEV_STATs,
67 * but they are separate. This device supports Virtualization, and
68 * as such might have several netdevs supporting VMDq and FCoE going
69 * through a single port. The NETDEV_STATs are for individual netdevs
70 * seen at the top of the stack, and the PF_STATs are for the physical
71 * function at the bottom of the stack hosting those netdevs.
72 *
73 * The PF_STATs are appended to the netdev stats only when ethtool -S
74 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
75 */
76static struct i40e_stats i40e_gstrings_stats[] = {
77 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
78 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
79 I40E_PF_STAT("rx_errors", stats.eth.rx_errors),
80 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
81 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
82 I40E_PF_STAT("tx_dropped", stats.eth.tx_discards),
83 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
84 I40E_PF_STAT("crc_errors", stats.crc_errors),
85 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
86 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
87 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
88 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
89 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
90 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
91 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
92 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
93 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
94 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
95 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
96 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
97 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
98 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
99 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
100 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
101 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
102 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
103 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
104 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
105 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
106 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
107 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
108 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
109 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
110 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
111 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
112};
113
114#define I40E_QUEUE_STATS_LEN(n) \
115 ((((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs + \
116 ((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs) * 2)
117#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
118#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
119#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
120 I40E_QUEUE_STATS_LEN((n)))
121#define I40E_PFC_STATS_LEN ( \
122 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
123 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
124 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
125 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
126 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
127 / sizeof(u64))
128#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
129 I40E_PFC_STATS_LEN + \
130 I40E_VSI_STATS_LEN((n)))
131
132enum i40e_ethtool_test_id {
133 I40E_ETH_TEST_REG = 0,
134 I40E_ETH_TEST_EEPROM,
135 I40E_ETH_TEST_INTR,
136 I40E_ETH_TEST_LOOPBACK,
137 I40E_ETH_TEST_LINK,
138};
139
140static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
141 "Register test (offline)",
142 "Eeprom test (offline)",
143 "Interrupt test (offline)",
144 "Loopback test (offline)",
145 "Link test (on/offline)"
146};
147
148#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
149
150/**
151 * i40e_get_settings - Get Link Speed and Duplex settings
152 * @netdev: network interface device structure
153 * @ecmd: ethtool command
154 *
155 * Reports speed/duplex settings based on media_type
156 **/
157static int i40e_get_settings(struct net_device *netdev,
158 struct ethtool_cmd *ecmd)
159{
160 struct i40e_netdev_priv *np = netdev_priv(netdev);
161 struct i40e_pf *pf = np->vsi->back;
162 struct i40e_hw *hw = &pf->hw;
163 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
164 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
165 u32 link_speed = hw_link_info->link_speed;
166
167 /* hardware is either in 40G mode or 10G mode
168 * NOTE: this section initializes supported and advertising
169 */
170 switch (hw_link_info->phy_type) {
171 case I40E_PHY_TYPE_40GBASE_CR4:
172 case I40E_PHY_TYPE_40GBASE_CR4_CU:
173 ecmd->supported = SUPPORTED_40000baseCR4_Full;
174 ecmd->advertising = ADVERTISED_40000baseCR4_Full;
175 break;
176 case I40E_PHY_TYPE_40GBASE_KR4:
177 ecmd->supported = SUPPORTED_40000baseKR4_Full;
178 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
179 break;
180 case I40E_PHY_TYPE_40GBASE_SR4:
181 ecmd->supported = SUPPORTED_40000baseSR4_Full;
182 ecmd->advertising = ADVERTISED_40000baseSR4_Full;
183 break;
184 case I40E_PHY_TYPE_40GBASE_LR4:
185 ecmd->supported = SUPPORTED_40000baseLR4_Full;
186 ecmd->advertising = ADVERTISED_40000baseLR4_Full;
187 break;
188 case I40E_PHY_TYPE_10GBASE_KX4:
189 ecmd->supported = SUPPORTED_10000baseKX4_Full;
190 ecmd->advertising = ADVERTISED_10000baseKX4_Full;
191 break;
192 case I40E_PHY_TYPE_10GBASE_KR:
193 ecmd->supported = SUPPORTED_10000baseKR_Full;
194 ecmd->advertising = ADVERTISED_10000baseKR_Full;
195 break;
196 case I40E_PHY_TYPE_10GBASE_T:
197 default:
198 ecmd->supported = SUPPORTED_10000baseT_Full;
199 ecmd->advertising = ADVERTISED_10000baseT_Full;
200 break;
201 }
202
203 /* for now just say autoneg all the time */
204 ecmd->supported |= SUPPORTED_Autoneg;
205
206 if (hw->phy.media_type == I40E_MEDIA_TYPE_BACKPLANE) {
207 ecmd->supported |= SUPPORTED_Backplane;
208 ecmd->advertising |= ADVERTISED_Backplane;
209 ecmd->port = PORT_NONE;
210 } else if (hw->phy.media_type == I40E_MEDIA_TYPE_BASET) {
211 ecmd->supported |= SUPPORTED_TP;
212 ecmd->advertising |= ADVERTISED_TP;
213 ecmd->port = PORT_TP;
214 } else {
215 ecmd->supported |= SUPPORTED_FIBRE;
216 ecmd->advertising |= ADVERTISED_FIBRE;
217 ecmd->port = PORT_FIBRE;
218 }
219
220 ecmd->transceiver = XCVR_EXTERNAL;
221
222 if (link_up) {
223 switch (link_speed) {
224 case I40E_LINK_SPEED_40GB:
225 /* need a SPEED_40000 in ethtool.h */
226 ethtool_cmd_speed_set(ecmd, 40000);
227 break;
228 case I40E_LINK_SPEED_10GB:
229 ethtool_cmd_speed_set(ecmd, SPEED_10000);
230 break;
231 default:
232 break;
233 }
234 ecmd->duplex = DUPLEX_FULL;
235 } else {
236 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
237 ecmd->duplex = DUPLEX_UNKNOWN;
238 }
239
240 return 0;
241}
242
243/**
244 * i40e_get_pauseparam - Get Flow Control status
245 * Return tx/rx-pause status
246 **/
247static void i40e_get_pauseparam(struct net_device *netdev,
248 struct ethtool_pauseparam *pause)
249{
250 struct i40e_netdev_priv *np = netdev_priv(netdev);
251 struct i40e_pf *pf = np->vsi->back;
252 struct i40e_hw *hw = &pf->hw;
253 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
254
255 pause->autoneg =
256 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
257 AUTONEG_ENABLE : AUTONEG_DISABLE);
258
259 pause->rx_pause = 0;
260 pause->tx_pause = 0;
261 if (hw_link_info->an_info & I40E_AQ_LINK_PAUSE_RX)
262 pause->rx_pause = 1;
263 if (hw_link_info->an_info & I40E_AQ_LINK_PAUSE_TX)
264 pause->tx_pause = 1;
265}
266
267static u32 i40e_get_msglevel(struct net_device *netdev)
268{
269 struct i40e_netdev_priv *np = netdev_priv(netdev);
270 struct i40e_pf *pf = np->vsi->back;
271
272 return pf->msg_enable;
273}
274
275static void i40e_set_msglevel(struct net_device *netdev, u32 data)
276{
277 struct i40e_netdev_priv *np = netdev_priv(netdev);
278 struct i40e_pf *pf = np->vsi->back;
279
280 if (I40E_DEBUG_USER & data)
281 pf->hw.debug_mask = data;
282 pf->msg_enable = data;
283}
284
285static int i40e_get_regs_len(struct net_device *netdev)
286{
287 int reg_count = 0;
288 int i;
289
290 for (i = 0; i40e_reg_list[i].offset != 0; i++)
291 reg_count += i40e_reg_list[i].elements;
292
293 return reg_count * sizeof(u32);
294}
295
296static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
297 void *p)
298{
299 struct i40e_netdev_priv *np = netdev_priv(netdev);
300 struct i40e_pf *pf = np->vsi->back;
301 struct i40e_hw *hw = &pf->hw;
302 u32 *reg_buf = p;
303 int i, j, ri;
304 u32 reg;
305
306 /* Tell ethtool which driver-version-specific regs output we have.
307 *
308 * At some point, if we have ethtool doing special formatting of
309 * this data, it will rely on this version number to know how to
310 * interpret things. Hence, this needs to be updated if/when the
311 * diags register table is changed.
312 */
313 regs->version = 1;
314
315 /* loop through the diags reg table for what to print */
316 ri = 0;
317 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
318 for (j = 0; j < i40e_reg_list[i].elements; j++) {
319 reg = i40e_reg_list[i].offset
320 + (j * i40e_reg_list[i].stride);
321 reg_buf[ri++] = rd32(hw, reg);
322 }
323 }
324
325}
326
327static int i40e_get_eeprom(struct net_device *netdev,
328 struct ethtool_eeprom *eeprom, u8 *bytes)
329{
330 struct i40e_netdev_priv *np = netdev_priv(netdev);
331 struct i40e_hw *hw = &np->vsi->back->hw;
332 int first_word, last_word;
333 u16 i, eeprom_len;
334 u16 *eeprom_buff;
335 int ret_val = 0;
336
337 if (eeprom->len == 0)
338 return -EINVAL;
339
340 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
341
342 first_word = eeprom->offset >> 1;
343 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
344 eeprom_len = last_word - first_word + 1;
345
346 eeprom_buff = kmalloc(sizeof(u16) * eeprom_len, GFP_KERNEL);
347 if (!eeprom_buff)
348 return -ENOMEM;
349
350 ret_val = i40e_read_nvm_buffer(hw, first_word, &eeprom_len,
351 eeprom_buff);
352 if (eeprom_len == 0) {
353 kfree(eeprom_buff);
354 return -EACCES;
355 }
356
357 /* Device's eeprom is always little-endian, word addressable */
358 for (i = 0; i < eeprom_len; i++)
359 le16_to_cpus(&eeprom_buff[i]);
360
361 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
362 kfree(eeprom_buff);
363
364 return ret_val;
365}
366
367static int i40e_get_eeprom_len(struct net_device *netdev)
368{
369 struct i40e_netdev_priv *np = netdev_priv(netdev);
370 struct i40e_hw *hw = &np->vsi->back->hw;
371
372 return hw->nvm.sr_size * 2;
373}
374
375static void i40e_get_drvinfo(struct net_device *netdev,
376 struct ethtool_drvinfo *drvinfo)
377{
378 struct i40e_netdev_priv *np = netdev_priv(netdev);
379 struct i40e_vsi *vsi = np->vsi;
380 struct i40e_pf *pf = vsi->back;
381
382 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
383 strlcpy(drvinfo->version, i40e_driver_version_str,
384 sizeof(drvinfo->version));
385 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
386 sizeof(drvinfo->fw_version));
387 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
388 sizeof(drvinfo->bus_info));
389}
390
391static void i40e_get_ringparam(struct net_device *netdev,
392 struct ethtool_ringparam *ring)
393{
394 struct i40e_netdev_priv *np = netdev_priv(netdev);
395 struct i40e_pf *pf = np->vsi->back;
396 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
397
398 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
399 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
400 ring->rx_mini_max_pending = 0;
401 ring->rx_jumbo_max_pending = 0;
402 ring->rx_pending = vsi->rx_rings[0].count;
403 ring->tx_pending = vsi->tx_rings[0].count;
404 ring->rx_mini_pending = 0;
405 ring->rx_jumbo_pending = 0;
406}
407
408static int i40e_set_ringparam(struct net_device *netdev,
409 struct ethtool_ringparam *ring)
410{
411 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
412 struct i40e_netdev_priv *np = netdev_priv(netdev);
413 struct i40e_vsi *vsi = np->vsi;
414 struct i40e_pf *pf = vsi->back;
415 u32 new_rx_count, new_tx_count;
416 int i, err = 0;
417
418 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
419 return -EINVAL;
420
421 new_tx_count = clamp_t(u32, ring->tx_pending,
422 I40E_MIN_NUM_DESCRIPTORS,
423 I40E_MAX_NUM_DESCRIPTORS);
424 new_tx_count = ALIGN(new_tx_count, I40E_REQ_DESCRIPTOR_MULTIPLE);
425
426 new_rx_count = clamp_t(u32, ring->rx_pending,
427 I40E_MIN_NUM_DESCRIPTORS,
428 I40E_MAX_NUM_DESCRIPTORS);
429 new_rx_count = ALIGN(new_rx_count, I40E_REQ_DESCRIPTOR_MULTIPLE);
430
431 /* if nothing to do return success */
432 if ((new_tx_count == vsi->tx_rings[0].count) &&
433 (new_rx_count == vsi->rx_rings[0].count))
434 return 0;
435
436 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
437 usleep_range(1000, 2000);
438
439 if (!netif_running(vsi->netdev)) {
440 /* simple case - set for the next time the netdev is started */
441 for (i = 0; i < vsi->num_queue_pairs; i++) {
442 vsi->tx_rings[i].count = new_tx_count;
443 vsi->rx_rings[i].count = new_rx_count;
444 }
445 goto done;
446 }
447
448 /* We can't just free everything and then setup again,
449 * because the ISRs in MSI-X mode get passed pointers
450 * to the Tx and Rx ring structs.
451 */
452
453 /* alloc updated Tx resources */
454 if (new_tx_count != vsi->tx_rings[0].count) {
455 netdev_info(netdev,
456 "Changing Tx descriptor count from %d to %d.\n",
457 vsi->tx_rings[0].count, new_tx_count);
458 tx_rings = kcalloc(vsi->alloc_queue_pairs,
459 sizeof(struct i40e_ring), GFP_KERNEL);
460 if (!tx_rings) {
461 err = -ENOMEM;
462 goto done;
463 }
464
465 for (i = 0; i < vsi->num_queue_pairs; i++) {
466 /* clone ring and setup updated count */
467 tx_rings[i] = vsi->tx_rings[i];
468 tx_rings[i].count = new_tx_count;
469 err = i40e_setup_tx_descriptors(&tx_rings[i]);
470 if (err) {
471 while (i) {
472 i--;
473 i40e_free_tx_resources(&tx_rings[i]);
474 }
475 kfree(tx_rings);
476 tx_rings = NULL;
477
478 goto done;
479 }
480 }
481 }
482
483 /* alloc updated Rx resources */
484 if (new_rx_count != vsi->rx_rings[0].count) {
485 netdev_info(netdev,
486 "Changing Rx descriptor count from %d to %d\n",
487 vsi->rx_rings[0].count, new_rx_count);
488 rx_rings = kcalloc(vsi->alloc_queue_pairs,
489 sizeof(struct i40e_ring), GFP_KERNEL);
490 if (!rx_rings) {
491 err = -ENOMEM;
492 goto free_tx;
493 }
494
495 for (i = 0; i < vsi->num_queue_pairs; i++) {
496 /* clone ring and setup updated count */
497 rx_rings[i] = vsi->rx_rings[i];
498 rx_rings[i].count = new_rx_count;
499 err = i40e_setup_rx_descriptors(&rx_rings[i]);
500 if (err) {
501 while (i) {
502 i--;
503 i40e_free_rx_resources(&rx_rings[i]);
504 }
505 kfree(rx_rings);
506 rx_rings = NULL;
507
508 goto free_tx;
509 }
510 }
511 }
512
513 /* Bring interface down, copy in the new ring info,
514 * then restore the interface
515 */
516 i40e_down(vsi);
517
518 if (tx_rings) {
519 for (i = 0; i < vsi->num_queue_pairs; i++) {
520 i40e_free_tx_resources(&vsi->tx_rings[i]);
521 vsi->tx_rings[i] = tx_rings[i];
522 }
523 kfree(tx_rings);
524 tx_rings = NULL;
525 }
526
527 if (rx_rings) {
528 for (i = 0; i < vsi->num_queue_pairs; i++) {
529 i40e_free_rx_resources(&vsi->rx_rings[i]);
530 vsi->rx_rings[i] = rx_rings[i];
531 }
532 kfree(rx_rings);
533 rx_rings = NULL;
534 }
535
536 i40e_up(vsi);
537
538free_tx:
539 /* error cleanup if the Rx allocations failed after getting Tx */
540 if (tx_rings) {
541 for (i = 0; i < vsi->num_queue_pairs; i++)
542 i40e_free_tx_resources(&tx_rings[i]);
543 kfree(tx_rings);
544 tx_rings = NULL;
545 }
546
547done:
548 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
549
550 return err;
551}
552
553static int i40e_get_sset_count(struct net_device *netdev, int sset)
554{
555 struct i40e_netdev_priv *np = netdev_priv(netdev);
556 struct i40e_vsi *vsi = np->vsi;
557 struct i40e_pf *pf = vsi->back;
558
559 switch (sset) {
560 case ETH_SS_TEST:
561 return I40E_TEST_LEN;
562 case ETH_SS_STATS:
563 if (vsi == pf->vsi[pf->lan_vsi])
564 return I40E_PF_STATS_LEN(netdev);
565 else
566 return I40E_VSI_STATS_LEN(netdev);
567 default:
568 return -EOPNOTSUPP;
569 }
570}
571
572static void i40e_get_ethtool_stats(struct net_device *netdev,
573 struct ethtool_stats *stats, u64 *data)
574{
575 struct i40e_netdev_priv *np = netdev_priv(netdev);
576 struct i40e_vsi *vsi = np->vsi;
577 struct i40e_pf *pf = vsi->back;
578 int i = 0;
579 char *p;
580 int j;
581 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
582
583 i40e_update_stats(vsi);
584
585 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
586 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
587 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
588 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
589 }
Alexander Duycka114d0a2013-09-28 06:00:43 +0000590 for (j = 0; j < vsi->num_queue_pairs; j++, i += 4) {
591 data[i] = vsi->tx_rings[j].stats.packets;
592 data[i + 1] = vsi->tx_rings[j].stats.bytes;
593 data[i + 2] = vsi->rx_rings[j].stats.packets;
594 data[i + 3] = vsi->rx_rings[j].stats.bytes;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000595 }
596 if (vsi == pf->vsi[pf->lan_vsi]) {
597 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
598 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
599 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
600 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
601 }
602 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
603 data[i++] = pf->stats.priority_xon_tx[j];
604 data[i++] = pf->stats.priority_xoff_tx[j];
605 }
606 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
607 data[i++] = pf->stats.priority_xon_rx[j];
608 data[i++] = pf->stats.priority_xoff_rx[j];
609 }
610 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
611 data[i++] = pf->stats.priority_xon_2_xoff[j];
612 }
613}
614
615static void i40e_get_strings(struct net_device *netdev, u32 stringset,
616 u8 *data)
617{
618 struct i40e_netdev_priv *np = netdev_priv(netdev);
619 struct i40e_vsi *vsi = np->vsi;
620 struct i40e_pf *pf = vsi->back;
621 char *p = (char *)data;
622 int i;
623
624 switch (stringset) {
625 case ETH_SS_TEST:
626 for (i = 0; i < I40E_TEST_LEN; i++) {
627 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
628 data += ETH_GSTRING_LEN;
629 }
630 break;
631 case ETH_SS_STATS:
632 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
633 snprintf(p, ETH_GSTRING_LEN, "%s",
634 i40e_gstrings_net_stats[i].stat_string);
635 p += ETH_GSTRING_LEN;
636 }
637 for (i = 0; i < vsi->num_queue_pairs; i++) {
638 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
639 p += ETH_GSTRING_LEN;
640 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
641 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000642 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
643 p += ETH_GSTRING_LEN;
644 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
645 p += ETH_GSTRING_LEN;
646 }
647 if (vsi == pf->vsi[pf->lan_vsi]) {
648 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
649 snprintf(p, ETH_GSTRING_LEN, "port.%s",
650 i40e_gstrings_stats[i].stat_string);
651 p += ETH_GSTRING_LEN;
652 }
653 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
654 snprintf(p, ETH_GSTRING_LEN,
655 "port.tx_priority_%u_xon", i);
656 p += ETH_GSTRING_LEN;
657 snprintf(p, ETH_GSTRING_LEN,
658 "port.tx_priority_%u_xoff", i);
659 p += ETH_GSTRING_LEN;
660 }
661 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
662 snprintf(p, ETH_GSTRING_LEN,
663 "port.rx_priority_%u_xon", i);
664 p += ETH_GSTRING_LEN;
665 snprintf(p, ETH_GSTRING_LEN,
666 "port.rx_priority_%u_xoff", i);
667 p += ETH_GSTRING_LEN;
668 }
669 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
670 snprintf(p, ETH_GSTRING_LEN,
671 "port.rx_priority_%u_xon_2_xoff", i);
672 p += ETH_GSTRING_LEN;
673 }
674 }
675 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
676 break;
677 }
678}
679
680static int i40e_get_ts_info(struct net_device *dev,
681 struct ethtool_ts_info *info)
682{
683 return ethtool_op_get_ts_info(dev, info);
684}
685
686static int i40e_link_test(struct i40e_pf *pf, u64 *data)
687{
688 if (i40e_get_link_status(&pf->hw))
689 *data = 0;
690 else
691 *data = 1;
692
693 return *data;
694}
695
696static int i40e_reg_test(struct i40e_pf *pf, u64 *data)
697{
698 i40e_status ret;
699
700 ret = i40e_diag_reg_test(&pf->hw);
701 *data = ret;
702
703 return ret;
704}
705
706static int i40e_eeprom_test(struct i40e_pf *pf, u64 *data)
707{
708 i40e_status ret;
709
710 ret = i40e_diag_eeprom_test(&pf->hw);
711 *data = ret;
712
713 return ret;
714}
715
716static int i40e_intr_test(struct i40e_pf *pf, u64 *data)
717{
718 *data = -ENOSYS;
719
720 return *data;
721}
722
723static int i40e_loopback_test(struct i40e_pf *pf, u64 *data)
724{
725 *data = -ENOSYS;
726
727 return *data;
728}
729
730static void i40e_diag_test(struct net_device *netdev,
731 struct ethtool_test *eth_test, u64 *data)
732{
733 struct i40e_netdev_priv *np = netdev_priv(netdev);
734 struct i40e_pf *pf = np->vsi->back;
735
736 set_bit(__I40E_TESTING, &pf->state);
737 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
738 /* Offline tests */
739
740 netdev_info(netdev, "offline testing starting\n");
741
742 /* Link test performed before hardware reset
743 * so autoneg doesn't interfere with test result
744 */
745 netdev_info(netdev, "link test starting\n");
746 if (i40e_link_test(pf, &data[I40E_ETH_TEST_LINK]))
747 eth_test->flags |= ETH_TEST_FL_FAILED;
748
749 netdev_info(netdev, "register test starting\n");
750 if (i40e_reg_test(pf, &data[I40E_ETH_TEST_REG]))
751 eth_test->flags |= ETH_TEST_FL_FAILED;
752
753 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
754 netdev_info(netdev, "eeprom test starting\n");
755 if (i40e_eeprom_test(pf, &data[I40E_ETH_TEST_EEPROM]))
756 eth_test->flags |= ETH_TEST_FL_FAILED;
757
758 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
759 netdev_info(netdev, "interrupt test starting\n");
760 if (i40e_intr_test(pf, &data[I40E_ETH_TEST_INTR]))
761 eth_test->flags |= ETH_TEST_FL_FAILED;
762
763 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
764 netdev_info(netdev, "loopback test starting\n");
765 if (i40e_loopback_test(pf, &data[I40E_ETH_TEST_LOOPBACK]))
766 eth_test->flags |= ETH_TEST_FL_FAILED;
767
768 } else {
769 netdev_info(netdev, "online test starting\n");
770 /* Online tests */
771 if (i40e_link_test(pf, &data[I40E_ETH_TEST_LINK]))
772 eth_test->flags |= ETH_TEST_FL_FAILED;
773
774 /* Offline only tests, not run in online; pass by default */
775 data[I40E_ETH_TEST_REG] = 0;
776 data[I40E_ETH_TEST_EEPROM] = 0;
777 data[I40E_ETH_TEST_INTR] = 0;
778 data[I40E_ETH_TEST_LOOPBACK] = 0;
779
780 clear_bit(__I40E_TESTING, &pf->state);
781 }
782}
783
784static void i40e_get_wol(struct net_device *netdev,
785 struct ethtool_wolinfo *wol)
786{
787 wol->supported = 0;
788 wol->wolopts = 0;
789}
790
791static int i40e_nway_reset(struct net_device *netdev)
792{
793 /* restart autonegotiation */
794 struct i40e_netdev_priv *np = netdev_priv(netdev);
795 struct i40e_pf *pf = np->vsi->back;
796 struct i40e_hw *hw = &pf->hw;
797 i40e_status ret = 0;
798
799 ret = i40e_aq_set_link_restart_an(hw, NULL);
800 if (ret) {
801 netdev_info(netdev, "link restart failed, aq_err=%d\n",
802 pf->hw.aq.asq_last_status);
803 return -EIO;
804 }
805
806 return 0;
807}
808
809static int i40e_set_phys_id(struct net_device *netdev,
810 enum ethtool_phys_id_state state)
811{
812 struct i40e_netdev_priv *np = netdev_priv(netdev);
813 struct i40e_pf *pf = np->vsi->back;
814 struct i40e_hw *hw = &pf->hw;
815 int blink_freq = 2;
816
817 switch (state) {
818 case ETHTOOL_ID_ACTIVE:
819 pf->led_status = i40e_led_get(hw);
820 return blink_freq;
821 case ETHTOOL_ID_ON:
822 i40e_led_set(hw, 0xF);
823 break;
824 case ETHTOOL_ID_OFF:
825 i40e_led_set(hw, 0x0);
826 break;
827 case ETHTOOL_ID_INACTIVE:
828 i40e_led_set(hw, pf->led_status);
829 break;
830 }
831
832 return 0;
833}
834
835/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
836 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
837 * 125us (8000 interrupts per second) == ITR(62)
838 */
839
840static int i40e_get_coalesce(struct net_device *netdev,
841 struct ethtool_coalesce *ec)
842{
843 struct i40e_netdev_priv *np = netdev_priv(netdev);
844 struct i40e_vsi *vsi = np->vsi;
845
846 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
847 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
848
849 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
850 ec->rx_coalesce_usecs = 1;
851 else
852 ec->rx_coalesce_usecs = vsi->rx_itr_setting;
853
854 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
855 ec->tx_coalesce_usecs = 1;
856 else
857 ec->tx_coalesce_usecs = vsi->tx_itr_setting;
858
859 return 0;
860}
861
862static int i40e_set_coalesce(struct net_device *netdev,
863 struct ethtool_coalesce *ec)
864{
865 struct i40e_netdev_priv *np = netdev_priv(netdev);
866 struct i40e_q_vector *q_vector;
867 struct i40e_vsi *vsi = np->vsi;
868 struct i40e_pf *pf = vsi->back;
869 struct i40e_hw *hw = &pf->hw;
870 u16 vector;
871 int i;
872
873 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
874 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
875
876 switch (ec->rx_coalesce_usecs) {
877 case 0:
878 vsi->rx_itr_setting = 0;
879 break;
880 case 1:
881 vsi->rx_itr_setting = (I40E_ITR_DYNAMIC |
882 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
883 break;
884 default:
885 if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
886 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)))
887 return -EINVAL;
888 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
889 break;
890 }
891
892 switch (ec->tx_coalesce_usecs) {
893 case 0:
894 vsi->tx_itr_setting = 0;
895 break;
896 case 1:
897 vsi->tx_itr_setting = (I40E_ITR_DYNAMIC |
898 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
899 break;
900 default:
901 if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
902 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)))
903 return -EINVAL;
904 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
905 break;
906 }
907
908 vector = vsi->base_vector;
Alexander Duyck493fb302013-09-28 07:01:44 +0000909 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
910 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000911 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
912 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
913 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
914 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
915 i40e_flush(hw);
916 }
917
918 return 0;
919}
920
921/**
922 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
923 * @pf: pointer to the physical function struct
924 * @cmd: ethtool rxnfc command
925 *
926 * Returns Success if the flow is supported, else Invalid Input.
927 **/
928static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
929{
930 cmd->data = 0;
931
932 /* Report default options for RSS on i40e */
933 switch (cmd->flow_type) {
934 case TCP_V4_FLOW:
935 case UDP_V4_FLOW:
936 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
937 /* fall through to add IP fields */
938 case SCTP_V4_FLOW:
939 case AH_ESP_V4_FLOW:
940 case AH_V4_FLOW:
941 case ESP_V4_FLOW:
942 case IPV4_FLOW:
943 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
944 break;
945 case TCP_V6_FLOW:
946 case UDP_V6_FLOW:
947 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
948 /* fall through to add IP fields */
949 case SCTP_V6_FLOW:
950 case AH_ESP_V6_FLOW:
951 case AH_V6_FLOW:
952 case ESP_V6_FLOW:
953 case IPV6_FLOW:
954 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
955 break;
956 default:
957 return -EINVAL;
958 }
959
960 return 0;
961}
962
963/**
964 * i40e_get_rxnfc - command to get RX flow classification rules
965 * @netdev: network interface device structure
966 * @cmd: ethtool rxnfc command
967 *
968 * Returns Success if the command is supported.
969 **/
970static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
971 u32 *rule_locs)
972{
973 struct i40e_netdev_priv *np = netdev_priv(netdev);
974 struct i40e_vsi *vsi = np->vsi;
975 struct i40e_pf *pf = vsi->back;
976 int ret = -EOPNOTSUPP;
977
978 switch (cmd->cmd) {
979 case ETHTOOL_GRXRINGS:
980 cmd->data = vsi->alloc_queue_pairs;
981 ret = 0;
982 break;
983 case ETHTOOL_GRXFH:
984 ret = i40e_get_rss_hash_opts(pf, cmd);
985 break;
986 case ETHTOOL_GRXCLSRLCNT:
987 ret = 0;
988 break;
989 case ETHTOOL_GRXCLSRULE:
990 ret = 0;
991 break;
992 case ETHTOOL_GRXCLSRLALL:
993 cmd->data = 500;
994 ret = 0;
995 default:
996 break;
997 }
998
999 return ret;
1000}
1001
1002/**
1003 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1004 * @pf: pointer to the physical function struct
1005 * @cmd: ethtool rxnfc command
1006 *
1007 * Returns Success if the flow input set is supported.
1008 **/
1009static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1010{
1011 struct i40e_hw *hw = &pf->hw;
1012 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1013 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1014
1015 /* RSS does not support anything other than hashing
1016 * to queues on src and dst IPs and ports
1017 */
1018 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1019 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1020 return -EINVAL;
1021
1022 /* We need at least the IP SRC and DEST fields for hashing */
1023 if (!(nfc->data & RXH_IP_SRC) ||
1024 !(nfc->data & RXH_IP_DST))
1025 return -EINVAL;
1026
1027 switch (nfc->flow_type) {
1028 case TCP_V4_FLOW:
1029 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1030 case 0:
1031 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1032 break;
1033 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1034 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1035 break;
1036 default:
1037 return -EINVAL;
1038 }
1039 break;
1040 case TCP_V6_FLOW:
1041 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1042 case 0:
1043 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1044 break;
1045 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1046 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1047 break;
1048 default:
1049 return -EINVAL;
1050 }
1051 break;
1052 case UDP_V4_FLOW:
1053 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1054 case 0:
1055 hena &=
1056 ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
1057 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
1058 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1059 break;
1060 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1061 hena |=
1062 (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
1063 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
1064 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1065 break;
1066 default:
1067 return -EINVAL;
1068 }
1069 break;
1070 case UDP_V6_FLOW:
1071 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1072 case 0:
1073 hena &=
1074 ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
1075 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
1076 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1077 break;
1078 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1079 hena |=
1080 (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
1081 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
1082 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1083 break;
1084 default:
1085 return -EINVAL;
1086 }
1087 break;
1088 case AH_ESP_V4_FLOW:
1089 case AH_V4_FLOW:
1090 case ESP_V4_FLOW:
1091 case SCTP_V4_FLOW:
1092 if ((nfc->data & RXH_L4_B_0_1) ||
1093 (nfc->data & RXH_L4_B_2_3))
1094 return -EINVAL;
1095 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1096 break;
1097 case AH_ESP_V6_FLOW:
1098 case AH_V6_FLOW:
1099 case ESP_V6_FLOW:
1100 case SCTP_V6_FLOW:
1101 if ((nfc->data & RXH_L4_B_0_1) ||
1102 (nfc->data & RXH_L4_B_2_3))
1103 return -EINVAL;
1104 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1105 break;
1106 case IPV4_FLOW:
1107 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1108 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1109 break;
1110 case IPV6_FLOW:
1111 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1112 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1113 break;
1114 default:
1115 return -EINVAL;
1116 }
1117
1118 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1119 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1120 i40e_flush(hw);
1121
1122 return 0;
1123}
1124
1125#define IP_HEADER_OFFSET 14
1126/**
1127 * i40e_add_del_fdir_udpv4 - Add/Remove UDPv4 Flow Director filters for
1128 * a specific flow spec
1129 * @vsi: pointer to the targeted VSI
1130 * @fd_data: the flow director data required from the FDir descriptor
1131 * @ethtool_rx_flow_spec: the flow spec
1132 * @add: true adds a filter, false removes it
1133 *
1134 * Returns 0 if the filters were successfully added or removed
1135 **/
1136static int i40e_add_del_fdir_udpv4(struct i40e_vsi *vsi,
1137 struct i40e_fdir_data *fd_data,
1138 struct ethtool_rx_flow_spec *fsp, bool add)
1139{
1140 struct i40e_pf *pf = vsi->back;
1141 struct udphdr *udp;
1142 struct iphdr *ip;
1143 bool err = false;
1144 int ret;
1145 int i;
1146
1147 ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
1148 udp = (struct udphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET
1149 + sizeof(struct iphdr));
1150
1151 ip->saddr = fsp->h_u.tcp_ip4_spec.ip4src;
1152 ip->daddr = fsp->h_u.tcp_ip4_spec.ip4dst;
1153 udp->source = fsp->h_u.tcp_ip4_spec.psrc;
1154 udp->dest = fsp->h_u.tcp_ip4_spec.pdst;
1155
1156 for (i = I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP;
1157 i <= I40E_FILTER_PCTYPE_NONF_IPV4_UDP; i++) {
1158 fd_data->pctype = i;
1159 ret = i40e_program_fdir_filter(fd_data, pf, add);
1160
1161 if (ret) {
1162 dev_info(&pf->pdev->dev,
1163 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1164 fd_data->pctype, ret);
1165 err = true;
1166 } else {
1167 dev_info(&pf->pdev->dev,
1168 "Filter OK for PCTYPE %d (ret = %d)\n",
1169 fd_data->pctype, ret);
1170 }
1171 }
1172
1173 return err ? -EOPNOTSUPP : 0;
1174}
1175
1176/**
1177 * i40e_add_del_fdir_tcpv4 - Add/Remove TCPv4 Flow Director filters for
1178 * a specific flow spec
1179 * @vsi: pointer to the targeted VSI
1180 * @fd_data: the flow director data required from the FDir descriptor
1181 * @ethtool_rx_flow_spec: the flow spec
1182 * @add: true adds a filter, false removes it
1183 *
1184 * Returns 0 if the filters were successfully added or removed
1185 **/
1186static int i40e_add_del_fdir_tcpv4(struct i40e_vsi *vsi,
1187 struct i40e_fdir_data *fd_data,
1188 struct ethtool_rx_flow_spec *fsp, bool add)
1189{
1190 struct i40e_pf *pf = vsi->back;
1191 struct tcphdr *tcp;
1192 struct iphdr *ip;
1193 bool err = false;
1194 int ret;
1195
1196 ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
1197 tcp = (struct tcphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET
1198 + sizeof(struct iphdr));
1199
1200 ip->daddr = fsp->h_u.tcp_ip4_spec.ip4dst;
1201 tcp->dest = fsp->h_u.tcp_ip4_spec.pdst;
1202
1203 fd_data->pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN;
1204 ret = i40e_program_fdir_filter(fd_data, pf, add);
1205
1206 if (ret) {
1207 dev_info(&pf->pdev->dev,
1208 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1209 fd_data->pctype, ret);
1210 err = true;
1211 } else {
1212 dev_info(&pf->pdev->dev, "Filter OK for PCTYPE %d (ret = %d)\n",
1213 fd_data->pctype, ret);
1214 }
1215
1216 ip->saddr = fsp->h_u.tcp_ip4_spec.ip4src;
1217 tcp->source = fsp->h_u.tcp_ip4_spec.psrc;
1218
1219 fd_data->pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
1220
1221 ret = i40e_program_fdir_filter(fd_data, pf, add);
1222 if (ret) {
1223 dev_info(&pf->pdev->dev,
1224 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1225 fd_data->pctype, ret);
1226 err = true;
1227 } else {
1228 dev_info(&pf->pdev->dev, "Filter OK for PCTYPE %d (ret = %d)\n",
1229 fd_data->pctype, ret);
1230 }
1231
1232 return err ? -EOPNOTSUPP : 0;
1233}
1234
1235/**
1236 * i40e_add_del_fdir_sctpv4 - Add/Remove SCTPv4 Flow Director filters for
1237 * a specific flow spec
1238 * @vsi: pointer to the targeted VSI
1239 * @fd_data: the flow director data required from the FDir descriptor
1240 * @ethtool_rx_flow_spec: the flow spec
1241 * @add: true adds a filter, false removes it
1242 *
1243 * Returns 0 if the filters were successfully added or removed
1244 **/
1245static int i40e_add_del_fdir_sctpv4(struct i40e_vsi *vsi,
1246 struct i40e_fdir_data *fd_data,
1247 struct ethtool_rx_flow_spec *fsp, bool add)
1248{
1249 return -EOPNOTSUPP;
1250}
1251
1252/**
1253 * i40e_add_del_fdir_ipv4 - Add/Remove IPv4 Flow Director filters for
1254 * a specific flow spec
1255 * @vsi: pointer to the targeted VSI
1256 * @fd_data: the flow director data required for the FDir descriptor
1257 * @fsp: the ethtool flow spec
1258 * @add: true adds a filter, false removes it
1259 *
1260 * Returns 0 if the filters were successfully added or removed
1261 **/
1262static int i40e_add_del_fdir_ipv4(struct i40e_vsi *vsi,
1263 struct i40e_fdir_data *fd_data,
1264 struct ethtool_rx_flow_spec *fsp, bool add)
1265{
1266 struct i40e_pf *pf = vsi->back;
1267 struct iphdr *ip;
1268 bool err = false;
1269 int ret;
1270 int i;
1271
1272 ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
1273
1274 ip->saddr = fsp->h_u.usr_ip4_spec.ip4src;
1275 ip->daddr = fsp->h_u.usr_ip4_spec.ip4dst;
1276 ip->protocol = fsp->h_u.usr_ip4_spec.proto;
1277
1278 for (i = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
1279 i <= I40E_FILTER_PCTYPE_FRAG_IPV4; i++) {
1280 fd_data->pctype = i;
1281 ret = i40e_program_fdir_filter(fd_data, pf, add);
1282
1283 if (ret) {
1284 dev_info(&pf->pdev->dev,
1285 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1286 fd_data->pctype, ret);
1287 err = true;
1288 } else {
1289 dev_info(&pf->pdev->dev,
1290 "Filter OK for PCTYPE %d (ret = %d)\n",
1291 fd_data->pctype, ret);
1292 }
1293 }
1294
1295 return err ? -EOPNOTSUPP : 0;
1296}
1297
1298/**
1299 * i40e_add_del_fdir_ethtool - Add/Remove Flow Director filters for
1300 * a specific flow spec based on their protocol
1301 * @vsi: pointer to the targeted VSI
1302 * @cmd: command to get or set RX flow classification rules
1303 * @add: true adds a filter, false removes it
1304 *
1305 * Returns 0 if the filters were successfully added or removed
1306 **/
1307static int i40e_add_del_fdir_ethtool(struct i40e_vsi *vsi,
1308 struct ethtool_rxnfc *cmd, bool add)
1309{
1310 struct i40e_fdir_data fd_data;
1311 int ret = -EINVAL;
1312 struct i40e_pf *pf;
1313 struct ethtool_rx_flow_spec *fsp =
1314 (struct ethtool_rx_flow_spec *)&cmd->fs;
1315
1316 if (!vsi)
1317 return -EINVAL;
1318
1319 pf = vsi->back;
1320
1321 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
1322 (fsp->ring_cookie >= vsi->num_queue_pairs))
1323 return -EINVAL;
1324
1325 /* Populate the Flow Director that we have at the moment
1326 * and allocate the raw packet buffer for the calling functions
1327 */
1328 fd_data.raw_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_LOOKUP,
1329 GFP_KERNEL);
1330
1331 if (!fd_data.raw_packet) {
1332 dev_info(&pf->pdev->dev, "Could not allocate memory\n");
1333 return -ENOMEM;
1334 }
1335
1336 fd_data.q_index = fsp->ring_cookie;
1337 fd_data.flex_off = 0;
1338 fd_data.pctype = 0;
1339 fd_data.dest_vsi = vsi->id;
1340 fd_data.dest_ctl = 0;
1341 fd_data.fd_status = 0;
1342 fd_data.cnt_index = 0;
1343 fd_data.fd_id = 0;
1344
1345 switch (fsp->flow_type & ~FLOW_EXT) {
1346 case TCP_V4_FLOW:
1347 ret = i40e_add_del_fdir_tcpv4(vsi, &fd_data, fsp, add);
1348 break;
1349 case UDP_V4_FLOW:
1350 ret = i40e_add_del_fdir_udpv4(vsi, &fd_data, fsp, add);
1351 break;
1352 case SCTP_V4_FLOW:
1353 ret = i40e_add_del_fdir_sctpv4(vsi, &fd_data, fsp, add);
1354 break;
1355 case IPV4_FLOW:
1356 ret = i40e_add_del_fdir_ipv4(vsi, &fd_data, fsp, add);
1357 break;
1358 case IP_USER_FLOW:
1359 switch (fsp->h_u.usr_ip4_spec.proto) {
1360 case IPPROTO_TCP:
1361 ret = i40e_add_del_fdir_tcpv4(vsi, &fd_data, fsp, add);
1362 break;
1363 case IPPROTO_UDP:
1364 ret = i40e_add_del_fdir_udpv4(vsi, &fd_data, fsp, add);
1365 break;
1366 case IPPROTO_SCTP:
1367 ret = i40e_add_del_fdir_sctpv4(vsi, &fd_data, fsp, add);
1368 break;
1369 default:
1370 ret = i40e_add_del_fdir_ipv4(vsi, &fd_data, fsp, add);
1371 break;
1372 }
1373 break;
1374 default:
1375 dev_info(&pf->pdev->dev, "Could not specify spec type\n");
1376 ret = -EINVAL;
1377 }
1378
1379 kfree(fd_data.raw_packet);
1380 fd_data.raw_packet = NULL;
1381
1382 return ret;
1383}
1384/**
1385 * i40e_set_rxnfc - command to set RX flow classification rules
1386 * @netdev: network interface device structure
1387 * @cmd: ethtool rxnfc command
1388 *
1389 * Returns Success if the command is supported.
1390 **/
1391static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1392{
1393 struct i40e_netdev_priv *np = netdev_priv(netdev);
1394 struct i40e_vsi *vsi = np->vsi;
1395 struct i40e_pf *pf = vsi->back;
1396 int ret = -EOPNOTSUPP;
1397
1398 switch (cmd->cmd) {
1399 case ETHTOOL_SRXFH:
1400 ret = i40e_set_rss_hash_opt(pf, cmd);
1401 break;
1402 case ETHTOOL_SRXCLSRLINS:
1403 ret = i40e_add_del_fdir_ethtool(vsi, cmd, true);
1404 break;
1405 case ETHTOOL_SRXCLSRLDEL:
1406 ret = i40e_add_del_fdir_ethtool(vsi, cmd, false);
1407 break;
1408 default:
1409 break;
1410 }
1411
1412 return ret;
1413}
1414
1415static const struct ethtool_ops i40e_ethtool_ops = {
1416 .get_settings = i40e_get_settings,
1417 .get_drvinfo = i40e_get_drvinfo,
1418 .get_regs_len = i40e_get_regs_len,
1419 .get_regs = i40e_get_regs,
1420 .nway_reset = i40e_nway_reset,
1421 .get_link = ethtool_op_get_link,
1422 .get_wol = i40e_get_wol,
1423 .get_eeprom_len = i40e_get_eeprom_len,
1424 .get_eeprom = i40e_get_eeprom,
1425 .get_ringparam = i40e_get_ringparam,
1426 .set_ringparam = i40e_set_ringparam,
1427 .get_pauseparam = i40e_get_pauseparam,
1428 .get_msglevel = i40e_get_msglevel,
1429 .set_msglevel = i40e_set_msglevel,
1430 .get_rxnfc = i40e_get_rxnfc,
1431 .set_rxnfc = i40e_set_rxnfc,
1432 .self_test = i40e_diag_test,
1433 .get_strings = i40e_get_strings,
1434 .set_phys_id = i40e_set_phys_id,
1435 .get_sset_count = i40e_get_sset_count,
1436 .get_ethtool_stats = i40e_get_ethtool_stats,
1437 .get_coalesce = i40e_get_coalesce,
1438 .set_coalesce = i40e_set_coalesce,
1439 .get_ts_info = i40e_get_ts_info,
1440};
1441
1442void i40e_set_ethtool_ops(struct net_device *netdev)
1443{
1444 SET_ETHTOOL_OPS(netdev, &i40e_ethtool_ops);
1445}