net-ipv6: Fix alleged compiler warning in ipv6_exthdrs_len()
[deliverable/linux.git] / drivers / net / ethernet / intel / i40e / i40e_ethtool.c
CommitLineData
c7d05ca8
JB
1/*******************************************************************************
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;
be405eb0
JB
214 } else if (hw->phy.media_type == I40E_MEDIA_TYPE_DA) {
215 ecmd->supported |= SUPPORTED_FIBRE;
216 ecmd->advertising |= ADVERTISED_FIBRE;
217 ecmd->port = PORT_DA;
c7d05ca8
JB
218 } else {
219 ecmd->supported |= SUPPORTED_FIBRE;
220 ecmd->advertising |= ADVERTISED_FIBRE;
221 ecmd->port = PORT_FIBRE;
222 }
223
224 ecmd->transceiver = XCVR_EXTERNAL;
225
226 if (link_up) {
227 switch (link_speed) {
228 case I40E_LINK_SPEED_40GB:
229 /* need a SPEED_40000 in ethtool.h */
230 ethtool_cmd_speed_set(ecmd, 40000);
231 break;
232 case I40E_LINK_SPEED_10GB:
233 ethtool_cmd_speed_set(ecmd, SPEED_10000);
234 break;
235 default:
236 break;
237 }
238 ecmd->duplex = DUPLEX_FULL;
239 } else {
240 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
241 ecmd->duplex = DUPLEX_UNKNOWN;
242 }
243
244 return 0;
245}
246
247/**
248 * i40e_get_pauseparam - Get Flow Control status
249 * Return tx/rx-pause status
250 **/
251static void i40e_get_pauseparam(struct net_device *netdev,
252 struct ethtool_pauseparam *pause)
253{
254 struct i40e_netdev_priv *np = netdev_priv(netdev);
255 struct i40e_pf *pf = np->vsi->back;
256 struct i40e_hw *hw = &pf->hw;
257 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
258
259 pause->autoneg =
260 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
261 AUTONEG_ENABLE : AUTONEG_DISABLE);
262
263 pause->rx_pause = 0;
264 pause->tx_pause = 0;
265 if (hw_link_info->an_info & I40E_AQ_LINK_PAUSE_RX)
266 pause->rx_pause = 1;
267 if (hw_link_info->an_info & I40E_AQ_LINK_PAUSE_TX)
268 pause->tx_pause = 1;
269}
270
271static u32 i40e_get_msglevel(struct net_device *netdev)
272{
273 struct i40e_netdev_priv *np = netdev_priv(netdev);
274 struct i40e_pf *pf = np->vsi->back;
275
276 return pf->msg_enable;
277}
278
279static void i40e_set_msglevel(struct net_device *netdev, u32 data)
280{
281 struct i40e_netdev_priv *np = netdev_priv(netdev);
282 struct i40e_pf *pf = np->vsi->back;
283
284 if (I40E_DEBUG_USER & data)
285 pf->hw.debug_mask = data;
286 pf->msg_enable = data;
287}
288
289static int i40e_get_regs_len(struct net_device *netdev)
290{
291 int reg_count = 0;
292 int i;
293
294 for (i = 0; i40e_reg_list[i].offset != 0; i++)
295 reg_count += i40e_reg_list[i].elements;
296
297 return reg_count * sizeof(u32);
298}
299
300static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
301 void *p)
302{
303 struct i40e_netdev_priv *np = netdev_priv(netdev);
304 struct i40e_pf *pf = np->vsi->back;
305 struct i40e_hw *hw = &pf->hw;
306 u32 *reg_buf = p;
307 int i, j, ri;
308 u32 reg;
309
310 /* Tell ethtool which driver-version-specific regs output we have.
311 *
312 * At some point, if we have ethtool doing special formatting of
313 * this data, it will rely on this version number to know how to
314 * interpret things. Hence, this needs to be updated if/when the
315 * diags register table is changed.
316 */
317 regs->version = 1;
318
319 /* loop through the diags reg table for what to print */
320 ri = 0;
321 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
322 for (j = 0; j < i40e_reg_list[i].elements; j++) {
323 reg = i40e_reg_list[i].offset
324 + (j * i40e_reg_list[i].stride);
325 reg_buf[ri++] = rd32(hw, reg);
326 }
327 }
328
329}
330
331static int i40e_get_eeprom(struct net_device *netdev,
332 struct ethtool_eeprom *eeprom, u8 *bytes)
333{
334 struct i40e_netdev_priv *np = netdev_priv(netdev);
335 struct i40e_hw *hw = &np->vsi->back->hw;
336 int first_word, last_word;
337 u16 i, eeprom_len;
338 u16 *eeprom_buff;
339 int ret_val = 0;
340
341 if (eeprom->len == 0)
342 return -EINVAL;
343
344 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
345
346 first_word = eeprom->offset >> 1;
347 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
348 eeprom_len = last_word - first_word + 1;
349
350 eeprom_buff = kmalloc(sizeof(u16) * eeprom_len, GFP_KERNEL);
351 if (!eeprom_buff)
352 return -ENOMEM;
353
354 ret_val = i40e_read_nvm_buffer(hw, first_word, &eeprom_len,
355 eeprom_buff);
356 if (eeprom_len == 0) {
357 kfree(eeprom_buff);
358 return -EACCES;
359 }
360
361 /* Device's eeprom is always little-endian, word addressable */
362 for (i = 0; i < eeprom_len; i++)
363 le16_to_cpus(&eeprom_buff[i]);
364
365 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
366 kfree(eeprom_buff);
367
368 return ret_val;
369}
370
371static int i40e_get_eeprom_len(struct net_device *netdev)
372{
373 struct i40e_netdev_priv *np = netdev_priv(netdev);
374 struct i40e_hw *hw = &np->vsi->back->hw;
375
376 return hw->nvm.sr_size * 2;
377}
378
379static void i40e_get_drvinfo(struct net_device *netdev,
380 struct ethtool_drvinfo *drvinfo)
381{
382 struct i40e_netdev_priv *np = netdev_priv(netdev);
383 struct i40e_vsi *vsi = np->vsi;
384 struct i40e_pf *pf = vsi->back;
385
386 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
387 strlcpy(drvinfo->version, i40e_driver_version_str,
388 sizeof(drvinfo->version));
389 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
390 sizeof(drvinfo->fw_version));
391 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
392 sizeof(drvinfo->bus_info));
393}
394
395static void i40e_get_ringparam(struct net_device *netdev,
396 struct ethtool_ringparam *ring)
397{
398 struct i40e_netdev_priv *np = netdev_priv(netdev);
399 struct i40e_pf *pf = np->vsi->back;
400 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
401
402 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
403 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
404 ring->rx_mini_max_pending = 0;
405 ring->rx_jumbo_max_pending = 0;
9f65e15b
AD
406 ring->rx_pending = vsi->rx_rings[0]->count;
407 ring->tx_pending = vsi->tx_rings[0]->count;
c7d05ca8
JB
408 ring->rx_mini_pending = 0;
409 ring->rx_jumbo_pending = 0;
410}
411
412static int i40e_set_ringparam(struct net_device *netdev,
413 struct ethtool_ringparam *ring)
414{
415 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
416 struct i40e_netdev_priv *np = netdev_priv(netdev);
417 struct i40e_vsi *vsi = np->vsi;
418 struct i40e_pf *pf = vsi->back;
419 u32 new_rx_count, new_tx_count;
420 int i, err = 0;
421
422 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
423 return -EINVAL;
424
1fa18370
SN
425 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
426 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
427 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
428 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
429 netdev_info(netdev,
430 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
431 ring->tx_pending, ring->rx_pending,
432 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
433 return -EINVAL;
434 }
435
436 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
437 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
c7d05ca8
JB
438
439 /* if nothing to do return success */
9f65e15b
AD
440 if ((new_tx_count == vsi->tx_rings[0]->count) &&
441 (new_rx_count == vsi->rx_rings[0]->count))
c7d05ca8
JB
442 return 0;
443
444 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
445 usleep_range(1000, 2000);
446
447 if (!netif_running(vsi->netdev)) {
448 /* simple case - set for the next time the netdev is started */
449 for (i = 0; i < vsi->num_queue_pairs; i++) {
9f65e15b
AD
450 vsi->tx_rings[i]->count = new_tx_count;
451 vsi->rx_rings[i]->count = new_rx_count;
c7d05ca8
JB
452 }
453 goto done;
454 }
455
456 /* We can't just free everything and then setup again,
457 * because the ISRs in MSI-X mode get passed pointers
458 * to the Tx and Rx ring structs.
459 */
460
461 /* alloc updated Tx resources */
9f65e15b 462 if (new_tx_count != vsi->tx_rings[0]->count) {
c7d05ca8
JB
463 netdev_info(netdev,
464 "Changing Tx descriptor count from %d to %d.\n",
9f65e15b 465 vsi->tx_rings[0]->count, new_tx_count);
c7d05ca8
JB
466 tx_rings = kcalloc(vsi->alloc_queue_pairs,
467 sizeof(struct i40e_ring), GFP_KERNEL);
468 if (!tx_rings) {
469 err = -ENOMEM;
470 goto done;
471 }
472
473 for (i = 0; i < vsi->num_queue_pairs; i++) {
474 /* clone ring and setup updated count */
9f65e15b 475 tx_rings[i] = *vsi->tx_rings[i];
c7d05ca8
JB
476 tx_rings[i].count = new_tx_count;
477 err = i40e_setup_tx_descriptors(&tx_rings[i]);
478 if (err) {
479 while (i) {
480 i--;
481 i40e_free_tx_resources(&tx_rings[i]);
482 }
483 kfree(tx_rings);
484 tx_rings = NULL;
485
486 goto done;
487 }
488 }
489 }
490
491 /* alloc updated Rx resources */
9f65e15b 492 if (new_rx_count != vsi->rx_rings[0]->count) {
c7d05ca8
JB
493 netdev_info(netdev,
494 "Changing Rx descriptor count from %d to %d\n",
9f65e15b 495 vsi->rx_rings[0]->count, new_rx_count);
c7d05ca8
JB
496 rx_rings = kcalloc(vsi->alloc_queue_pairs,
497 sizeof(struct i40e_ring), GFP_KERNEL);
498 if (!rx_rings) {
499 err = -ENOMEM;
500 goto free_tx;
501 }
502
503 for (i = 0; i < vsi->num_queue_pairs; i++) {
504 /* clone ring and setup updated count */
9f65e15b 505 rx_rings[i] = *vsi->rx_rings[i];
c7d05ca8
JB
506 rx_rings[i].count = new_rx_count;
507 err = i40e_setup_rx_descriptors(&rx_rings[i]);
508 if (err) {
509 while (i) {
510 i--;
511 i40e_free_rx_resources(&rx_rings[i]);
512 }
513 kfree(rx_rings);
514 rx_rings = NULL;
515
516 goto free_tx;
517 }
518 }
519 }
520
521 /* Bring interface down, copy in the new ring info,
522 * then restore the interface
523 */
524 i40e_down(vsi);
525
526 if (tx_rings) {
527 for (i = 0; i < vsi->num_queue_pairs; i++) {
9f65e15b
AD
528 i40e_free_tx_resources(vsi->tx_rings[i]);
529 *vsi->tx_rings[i] = tx_rings[i];
c7d05ca8
JB
530 }
531 kfree(tx_rings);
532 tx_rings = NULL;
533 }
534
535 if (rx_rings) {
536 for (i = 0; i < vsi->num_queue_pairs; i++) {
9f65e15b
AD
537 i40e_free_rx_resources(vsi->rx_rings[i]);
538 *vsi->rx_rings[i] = rx_rings[i];
c7d05ca8
JB
539 }
540 kfree(rx_rings);
541 rx_rings = NULL;
542 }
543
544 i40e_up(vsi);
545
546free_tx:
547 /* error cleanup if the Rx allocations failed after getting Tx */
548 if (tx_rings) {
549 for (i = 0; i < vsi->num_queue_pairs; i++)
550 i40e_free_tx_resources(&tx_rings[i]);
551 kfree(tx_rings);
552 tx_rings = NULL;
553 }
554
555done:
556 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
557
558 return err;
559}
560
561static int i40e_get_sset_count(struct net_device *netdev, int sset)
562{
563 struct i40e_netdev_priv *np = netdev_priv(netdev);
564 struct i40e_vsi *vsi = np->vsi;
565 struct i40e_pf *pf = vsi->back;
566
567 switch (sset) {
568 case ETH_SS_TEST:
569 return I40E_TEST_LEN;
570 case ETH_SS_STATS:
571 if (vsi == pf->vsi[pf->lan_vsi])
572 return I40E_PF_STATS_LEN(netdev);
573 else
574 return I40E_VSI_STATS_LEN(netdev);
575 default:
576 return -EOPNOTSUPP;
577 }
578}
579
580static void i40e_get_ethtool_stats(struct net_device *netdev,
581 struct ethtool_stats *stats, u64 *data)
582{
583 struct i40e_netdev_priv *np = netdev_priv(netdev);
584 struct i40e_vsi *vsi = np->vsi;
585 struct i40e_pf *pf = vsi->back;
586 int i = 0;
587 char *p;
588 int j;
589 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
980e9b11 590 unsigned int start;
c7d05ca8
JB
591
592 i40e_update_stats(vsi);
593
594 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
595 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
596 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
597 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
598 }
980e9b11 599 rcu_read_lock();
a114d0a6 600 for (j = 0; j < vsi->num_queue_pairs; j++, i += 4) {
980e9b11
AD
601 struct i40e_ring *tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
602 struct i40e_ring *rx_ring;
603
604 if (!tx_ring)
605 continue;
606
607 /* process Tx ring statistics */
608 do {
609 start = u64_stats_fetch_begin_bh(&tx_ring->syncp);
610 data[i] = tx_ring->stats.packets;
611 data[i + 1] = tx_ring->stats.bytes;
612 } while (u64_stats_fetch_retry_bh(&tx_ring->syncp, start));
613
614 /* Rx ring is the 2nd half of the queue pair */
615 rx_ring = &tx_ring[1];
616 do {
617 start = u64_stats_fetch_begin_bh(&rx_ring->syncp);
618 data[i + 2] = rx_ring->stats.packets;
619 data[i + 3] = rx_ring->stats.bytes;
620 } while (u64_stats_fetch_retry_bh(&rx_ring->syncp, start));
c7d05ca8 621 }
980e9b11 622 rcu_read_unlock();
c7d05ca8
JB
623 if (vsi == pf->vsi[pf->lan_vsi]) {
624 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
625 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
626 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
627 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
628 }
629 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
630 data[i++] = pf->stats.priority_xon_tx[j];
631 data[i++] = pf->stats.priority_xoff_tx[j];
632 }
633 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
634 data[i++] = pf->stats.priority_xon_rx[j];
635 data[i++] = pf->stats.priority_xoff_rx[j];
636 }
637 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
638 data[i++] = pf->stats.priority_xon_2_xoff[j];
639 }
640}
641
642static void i40e_get_strings(struct net_device *netdev, u32 stringset,
643 u8 *data)
644{
645 struct i40e_netdev_priv *np = netdev_priv(netdev);
646 struct i40e_vsi *vsi = np->vsi;
647 struct i40e_pf *pf = vsi->back;
648 char *p = (char *)data;
649 int i;
650
651 switch (stringset) {
652 case ETH_SS_TEST:
653 for (i = 0; i < I40E_TEST_LEN; i++) {
654 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
655 data += ETH_GSTRING_LEN;
656 }
657 break;
658 case ETH_SS_STATS:
659 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
660 snprintf(p, ETH_GSTRING_LEN, "%s",
661 i40e_gstrings_net_stats[i].stat_string);
662 p += ETH_GSTRING_LEN;
663 }
664 for (i = 0; i < vsi->num_queue_pairs; i++) {
665 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
666 p += ETH_GSTRING_LEN;
667 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
668 p += ETH_GSTRING_LEN;
c7d05ca8
JB
669 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
670 p += ETH_GSTRING_LEN;
671 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
672 p += ETH_GSTRING_LEN;
673 }
674 if (vsi == pf->vsi[pf->lan_vsi]) {
675 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
676 snprintf(p, ETH_GSTRING_LEN, "port.%s",
677 i40e_gstrings_stats[i].stat_string);
678 p += ETH_GSTRING_LEN;
679 }
680 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
681 snprintf(p, ETH_GSTRING_LEN,
682 "port.tx_priority_%u_xon", i);
683 p += ETH_GSTRING_LEN;
684 snprintf(p, ETH_GSTRING_LEN,
685 "port.tx_priority_%u_xoff", i);
686 p += ETH_GSTRING_LEN;
687 }
688 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
689 snprintf(p, ETH_GSTRING_LEN,
690 "port.rx_priority_%u_xon", i);
691 p += ETH_GSTRING_LEN;
692 snprintf(p, ETH_GSTRING_LEN,
693 "port.rx_priority_%u_xoff", i);
694 p += ETH_GSTRING_LEN;
695 }
696 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
697 snprintf(p, ETH_GSTRING_LEN,
698 "port.rx_priority_%u_xon_2_xoff", i);
699 p += ETH_GSTRING_LEN;
700 }
701 }
702 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
703 break;
704 }
705}
706
707static int i40e_get_ts_info(struct net_device *dev,
708 struct ethtool_ts_info *info)
709{
710 return ethtool_op_get_ts_info(dev, info);
711}
712
7b086397 713static int i40e_link_test(struct net_device *netdev, u64 *data)
c7d05ca8 714{
7b086397
SN
715 struct i40e_netdev_priv *np = netdev_priv(netdev);
716 struct i40e_pf *pf = np->vsi->back;
717
b03aaa9c 718 netif_info(pf, hw, netdev, "link test\n");
c7d05ca8
JB
719 if (i40e_get_link_status(&pf->hw))
720 *data = 0;
721 else
722 *data = 1;
723
724 return *data;
725}
726
7b086397 727static int i40e_reg_test(struct net_device *netdev, u64 *data)
c7d05ca8 728{
7b086397
SN
729 struct i40e_netdev_priv *np = netdev_priv(netdev);
730 struct i40e_pf *pf = np->vsi->back;
c7d05ca8 731
b03aaa9c 732 netif_info(pf, hw, netdev, "register test\n");
7b086397 733 *data = i40e_diag_reg_test(&pf->hw);
c7d05ca8 734
7b086397
SN
735 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
736 return *data;
c7d05ca8
JB
737}
738
7b086397 739static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
c7d05ca8 740{
7b086397
SN
741 struct i40e_netdev_priv *np = netdev_priv(netdev);
742 struct i40e_pf *pf = np->vsi->back;
c7d05ca8 743
b03aaa9c 744 netif_info(pf, hw, netdev, "eeprom test\n");
7b086397 745 *data = i40e_diag_eeprom_test(&pf->hw);
c7d05ca8 746
7b086397 747 return *data;
c7d05ca8
JB
748}
749
7b086397 750static int i40e_intr_test(struct net_device *netdev, u64 *data)
c7d05ca8 751{
7b086397
SN
752 struct i40e_netdev_priv *np = netdev_priv(netdev);
753 struct i40e_pf *pf = np->vsi->back;
cd92e72f
SN
754 u16 swc_old = pf->sw_int_count;
755
b03aaa9c 756 netif_info(pf, hw, netdev, "interrupt test\n");
cd92e72f
SN
757 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
758 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
759 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
760 usleep_range(1000, 2000);
761 *data = (swc_old == pf->sw_int_count);
c7d05ca8
JB
762
763 return *data;
764}
765
7b086397 766static int i40e_loopback_test(struct net_device *netdev, u64 *data)
c7d05ca8 767{
b03aaa9c
SN
768 struct i40e_netdev_priv *np = netdev_priv(netdev);
769 struct i40e_pf *pf = np->vsi->back;
770
771 netif_info(pf, hw, netdev, "loopback test not implemented\n");
cd92e72f 772 *data = 0;
c7d05ca8
JB
773
774 return *data;
775}
776
777static void i40e_diag_test(struct net_device *netdev,
778 struct ethtool_test *eth_test, u64 *data)
779{
780 struct i40e_netdev_priv *np = netdev_priv(netdev);
781 struct i40e_pf *pf = np->vsi->back;
782
783 set_bit(__I40E_TESTING, &pf->state);
784 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
785 /* Offline tests */
b03aaa9c 786 netif_info(pf, drv, netdev, "offline testing starting\n");
c7d05ca8
JB
787
788 /* Link test performed before hardware reset
789 * so autoneg doesn't interfere with test result
790 */
7b086397 791 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
c7d05ca8
JB
792 eth_test->flags |= ETH_TEST_FL_FAILED;
793
7b086397 794 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
c7d05ca8
JB
795 eth_test->flags |= ETH_TEST_FL_FAILED;
796
7b086397 797 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
c7d05ca8
JB
798 eth_test->flags |= ETH_TEST_FL_FAILED;
799
7b086397 800 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
c7d05ca8
JB
801 eth_test->flags |= ETH_TEST_FL_FAILED;
802
7b086397 803 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
c7d05ca8
JB
804 eth_test->flags |= ETH_TEST_FL_FAILED;
805
806 } else {
c7d05ca8 807 /* Online tests */
b03aaa9c
SN
808 netif_info(pf, drv, netdev, "online testing starting\n");
809
7b086397 810 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
c7d05ca8
JB
811 eth_test->flags |= ETH_TEST_FL_FAILED;
812
813 /* Offline only tests, not run in online; pass by default */
814 data[I40E_ETH_TEST_REG] = 0;
815 data[I40E_ETH_TEST_EEPROM] = 0;
816 data[I40E_ETH_TEST_INTR] = 0;
817 data[I40E_ETH_TEST_LOOPBACK] = 0;
c7d05ca8 818 }
c140c17b
SN
819 clear_bit(__I40E_TESTING, &pf->state);
820
b03aaa9c 821 netif_info(pf, drv, netdev, "testing finished\n");
c7d05ca8
JB
822}
823
824static void i40e_get_wol(struct net_device *netdev,
825 struct ethtool_wolinfo *wol)
826{
827 wol->supported = 0;
828 wol->wolopts = 0;
829}
830
831static int i40e_nway_reset(struct net_device *netdev)
832{
833 /* restart autonegotiation */
834 struct i40e_netdev_priv *np = netdev_priv(netdev);
835 struct i40e_pf *pf = np->vsi->back;
836 struct i40e_hw *hw = &pf->hw;
837 i40e_status ret = 0;
838
839 ret = i40e_aq_set_link_restart_an(hw, NULL);
840 if (ret) {
841 netdev_info(netdev, "link restart failed, aq_err=%d\n",
842 pf->hw.aq.asq_last_status);
843 return -EIO;
844 }
845
846 return 0;
847}
848
849static int i40e_set_phys_id(struct net_device *netdev,
850 enum ethtool_phys_id_state state)
851{
852 struct i40e_netdev_priv *np = netdev_priv(netdev);
853 struct i40e_pf *pf = np->vsi->back;
854 struct i40e_hw *hw = &pf->hw;
855 int blink_freq = 2;
856
857 switch (state) {
858 case ETHTOOL_ID_ACTIVE:
859 pf->led_status = i40e_led_get(hw);
860 return blink_freq;
861 case ETHTOOL_ID_ON:
862 i40e_led_set(hw, 0xF);
863 break;
864 case ETHTOOL_ID_OFF:
865 i40e_led_set(hw, 0x0);
866 break;
867 case ETHTOOL_ID_INACTIVE:
868 i40e_led_set(hw, pf->led_status);
869 break;
870 }
871
872 return 0;
873}
874
875/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
876 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
877 * 125us (8000 interrupts per second) == ITR(62)
878 */
879
880static int i40e_get_coalesce(struct net_device *netdev,
881 struct ethtool_coalesce *ec)
882{
883 struct i40e_netdev_priv *np = netdev_priv(netdev);
884 struct i40e_vsi *vsi = np->vsi;
885
886 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
887 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
888
889 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
890 ec->rx_coalesce_usecs = 1;
891 else
892 ec->rx_coalesce_usecs = vsi->rx_itr_setting;
893
894 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
895 ec->tx_coalesce_usecs = 1;
896 else
897 ec->tx_coalesce_usecs = vsi->tx_itr_setting;
898
899 return 0;
900}
901
902static int i40e_set_coalesce(struct net_device *netdev,
903 struct ethtool_coalesce *ec)
904{
905 struct i40e_netdev_priv *np = netdev_priv(netdev);
906 struct i40e_q_vector *q_vector;
907 struct i40e_vsi *vsi = np->vsi;
908 struct i40e_pf *pf = vsi->back;
909 struct i40e_hw *hw = &pf->hw;
910 u16 vector;
911 int i;
912
913 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
914 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
915
916 switch (ec->rx_coalesce_usecs) {
917 case 0:
918 vsi->rx_itr_setting = 0;
919 break;
920 case 1:
921 vsi->rx_itr_setting = (I40E_ITR_DYNAMIC |
922 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
923 break;
924 default:
925 if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
926 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)))
927 return -EINVAL;
928 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
929 break;
930 }
931
932 switch (ec->tx_coalesce_usecs) {
933 case 0:
934 vsi->tx_itr_setting = 0;
935 break;
936 case 1:
937 vsi->tx_itr_setting = (I40E_ITR_DYNAMIC |
938 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
939 break;
940 default:
941 if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
942 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)))
943 return -EINVAL;
944 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
945 break;
946 }
947
948 vector = vsi->base_vector;
493fb300
AD
949 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
950 q_vector = vsi->q_vectors[i];
c7d05ca8
JB
951 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
952 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
953 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
954 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
955 i40e_flush(hw);
956 }
957
958 return 0;
959}
960
961/**
962 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
963 * @pf: pointer to the physical function struct
964 * @cmd: ethtool rxnfc command
965 *
966 * Returns Success if the flow is supported, else Invalid Input.
967 **/
968static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
969{
970 cmd->data = 0;
971
972 /* Report default options for RSS on i40e */
973 switch (cmd->flow_type) {
974 case TCP_V4_FLOW:
975 case UDP_V4_FLOW:
976 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
977 /* fall through to add IP fields */
978 case SCTP_V4_FLOW:
979 case AH_ESP_V4_FLOW:
980 case AH_V4_FLOW:
981 case ESP_V4_FLOW:
982 case IPV4_FLOW:
983 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
984 break;
985 case TCP_V6_FLOW:
986 case UDP_V6_FLOW:
987 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
988 /* fall through to add IP fields */
989 case SCTP_V6_FLOW:
990 case AH_ESP_V6_FLOW:
991 case AH_V6_FLOW:
992 case ESP_V6_FLOW:
993 case IPV6_FLOW:
994 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
995 break;
996 default:
997 return -EINVAL;
998 }
999
1000 return 0;
1001}
1002
1003/**
1004 * i40e_get_rxnfc - command to get RX flow classification rules
1005 * @netdev: network interface device structure
1006 * @cmd: ethtool rxnfc command
1007 *
1008 * Returns Success if the command is supported.
1009 **/
1010static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1011 u32 *rule_locs)
1012{
1013 struct i40e_netdev_priv *np = netdev_priv(netdev);
1014 struct i40e_vsi *vsi = np->vsi;
1015 struct i40e_pf *pf = vsi->back;
1016 int ret = -EOPNOTSUPP;
1017
1018 switch (cmd->cmd) {
1019 case ETHTOOL_GRXRINGS:
1020 cmd->data = vsi->alloc_queue_pairs;
1021 ret = 0;
1022 break;
1023 case ETHTOOL_GRXFH:
1024 ret = i40e_get_rss_hash_opts(pf, cmd);
1025 break;
1026 case ETHTOOL_GRXCLSRLCNT:
1027 ret = 0;
1028 break;
1029 case ETHTOOL_GRXCLSRULE:
1030 ret = 0;
1031 break;
1032 case ETHTOOL_GRXCLSRLALL:
1033 cmd->data = 500;
1034 ret = 0;
1035 default:
1036 break;
1037 }
1038
1039 return ret;
1040}
1041
1042/**
1043 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1044 * @pf: pointer to the physical function struct
1045 * @cmd: ethtool rxnfc command
1046 *
1047 * Returns Success if the flow input set is supported.
1048 **/
1049static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1050{
1051 struct i40e_hw *hw = &pf->hw;
1052 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1053 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1054
1055 /* RSS does not support anything other than hashing
1056 * to queues on src and dst IPs and ports
1057 */
1058 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1059 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1060 return -EINVAL;
1061
1062 /* We need at least the IP SRC and DEST fields for hashing */
1063 if (!(nfc->data & RXH_IP_SRC) ||
1064 !(nfc->data & RXH_IP_DST))
1065 return -EINVAL;
1066
1067 switch (nfc->flow_type) {
1068 case TCP_V4_FLOW:
1069 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1070 case 0:
1071 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1072 break;
1073 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1074 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1075 break;
1076 default:
1077 return -EINVAL;
1078 }
1079 break;
1080 case TCP_V6_FLOW:
1081 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1082 case 0:
1083 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1084 break;
1085 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1086 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1087 break;
1088 default:
1089 return -EINVAL;
1090 }
1091 break;
1092 case UDP_V4_FLOW:
1093 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1094 case 0:
1095 hena &=
1096 ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
1097 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
1098 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1099 break;
1100 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1101 hena |=
1102 (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
1103 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
1104 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1105 break;
1106 default:
1107 return -EINVAL;
1108 }
1109 break;
1110 case UDP_V6_FLOW:
1111 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1112 case 0:
1113 hena &=
1114 ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
1115 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
1116 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1117 break;
1118 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1119 hena |=
1120 (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
1121 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
1122 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1123 break;
1124 default:
1125 return -EINVAL;
1126 }
1127 break;
1128 case AH_ESP_V4_FLOW:
1129 case AH_V4_FLOW:
1130 case ESP_V4_FLOW:
1131 case SCTP_V4_FLOW:
1132 if ((nfc->data & RXH_L4_B_0_1) ||
1133 (nfc->data & RXH_L4_B_2_3))
1134 return -EINVAL;
1135 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1136 break;
1137 case AH_ESP_V6_FLOW:
1138 case AH_V6_FLOW:
1139 case ESP_V6_FLOW:
1140 case SCTP_V6_FLOW:
1141 if ((nfc->data & RXH_L4_B_0_1) ||
1142 (nfc->data & RXH_L4_B_2_3))
1143 return -EINVAL;
1144 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1145 break;
1146 case IPV4_FLOW:
1147 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1148 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1149 break;
1150 case IPV6_FLOW:
1151 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1152 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1153 break;
1154 default:
1155 return -EINVAL;
1156 }
1157
1158 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1159 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1160 i40e_flush(hw);
1161
1162 return 0;
1163}
1164
1165#define IP_HEADER_OFFSET 14
1166/**
1167 * i40e_add_del_fdir_udpv4 - Add/Remove UDPv4 Flow Director filters for
1168 * a specific flow spec
1169 * @vsi: pointer to the targeted VSI
1170 * @fd_data: the flow director data required from the FDir descriptor
1171 * @ethtool_rx_flow_spec: the flow spec
1172 * @add: true adds a filter, false removes it
1173 *
1174 * Returns 0 if the filters were successfully added or removed
1175 **/
1176static int i40e_add_del_fdir_udpv4(struct i40e_vsi *vsi,
1177 struct i40e_fdir_data *fd_data,
1178 struct ethtool_rx_flow_spec *fsp, bool add)
1179{
1180 struct i40e_pf *pf = vsi->back;
1181 struct udphdr *udp;
1182 struct iphdr *ip;
1183 bool err = false;
1184 int ret;
1185 int i;
1186
1187 ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
1188 udp = (struct udphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET
1189 + sizeof(struct iphdr));
1190
1191 ip->saddr = fsp->h_u.tcp_ip4_spec.ip4src;
1192 ip->daddr = fsp->h_u.tcp_ip4_spec.ip4dst;
1193 udp->source = fsp->h_u.tcp_ip4_spec.psrc;
1194 udp->dest = fsp->h_u.tcp_ip4_spec.pdst;
1195
1196 for (i = I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP;
1197 i <= I40E_FILTER_PCTYPE_NONF_IPV4_UDP; i++) {
1198 fd_data->pctype = i;
1199 ret = i40e_program_fdir_filter(fd_data, pf, add);
1200
1201 if (ret) {
1202 dev_info(&pf->pdev->dev,
1203 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1204 fd_data->pctype, ret);
1205 err = true;
1206 } else {
1207 dev_info(&pf->pdev->dev,
1208 "Filter OK for PCTYPE %d (ret = %d)\n",
1209 fd_data->pctype, ret);
1210 }
1211 }
1212
1213 return err ? -EOPNOTSUPP : 0;
1214}
1215
1216/**
1217 * i40e_add_del_fdir_tcpv4 - Add/Remove TCPv4 Flow Director filters for
1218 * a specific flow spec
1219 * @vsi: pointer to the targeted VSI
1220 * @fd_data: the flow director data required from the FDir descriptor
1221 * @ethtool_rx_flow_spec: the flow spec
1222 * @add: true adds a filter, false removes it
1223 *
1224 * Returns 0 if the filters were successfully added or removed
1225 **/
1226static int i40e_add_del_fdir_tcpv4(struct i40e_vsi *vsi,
1227 struct i40e_fdir_data *fd_data,
1228 struct ethtool_rx_flow_spec *fsp, bool add)
1229{
1230 struct i40e_pf *pf = vsi->back;
1231 struct tcphdr *tcp;
1232 struct iphdr *ip;
1233 bool err = false;
1234 int ret;
1235
1236 ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
1237 tcp = (struct tcphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET
1238 + sizeof(struct iphdr));
1239
1240 ip->daddr = fsp->h_u.tcp_ip4_spec.ip4dst;
1241 tcp->dest = fsp->h_u.tcp_ip4_spec.pdst;
1242
1243 fd_data->pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN;
1244 ret = i40e_program_fdir_filter(fd_data, pf, add);
1245
1246 if (ret) {
1247 dev_info(&pf->pdev->dev,
1248 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1249 fd_data->pctype, ret);
1250 err = true;
1251 } else {
1252 dev_info(&pf->pdev->dev, "Filter OK for PCTYPE %d (ret = %d)\n",
1253 fd_data->pctype, ret);
1254 }
1255
1256 ip->saddr = fsp->h_u.tcp_ip4_spec.ip4src;
1257 tcp->source = fsp->h_u.tcp_ip4_spec.psrc;
1258
1259 fd_data->pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
1260
1261 ret = i40e_program_fdir_filter(fd_data, pf, add);
1262 if (ret) {
1263 dev_info(&pf->pdev->dev,
1264 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1265 fd_data->pctype, ret);
1266 err = true;
1267 } else {
1268 dev_info(&pf->pdev->dev, "Filter OK for PCTYPE %d (ret = %d)\n",
1269 fd_data->pctype, ret);
1270 }
1271
1272 return err ? -EOPNOTSUPP : 0;
1273}
1274
1275/**
1276 * i40e_add_del_fdir_sctpv4 - Add/Remove SCTPv4 Flow Director filters for
1277 * a specific flow spec
1278 * @vsi: pointer to the targeted VSI
1279 * @fd_data: the flow director data required from the FDir descriptor
1280 * @ethtool_rx_flow_spec: the flow spec
1281 * @add: true adds a filter, false removes it
1282 *
1283 * Returns 0 if the filters were successfully added or removed
1284 **/
1285static int i40e_add_del_fdir_sctpv4(struct i40e_vsi *vsi,
1286 struct i40e_fdir_data *fd_data,
1287 struct ethtool_rx_flow_spec *fsp, bool add)
1288{
1289 return -EOPNOTSUPP;
1290}
1291
1292/**
1293 * i40e_add_del_fdir_ipv4 - Add/Remove IPv4 Flow Director filters for
1294 * a specific flow spec
1295 * @vsi: pointer to the targeted VSI
1296 * @fd_data: the flow director data required for the FDir descriptor
1297 * @fsp: the ethtool flow spec
1298 * @add: true adds a filter, false removes it
1299 *
1300 * Returns 0 if the filters were successfully added or removed
1301 **/
1302static int i40e_add_del_fdir_ipv4(struct i40e_vsi *vsi,
1303 struct i40e_fdir_data *fd_data,
1304 struct ethtool_rx_flow_spec *fsp, bool add)
1305{
1306 struct i40e_pf *pf = vsi->back;
1307 struct iphdr *ip;
1308 bool err = false;
1309 int ret;
1310 int i;
1311
1312 ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
1313
1314 ip->saddr = fsp->h_u.usr_ip4_spec.ip4src;
1315 ip->daddr = fsp->h_u.usr_ip4_spec.ip4dst;
1316 ip->protocol = fsp->h_u.usr_ip4_spec.proto;
1317
1318 for (i = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
1319 i <= I40E_FILTER_PCTYPE_FRAG_IPV4; i++) {
1320 fd_data->pctype = i;
1321 ret = i40e_program_fdir_filter(fd_data, pf, add);
1322
1323 if (ret) {
1324 dev_info(&pf->pdev->dev,
1325 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1326 fd_data->pctype, ret);
1327 err = true;
1328 } else {
1329 dev_info(&pf->pdev->dev,
1330 "Filter OK for PCTYPE %d (ret = %d)\n",
1331 fd_data->pctype, ret);
1332 }
1333 }
1334
1335 return err ? -EOPNOTSUPP : 0;
1336}
1337
1338/**
1339 * i40e_add_del_fdir_ethtool - Add/Remove Flow Director filters for
1340 * a specific flow spec based on their protocol
1341 * @vsi: pointer to the targeted VSI
1342 * @cmd: command to get or set RX flow classification rules
1343 * @add: true adds a filter, false removes it
1344 *
1345 * Returns 0 if the filters were successfully added or removed
1346 **/
1347static int i40e_add_del_fdir_ethtool(struct i40e_vsi *vsi,
1348 struct ethtool_rxnfc *cmd, bool add)
1349{
1350 struct i40e_fdir_data fd_data;
1351 int ret = -EINVAL;
1352 struct i40e_pf *pf;
1353 struct ethtool_rx_flow_spec *fsp =
1354 (struct ethtool_rx_flow_spec *)&cmd->fs;
1355
1356 if (!vsi)
1357 return -EINVAL;
1358
1359 pf = vsi->back;
1360
1361 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
1362 (fsp->ring_cookie >= vsi->num_queue_pairs))
1363 return -EINVAL;
1364
1365 /* Populate the Flow Director that we have at the moment
1366 * and allocate the raw packet buffer for the calling functions
1367 */
1368 fd_data.raw_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_LOOKUP,
1369 GFP_KERNEL);
1370
1371 if (!fd_data.raw_packet) {
1372 dev_info(&pf->pdev->dev, "Could not allocate memory\n");
1373 return -ENOMEM;
1374 }
1375
1376 fd_data.q_index = fsp->ring_cookie;
1377 fd_data.flex_off = 0;
1378 fd_data.pctype = 0;
1379 fd_data.dest_vsi = vsi->id;
1380 fd_data.dest_ctl = 0;
1381 fd_data.fd_status = 0;
1382 fd_data.cnt_index = 0;
1383 fd_data.fd_id = 0;
1384
1385 switch (fsp->flow_type & ~FLOW_EXT) {
1386 case TCP_V4_FLOW:
1387 ret = i40e_add_del_fdir_tcpv4(vsi, &fd_data, fsp, add);
1388 break;
1389 case UDP_V4_FLOW:
1390 ret = i40e_add_del_fdir_udpv4(vsi, &fd_data, fsp, add);
1391 break;
1392 case SCTP_V4_FLOW:
1393 ret = i40e_add_del_fdir_sctpv4(vsi, &fd_data, fsp, add);
1394 break;
1395 case IPV4_FLOW:
1396 ret = i40e_add_del_fdir_ipv4(vsi, &fd_data, fsp, add);
1397 break;
1398 case IP_USER_FLOW:
1399 switch (fsp->h_u.usr_ip4_spec.proto) {
1400 case IPPROTO_TCP:
1401 ret = i40e_add_del_fdir_tcpv4(vsi, &fd_data, fsp, add);
1402 break;
1403 case IPPROTO_UDP:
1404 ret = i40e_add_del_fdir_udpv4(vsi, &fd_data, fsp, add);
1405 break;
1406 case IPPROTO_SCTP:
1407 ret = i40e_add_del_fdir_sctpv4(vsi, &fd_data, fsp, add);
1408 break;
1409 default:
1410 ret = i40e_add_del_fdir_ipv4(vsi, &fd_data, fsp, add);
1411 break;
1412 }
1413 break;
1414 default:
1415 dev_info(&pf->pdev->dev, "Could not specify spec type\n");
1416 ret = -EINVAL;
1417 }
1418
1419 kfree(fd_data.raw_packet);
1420 fd_data.raw_packet = NULL;
1421
1422 return ret;
1423}
1424/**
1425 * i40e_set_rxnfc - command to set RX flow classification rules
1426 * @netdev: network interface device structure
1427 * @cmd: ethtool rxnfc command
1428 *
1429 * Returns Success if the command is supported.
1430 **/
1431static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1432{
1433 struct i40e_netdev_priv *np = netdev_priv(netdev);
1434 struct i40e_vsi *vsi = np->vsi;
1435 struct i40e_pf *pf = vsi->back;
1436 int ret = -EOPNOTSUPP;
1437
1438 switch (cmd->cmd) {
1439 case ETHTOOL_SRXFH:
1440 ret = i40e_set_rss_hash_opt(pf, cmd);
1441 break;
1442 case ETHTOOL_SRXCLSRLINS:
1443 ret = i40e_add_del_fdir_ethtool(vsi, cmd, true);
1444 break;
1445 case ETHTOOL_SRXCLSRLDEL:
1446 ret = i40e_add_del_fdir_ethtool(vsi, cmd, false);
1447 break;
1448 default:
1449 break;
1450 }
1451
1452 return ret;
1453}
1454
1455static const struct ethtool_ops i40e_ethtool_ops = {
1456 .get_settings = i40e_get_settings,
1457 .get_drvinfo = i40e_get_drvinfo,
1458 .get_regs_len = i40e_get_regs_len,
1459 .get_regs = i40e_get_regs,
1460 .nway_reset = i40e_nway_reset,
1461 .get_link = ethtool_op_get_link,
1462 .get_wol = i40e_get_wol,
1463 .get_eeprom_len = i40e_get_eeprom_len,
1464 .get_eeprom = i40e_get_eeprom,
1465 .get_ringparam = i40e_get_ringparam,
1466 .set_ringparam = i40e_set_ringparam,
1467 .get_pauseparam = i40e_get_pauseparam,
1468 .get_msglevel = i40e_get_msglevel,
1469 .set_msglevel = i40e_set_msglevel,
1470 .get_rxnfc = i40e_get_rxnfc,
1471 .set_rxnfc = i40e_set_rxnfc,
1472 .self_test = i40e_diag_test,
1473 .get_strings = i40e_get_strings,
1474 .set_phys_id = i40e_set_phys_id,
1475 .get_sset_count = i40e_get_sset_count,
1476 .get_ethtool_stats = i40e_get_ethtool_stats,
1477 .get_coalesce = i40e_get_coalesce,
1478 .set_coalesce = i40e_set_coalesce,
1479 .get_ts_info = i40e_get_ts_info,
1480};
1481
1482void i40e_set_ethtool_ops(struct net_device *netdev)
1483{
1484 SET_ETHTOOL_OPS(netdev, &i40e_ethtool_ops);
1485}
This page took 0.12378 seconds and 5 git commands to generate.