1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 Intel Corporation.
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.
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
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.
19 * The full GNU General Public License is included in this distribution in
20 * the file called "COPYING".
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
26 ******************************************************************************/
28 /* ethtool support for i40e */
31 #include "i40e_diag.h"
34 char stat_string
[ETH_GSTRING_LEN
];
39 #define I40E_STAT(_type, _name, _stat) { \
40 .stat_string = _name, \
41 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
42 .stat_offset = offsetof(_type, _stat) \
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)
51 static 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
),
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.
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.
76 static 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
),
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)) \
128 #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
129 I40E_PFC_STATS_LEN + \
130 I40E_VSI_STATS_LEN((n)))
132 enum i40e_ethtool_test_id
{
133 I40E_ETH_TEST_REG
= 0,
134 I40E_ETH_TEST_EEPROM
,
136 I40E_ETH_TEST_LOOPBACK
,
140 static 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)"
148 #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
151 * i40e_get_settings - Get Link Speed and Duplex settings
152 * @netdev: network interface device structure
153 * @ecmd: ethtool command
155 * Reports speed/duplex settings based on media_type
157 static int i40e_get_settings(struct net_device
*netdev
,
158 struct ethtool_cmd
*ecmd
)
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
;
167 /* hardware is either in 40G mode or 10G mode
168 * NOTE: this section initializes supported and advertising
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
;
176 case I40E_PHY_TYPE_40GBASE_KR4
:
177 ecmd
->supported
= SUPPORTED_40000baseKR4_Full
;
178 ecmd
->advertising
= ADVERTISED_40000baseKR4_Full
;
180 case I40E_PHY_TYPE_40GBASE_SR4
:
181 ecmd
->supported
= SUPPORTED_40000baseSR4_Full
;
182 ecmd
->advertising
= ADVERTISED_40000baseSR4_Full
;
184 case I40E_PHY_TYPE_40GBASE_LR4
:
185 ecmd
->supported
= SUPPORTED_40000baseLR4_Full
;
186 ecmd
->advertising
= ADVERTISED_40000baseLR4_Full
;
188 case I40E_PHY_TYPE_10GBASE_KX4
:
189 ecmd
->supported
= SUPPORTED_10000baseKX4_Full
;
190 ecmd
->advertising
= ADVERTISED_10000baseKX4_Full
;
192 case I40E_PHY_TYPE_10GBASE_KR
:
193 ecmd
->supported
= SUPPORTED_10000baseKR_Full
;
194 ecmd
->advertising
= ADVERTISED_10000baseKR_Full
;
197 if (i40e_is_40G_device(hw
->device_id
)) {
198 ecmd
->supported
= SUPPORTED_40000baseSR4_Full
;
199 ecmd
->advertising
= ADVERTISED_40000baseSR4_Full
;
201 ecmd
->supported
= SUPPORTED_10000baseT_Full
;
202 ecmd
->advertising
= ADVERTISED_10000baseT_Full
;
207 ecmd
->supported
|= SUPPORTED_Autoneg
;
208 ecmd
->advertising
|= ADVERTISED_Autoneg
;
209 ecmd
->autoneg
= ((hw_link_info
->an_info
& I40E_AQ_AN_COMPLETED
) ?
210 AUTONEG_ENABLE
: AUTONEG_DISABLE
);
212 switch (hw
->phy
.media_type
) {
213 case I40E_MEDIA_TYPE_BACKPLANE
:
214 ecmd
->supported
|= SUPPORTED_Backplane
;
215 ecmd
->advertising
|= ADVERTISED_Backplane
;
216 ecmd
->port
= PORT_NONE
;
218 case I40E_MEDIA_TYPE_BASET
:
219 ecmd
->supported
|= SUPPORTED_TP
;
220 ecmd
->advertising
|= ADVERTISED_TP
;
221 ecmd
->port
= PORT_TP
;
223 case I40E_MEDIA_TYPE_DA
:
224 case I40E_MEDIA_TYPE_CX4
:
225 ecmd
->supported
|= SUPPORTED_FIBRE
;
226 ecmd
->advertising
|= ADVERTISED_FIBRE
;
227 ecmd
->port
= PORT_DA
;
229 case I40E_MEDIA_TYPE_FIBER
:
230 ecmd
->supported
|= SUPPORTED_FIBRE
;
231 ecmd
->advertising
|= ADVERTISED_FIBRE
;
232 ecmd
->port
= PORT_FIBRE
;
234 case I40E_MEDIA_TYPE_UNKNOWN
:
236 ecmd
->port
= PORT_OTHER
;
240 ecmd
->transceiver
= XCVR_EXTERNAL
;
243 switch (link_speed
) {
244 case I40E_LINK_SPEED_40GB
:
245 /* need a SPEED_40000 in ethtool.h */
246 ethtool_cmd_speed_set(ecmd
, 40000);
248 case I40E_LINK_SPEED_10GB
:
249 ethtool_cmd_speed_set(ecmd
, SPEED_10000
);
254 ecmd
->duplex
= DUPLEX_FULL
;
256 ethtool_cmd_speed_set(ecmd
, SPEED_UNKNOWN
);
257 ecmd
->duplex
= DUPLEX_UNKNOWN
;
264 * i40e_get_pauseparam - Get Flow Control status
265 * Return tx/rx-pause status
267 static void i40e_get_pauseparam(struct net_device
*netdev
,
268 struct ethtool_pauseparam
*pause
)
270 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
271 struct i40e_pf
*pf
= np
->vsi
->back
;
272 struct i40e_hw
*hw
= &pf
->hw
;
273 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
276 ((hw_link_info
->an_info
& I40E_AQ_AN_COMPLETED
) ?
277 AUTONEG_ENABLE
: AUTONEG_DISABLE
);
279 if (hw
->fc
.current_mode
== I40E_FC_RX_PAUSE
) {
281 } else if (hw
->fc
.current_mode
== I40E_FC_TX_PAUSE
) {
283 } else if (hw
->fc
.current_mode
== I40E_FC_FULL
) {
289 static u32
i40e_get_msglevel(struct net_device
*netdev
)
291 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
292 struct i40e_pf
*pf
= np
->vsi
->back
;
294 return pf
->msg_enable
;
297 static void i40e_set_msglevel(struct net_device
*netdev
, u32 data
)
299 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
300 struct i40e_pf
*pf
= np
->vsi
->back
;
302 if (I40E_DEBUG_USER
& data
)
303 pf
->hw
.debug_mask
= data
;
304 pf
->msg_enable
= data
;
307 static int i40e_get_regs_len(struct net_device
*netdev
)
312 for (i
= 0; i40e_reg_list
[i
].offset
!= 0; i
++)
313 reg_count
+= i40e_reg_list
[i
].elements
;
315 return reg_count
* sizeof(u32
);
318 static void i40e_get_regs(struct net_device
*netdev
, struct ethtool_regs
*regs
,
321 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
322 struct i40e_pf
*pf
= np
->vsi
->back
;
323 struct i40e_hw
*hw
= &pf
->hw
;
328 /* Tell ethtool which driver-version-specific regs output we have.
330 * At some point, if we have ethtool doing special formatting of
331 * this data, it will rely on this version number to know how to
332 * interpret things. Hence, this needs to be updated if/when the
333 * diags register table is changed.
337 /* loop through the diags reg table for what to print */
339 for (i
= 0; i40e_reg_list
[i
].offset
!= 0; i
++) {
340 for (j
= 0; j
< i40e_reg_list
[i
].elements
; j
++) {
341 reg
= i40e_reg_list
[i
].offset
342 + (j
* i40e_reg_list
[i
].stride
);
343 reg_buf
[ri
++] = rd32(hw
, reg
);
349 static int i40e_get_eeprom(struct net_device
*netdev
,
350 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
352 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
353 struct i40e_hw
*hw
= &np
->vsi
->back
->hw
;
354 struct i40e_pf
*pf
= np
->vsi
->back
;
355 int ret_val
= 0, len
;
359 #define I40E_NVM_SECTOR_SIZE 4096
360 if (eeprom
->len
== 0)
363 eeprom
->magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
365 eeprom_buff
= kzalloc(eeprom
->len
, GFP_KERNEL
);
369 ret_val
= i40e_acquire_nvm(hw
, I40E_RESOURCE_READ
);
371 dev_info(&pf
->pdev
->dev
,
372 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
373 ret_val
, hw
->aq
.asq_last_status
);
377 sectors
= eeprom
->len
/ I40E_NVM_SECTOR_SIZE
;
378 sectors
+= (eeprom
->len
% I40E_NVM_SECTOR_SIZE
) ? 1 : 0;
379 len
= I40E_NVM_SECTOR_SIZE
;
381 for (i
= 0; i
< sectors
; i
++) {
382 if (i
== (sectors
- 1)) {
383 len
= eeprom
->len
- (I40E_NVM_SECTOR_SIZE
* i
);
386 ret_val
= i40e_aq_read_nvm(hw
, 0x0,
387 eeprom
->offset
+ (I40E_NVM_SECTOR_SIZE
* i
),
389 (u8
*)eeprom_buff
+ (I40E_NVM_SECTOR_SIZE
* i
),
392 dev_info(&pf
->pdev
->dev
,
393 "read NVM failed err=%d status=0x%x\n",
394 ret_val
, hw
->aq
.asq_last_status
);
400 i40e_release_nvm(hw
);
401 memcpy(bytes
, (u8
*)eeprom_buff
, eeprom
->len
);
407 static int i40e_get_eeprom_len(struct net_device
*netdev
)
409 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
410 struct i40e_hw
*hw
= &np
->vsi
->back
->hw
;
413 val
= (rd32(hw
, I40E_GLPCI_LBARCTRL
)
414 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK
)
415 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT
;
416 /* register returns value in power of 2, 64Kbyte chunks. */
417 val
= (64 * 1024) * (1 << val
);
421 static void i40e_get_drvinfo(struct net_device
*netdev
,
422 struct ethtool_drvinfo
*drvinfo
)
424 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
425 struct i40e_vsi
*vsi
= np
->vsi
;
426 struct i40e_pf
*pf
= vsi
->back
;
428 strlcpy(drvinfo
->driver
, i40e_driver_name
, sizeof(drvinfo
->driver
));
429 strlcpy(drvinfo
->version
, i40e_driver_version_str
,
430 sizeof(drvinfo
->version
));
431 strlcpy(drvinfo
->fw_version
, i40e_fw_version_str(&pf
->hw
),
432 sizeof(drvinfo
->fw_version
));
433 strlcpy(drvinfo
->bus_info
, pci_name(pf
->pdev
),
434 sizeof(drvinfo
->bus_info
));
437 static void i40e_get_ringparam(struct net_device
*netdev
,
438 struct ethtool_ringparam
*ring
)
440 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
441 struct i40e_pf
*pf
= np
->vsi
->back
;
442 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
444 ring
->rx_max_pending
= I40E_MAX_NUM_DESCRIPTORS
;
445 ring
->tx_max_pending
= I40E_MAX_NUM_DESCRIPTORS
;
446 ring
->rx_mini_max_pending
= 0;
447 ring
->rx_jumbo_max_pending
= 0;
448 ring
->rx_pending
= vsi
->rx_rings
[0]->count
;
449 ring
->tx_pending
= vsi
->tx_rings
[0]->count
;
450 ring
->rx_mini_pending
= 0;
451 ring
->rx_jumbo_pending
= 0;
454 static int i40e_set_ringparam(struct net_device
*netdev
,
455 struct ethtool_ringparam
*ring
)
457 struct i40e_ring
*tx_rings
= NULL
, *rx_rings
= NULL
;
458 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
459 struct i40e_vsi
*vsi
= np
->vsi
;
460 struct i40e_pf
*pf
= vsi
->back
;
461 u32 new_rx_count
, new_tx_count
;
464 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
467 if (ring
->tx_pending
> I40E_MAX_NUM_DESCRIPTORS
||
468 ring
->tx_pending
< I40E_MIN_NUM_DESCRIPTORS
||
469 ring
->rx_pending
> I40E_MAX_NUM_DESCRIPTORS
||
470 ring
->rx_pending
< I40E_MIN_NUM_DESCRIPTORS
) {
472 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
473 ring
->tx_pending
, ring
->rx_pending
,
474 I40E_MIN_NUM_DESCRIPTORS
, I40E_MAX_NUM_DESCRIPTORS
);
478 new_tx_count
= ALIGN(ring
->tx_pending
, I40E_REQ_DESCRIPTOR_MULTIPLE
);
479 new_rx_count
= ALIGN(ring
->rx_pending
, I40E_REQ_DESCRIPTOR_MULTIPLE
);
481 /* if nothing to do return success */
482 if ((new_tx_count
== vsi
->tx_rings
[0]->count
) &&
483 (new_rx_count
== vsi
->rx_rings
[0]->count
))
486 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
487 usleep_range(1000, 2000);
489 if (!netif_running(vsi
->netdev
)) {
490 /* simple case - set for the next time the netdev is started */
491 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
492 vsi
->tx_rings
[i
]->count
= new_tx_count
;
493 vsi
->rx_rings
[i
]->count
= new_rx_count
;
498 /* We can't just free everything and then setup again,
499 * because the ISRs in MSI-X mode get passed pointers
500 * to the Tx and Rx ring structs.
503 /* alloc updated Tx resources */
504 if (new_tx_count
!= vsi
->tx_rings
[0]->count
) {
506 "Changing Tx descriptor count from %d to %d.\n",
507 vsi
->tx_rings
[0]->count
, new_tx_count
);
508 tx_rings
= kcalloc(vsi
->alloc_queue_pairs
,
509 sizeof(struct i40e_ring
), GFP_KERNEL
);
515 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
516 /* clone ring and setup updated count */
517 tx_rings
[i
] = *vsi
->tx_rings
[i
];
518 tx_rings
[i
].count
= new_tx_count
;
519 err
= i40e_setup_tx_descriptors(&tx_rings
[i
]);
523 i40e_free_tx_resources(&tx_rings
[i
]);
533 /* alloc updated Rx resources */
534 if (new_rx_count
!= vsi
->rx_rings
[0]->count
) {
536 "Changing Rx descriptor count from %d to %d\n",
537 vsi
->rx_rings
[0]->count
, new_rx_count
);
538 rx_rings
= kcalloc(vsi
->alloc_queue_pairs
,
539 sizeof(struct i40e_ring
), GFP_KERNEL
);
545 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
546 /* clone ring and setup updated count */
547 rx_rings
[i
] = *vsi
->rx_rings
[i
];
548 rx_rings
[i
].count
= new_rx_count
;
549 err
= i40e_setup_rx_descriptors(&rx_rings
[i
]);
553 i40e_free_rx_resources(&rx_rings
[i
]);
563 /* Bring interface down, copy in the new ring info,
564 * then restore the interface
569 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
570 i40e_free_tx_resources(vsi
->tx_rings
[i
]);
571 *vsi
->tx_rings
[i
] = tx_rings
[i
];
578 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
579 i40e_free_rx_resources(vsi
->rx_rings
[i
]);
580 *vsi
->rx_rings
[i
] = rx_rings
[i
];
589 /* error cleanup if the Rx allocations failed after getting Tx */
591 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
592 i40e_free_tx_resources(&tx_rings
[i
]);
598 clear_bit(__I40E_CONFIG_BUSY
, &pf
->state
);
603 static int i40e_get_sset_count(struct net_device
*netdev
, int sset
)
605 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
606 struct i40e_vsi
*vsi
= np
->vsi
;
607 struct i40e_pf
*pf
= vsi
->back
;
611 return I40E_TEST_LEN
;
613 if (vsi
== pf
->vsi
[pf
->lan_vsi
])
614 return I40E_PF_STATS_LEN(netdev
);
616 return I40E_VSI_STATS_LEN(netdev
);
622 static void i40e_get_ethtool_stats(struct net_device
*netdev
,
623 struct ethtool_stats
*stats
, u64
*data
)
625 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
626 struct i40e_vsi
*vsi
= np
->vsi
;
627 struct i40e_pf
*pf
= vsi
->back
;
631 struct rtnl_link_stats64
*net_stats
= i40e_get_vsi_stats_struct(vsi
);
634 i40e_update_stats(vsi
);
636 for (j
= 0; j
< I40E_NETDEV_STATS_LEN
; j
++) {
637 p
= (char *)net_stats
+ i40e_gstrings_net_stats
[j
].stat_offset
;
638 data
[i
++] = (i40e_gstrings_net_stats
[j
].sizeof_stat
==
639 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
642 for (j
= 0; j
< vsi
->num_queue_pairs
; j
++, i
+= 4) {
643 struct i40e_ring
*tx_ring
= ACCESS_ONCE(vsi
->tx_rings
[j
]);
644 struct i40e_ring
*rx_ring
;
649 /* process Tx ring statistics */
651 start
= u64_stats_fetch_begin_bh(&tx_ring
->syncp
);
652 data
[i
] = tx_ring
->stats
.packets
;
653 data
[i
+ 1] = tx_ring
->stats
.bytes
;
654 } while (u64_stats_fetch_retry_bh(&tx_ring
->syncp
, start
));
656 /* Rx ring is the 2nd half of the queue pair */
657 rx_ring
= &tx_ring
[1];
659 start
= u64_stats_fetch_begin_bh(&rx_ring
->syncp
);
660 data
[i
+ 2] = rx_ring
->stats
.packets
;
661 data
[i
+ 3] = rx_ring
->stats
.bytes
;
662 } while (u64_stats_fetch_retry_bh(&rx_ring
->syncp
, start
));
665 if (vsi
== pf
->vsi
[pf
->lan_vsi
]) {
666 for (j
= 0; j
< I40E_GLOBAL_STATS_LEN
; j
++) {
667 p
= (char *)pf
+ i40e_gstrings_stats
[j
].stat_offset
;
668 data
[i
++] = (i40e_gstrings_stats
[j
].sizeof_stat
==
669 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
671 for (j
= 0; j
< I40E_MAX_USER_PRIORITY
; j
++) {
672 data
[i
++] = pf
->stats
.priority_xon_tx
[j
];
673 data
[i
++] = pf
->stats
.priority_xoff_tx
[j
];
675 for (j
= 0; j
< I40E_MAX_USER_PRIORITY
; j
++) {
676 data
[i
++] = pf
->stats
.priority_xon_rx
[j
];
677 data
[i
++] = pf
->stats
.priority_xoff_rx
[j
];
679 for (j
= 0; j
< I40E_MAX_USER_PRIORITY
; j
++)
680 data
[i
++] = pf
->stats
.priority_xon_2_xoff
[j
];
684 static void i40e_get_strings(struct net_device
*netdev
, u32 stringset
,
687 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
688 struct i40e_vsi
*vsi
= np
->vsi
;
689 struct i40e_pf
*pf
= vsi
->back
;
690 char *p
= (char *)data
;
695 for (i
= 0; i
< I40E_TEST_LEN
; i
++) {
696 memcpy(data
, i40e_gstrings_test
[i
], ETH_GSTRING_LEN
);
697 data
+= ETH_GSTRING_LEN
;
701 for (i
= 0; i
< I40E_NETDEV_STATS_LEN
; i
++) {
702 snprintf(p
, ETH_GSTRING_LEN
, "%s",
703 i40e_gstrings_net_stats
[i
].stat_string
);
704 p
+= ETH_GSTRING_LEN
;
706 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
707 snprintf(p
, ETH_GSTRING_LEN
, "tx-%u.tx_packets", i
);
708 p
+= ETH_GSTRING_LEN
;
709 snprintf(p
, ETH_GSTRING_LEN
, "tx-%u.tx_bytes", i
);
710 p
+= ETH_GSTRING_LEN
;
711 snprintf(p
, ETH_GSTRING_LEN
, "rx-%u.rx_packets", i
);
712 p
+= ETH_GSTRING_LEN
;
713 snprintf(p
, ETH_GSTRING_LEN
, "rx-%u.rx_bytes", i
);
714 p
+= ETH_GSTRING_LEN
;
716 if (vsi
== pf
->vsi
[pf
->lan_vsi
]) {
717 for (i
= 0; i
< I40E_GLOBAL_STATS_LEN
; i
++) {
718 snprintf(p
, ETH_GSTRING_LEN
, "port.%s",
719 i40e_gstrings_stats
[i
].stat_string
);
720 p
+= ETH_GSTRING_LEN
;
722 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
723 snprintf(p
, ETH_GSTRING_LEN
,
724 "port.tx_priority_%u_xon", i
);
725 p
+= ETH_GSTRING_LEN
;
726 snprintf(p
, ETH_GSTRING_LEN
,
727 "port.tx_priority_%u_xoff", i
);
728 p
+= ETH_GSTRING_LEN
;
730 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
731 snprintf(p
, ETH_GSTRING_LEN
,
732 "port.rx_priority_%u_xon", i
);
733 p
+= ETH_GSTRING_LEN
;
734 snprintf(p
, ETH_GSTRING_LEN
,
735 "port.rx_priority_%u_xoff", i
);
736 p
+= ETH_GSTRING_LEN
;
738 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
739 snprintf(p
, ETH_GSTRING_LEN
,
740 "port.rx_priority_%u_xon_2_xoff", i
);
741 p
+= ETH_GSTRING_LEN
;
744 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
749 static int i40e_get_ts_info(struct net_device
*dev
,
750 struct ethtool_ts_info
*info
)
752 return ethtool_op_get_ts_info(dev
, info
);
755 static int i40e_link_test(struct net_device
*netdev
, u64
*data
)
757 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
758 struct i40e_pf
*pf
= np
->vsi
->back
;
760 netif_info(pf
, hw
, netdev
, "link test\n");
761 if (i40e_get_link_status(&pf
->hw
))
769 static int i40e_reg_test(struct net_device
*netdev
, u64
*data
)
771 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
772 struct i40e_pf
*pf
= np
->vsi
->back
;
774 netif_info(pf
, hw
, netdev
, "register test\n");
775 *data
= i40e_diag_reg_test(&pf
->hw
);
780 static int i40e_eeprom_test(struct net_device
*netdev
, u64
*data
)
782 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
783 struct i40e_pf
*pf
= np
->vsi
->back
;
785 netif_info(pf
, hw
, netdev
, "eeprom test\n");
786 *data
= i40e_diag_eeprom_test(&pf
->hw
);
791 static int i40e_intr_test(struct net_device
*netdev
, u64
*data
)
793 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
794 struct i40e_pf
*pf
= np
->vsi
->back
;
795 u16 swc_old
= pf
->sw_int_count
;
797 netif_info(pf
, hw
, netdev
, "interrupt test\n");
798 wr32(&pf
->hw
, I40E_PFINT_DYN_CTL0
,
799 (I40E_PFINT_DYN_CTL0_INTENA_MASK
|
800 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK
));
801 usleep_range(1000, 2000);
802 *data
= (swc_old
== pf
->sw_int_count
);
807 static int i40e_loopback_test(struct net_device
*netdev
, u64
*data
)
809 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
810 struct i40e_pf
*pf
= np
->vsi
->back
;
812 netif_info(pf
, hw
, netdev
, "loopback test not implemented\n");
818 static void i40e_diag_test(struct net_device
*netdev
,
819 struct ethtool_test
*eth_test
, u64
*data
)
821 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
822 struct i40e_pf
*pf
= np
->vsi
->back
;
824 if (eth_test
->flags
== ETH_TEST_FL_OFFLINE
) {
826 netif_info(pf
, drv
, netdev
, "offline testing starting\n");
828 set_bit(__I40E_TESTING
, &pf
->state
);
830 /* Link test performed before hardware reset
831 * so autoneg doesn't interfere with test result
833 if (i40e_link_test(netdev
, &data
[I40E_ETH_TEST_LINK
]))
834 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
836 if (i40e_eeprom_test(netdev
, &data
[I40E_ETH_TEST_EEPROM
]))
837 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
839 if (i40e_intr_test(netdev
, &data
[I40E_ETH_TEST_INTR
]))
840 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
842 if (i40e_loopback_test(netdev
, &data
[I40E_ETH_TEST_LOOPBACK
]))
843 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
845 /* run reg test last, a reset is required after it */
846 if (i40e_reg_test(netdev
, &data
[I40E_ETH_TEST_REG
]))
847 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
849 clear_bit(__I40E_TESTING
, &pf
->state
);
850 i40e_do_reset(pf
, (1 << __I40E_PF_RESET_REQUESTED
));
853 netif_info(pf
, drv
, netdev
, "online testing starting\n");
855 if (i40e_link_test(netdev
, &data
[I40E_ETH_TEST_LINK
]))
856 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
858 /* Offline only tests, not run in online; pass by default */
859 data
[I40E_ETH_TEST_REG
] = 0;
860 data
[I40E_ETH_TEST_EEPROM
] = 0;
861 data
[I40E_ETH_TEST_INTR
] = 0;
862 data
[I40E_ETH_TEST_LOOPBACK
] = 0;
865 netif_info(pf
, drv
, netdev
, "testing finished\n");
868 static void i40e_get_wol(struct net_device
*netdev
,
869 struct ethtool_wolinfo
*wol
)
871 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
872 struct i40e_pf
*pf
= np
->vsi
->back
;
873 struct i40e_hw
*hw
= &pf
->hw
;
876 /* NVM bit on means WoL disabled for the port */
877 i40e_read_nvm_word(hw
, I40E_SR_NVM_WAKE_ON_LAN
, &wol_nvm_bits
);
878 if ((1 << hw
->port
) & wol_nvm_bits
) {
882 wol
->supported
= WAKE_MAGIC
;
883 wol
->wolopts
= (pf
->wol_en
? WAKE_MAGIC
: 0);
887 static int i40e_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
889 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
890 struct i40e_pf
*pf
= np
->vsi
->back
;
891 struct i40e_hw
*hw
= &pf
->hw
;
894 /* NVM bit on means WoL disabled for the port */
895 i40e_read_nvm_word(hw
, I40E_SR_NVM_WAKE_ON_LAN
, &wol_nvm_bits
);
896 if (((1 << hw
->port
) & wol_nvm_bits
))
899 /* only magic packet is supported */
900 if (wol
->wolopts
&& (wol
->wolopts
!= WAKE_MAGIC
))
903 /* is this a new value? */
904 if (pf
->wol_en
!= !!wol
->wolopts
) {
905 pf
->wol_en
= !!wol
->wolopts
;
906 device_set_wakeup_enable(&pf
->pdev
->dev
, pf
->wol_en
);
912 static int i40e_nway_reset(struct net_device
*netdev
)
914 /* restart autonegotiation */
915 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
916 struct i40e_pf
*pf
= np
->vsi
->back
;
917 struct i40e_hw
*hw
= &pf
->hw
;
920 ret
= i40e_aq_set_link_restart_an(hw
, NULL
);
922 netdev_info(netdev
, "link restart failed, aq_err=%d\n",
923 pf
->hw
.aq
.asq_last_status
);
930 static int i40e_set_phys_id(struct net_device
*netdev
,
931 enum ethtool_phys_id_state state
)
933 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
934 struct i40e_pf
*pf
= np
->vsi
->back
;
935 struct i40e_hw
*hw
= &pf
->hw
;
939 case ETHTOOL_ID_ACTIVE
:
940 pf
->led_status
= i40e_led_get(hw
);
943 i40e_led_set(hw
, 0xF, false);
946 i40e_led_set(hw
, 0x0, false);
948 case ETHTOOL_ID_INACTIVE
:
949 i40e_led_set(hw
, pf
->led_status
, false);
956 /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
957 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
958 * 125us (8000 interrupts per second) == ITR(62)
961 static int i40e_get_coalesce(struct net_device
*netdev
,
962 struct ethtool_coalesce
*ec
)
964 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
965 struct i40e_vsi
*vsi
= np
->vsi
;
967 ec
->tx_max_coalesced_frames_irq
= vsi
->work_limit
;
968 ec
->rx_max_coalesced_frames_irq
= vsi
->work_limit
;
970 if (ITR_IS_DYNAMIC(vsi
->rx_itr_setting
))
971 ec
->rx_coalesce_usecs
= 1;
973 ec
->rx_coalesce_usecs
= vsi
->rx_itr_setting
;
975 if (ITR_IS_DYNAMIC(vsi
->tx_itr_setting
))
976 ec
->tx_coalesce_usecs
= 1;
978 ec
->tx_coalesce_usecs
= vsi
->tx_itr_setting
;
983 static int i40e_set_coalesce(struct net_device
*netdev
,
984 struct ethtool_coalesce
*ec
)
986 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
987 struct i40e_q_vector
*q_vector
;
988 struct i40e_vsi
*vsi
= np
->vsi
;
989 struct i40e_pf
*pf
= vsi
->back
;
990 struct i40e_hw
*hw
= &pf
->hw
;
994 if (ec
->tx_max_coalesced_frames_irq
|| ec
->rx_max_coalesced_frames_irq
)
995 vsi
->work_limit
= ec
->tx_max_coalesced_frames_irq
;
997 switch (ec
->rx_coalesce_usecs
) {
999 vsi
->rx_itr_setting
= 0;
1002 vsi
->rx_itr_setting
= (I40E_ITR_DYNAMIC
|
1003 ITR_REG_TO_USEC(I40E_ITR_RX_DEF
));
1006 if ((ec
->rx_coalesce_usecs
< (I40E_MIN_ITR
<< 1)) ||
1007 (ec
->rx_coalesce_usecs
> (I40E_MAX_ITR
<< 1)))
1009 vsi
->rx_itr_setting
= ec
->rx_coalesce_usecs
;
1013 switch (ec
->tx_coalesce_usecs
) {
1015 vsi
->tx_itr_setting
= 0;
1018 vsi
->tx_itr_setting
= (I40E_ITR_DYNAMIC
|
1019 ITR_REG_TO_USEC(I40E_ITR_TX_DEF
));
1022 if ((ec
->tx_coalesce_usecs
< (I40E_MIN_ITR
<< 1)) ||
1023 (ec
->tx_coalesce_usecs
> (I40E_MAX_ITR
<< 1)))
1025 vsi
->tx_itr_setting
= ec
->tx_coalesce_usecs
;
1029 vector
= vsi
->base_vector
;
1030 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vector
++) {
1031 q_vector
= vsi
->q_vectors
[i
];
1032 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_itr_setting
);
1033 wr32(hw
, I40E_PFINT_ITRN(0, vector
- 1), q_vector
->rx
.itr
);
1034 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_itr_setting
);
1035 wr32(hw
, I40E_PFINT_ITRN(1, vector
- 1), q_vector
->tx
.itr
);
1043 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1044 * @pf: pointer to the physical function struct
1045 * @cmd: ethtool rxnfc command
1047 * Returns Success if the flow is supported, else Invalid Input.
1049 static int i40e_get_rss_hash_opts(struct i40e_pf
*pf
, struct ethtool_rxnfc
*cmd
)
1053 /* Report default options for RSS on i40e */
1054 switch (cmd
->flow_type
) {
1057 cmd
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
1058 /* fall through to add IP fields */
1060 case AH_ESP_V4_FLOW
:
1064 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
1068 cmd
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
1069 /* fall through to add IP fields */
1071 case AH_ESP_V6_FLOW
:
1075 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
1085 * i40e_get_rxnfc - command to get RX flow classification rules
1086 * @netdev: network interface device structure
1087 * @cmd: ethtool rxnfc command
1089 * Returns Success if the command is supported.
1091 static int i40e_get_rxnfc(struct net_device
*netdev
, struct ethtool_rxnfc
*cmd
,
1094 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1095 struct i40e_vsi
*vsi
= np
->vsi
;
1096 struct i40e_pf
*pf
= vsi
->back
;
1097 int ret
= -EOPNOTSUPP
;
1100 case ETHTOOL_GRXRINGS
:
1101 cmd
->data
= vsi
->alloc_queue_pairs
;
1105 ret
= i40e_get_rss_hash_opts(pf
, cmd
);
1107 case ETHTOOL_GRXCLSRLCNT
:
1110 case ETHTOOL_GRXCLSRULE
:
1113 case ETHTOOL_GRXCLSRLALL
:
1124 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1125 * @pf: pointer to the physical function struct
1126 * @cmd: ethtool rxnfc command
1128 * Returns Success if the flow input set is supported.
1130 static int i40e_set_rss_hash_opt(struct i40e_pf
*pf
, struct ethtool_rxnfc
*nfc
)
1132 struct i40e_hw
*hw
= &pf
->hw
;
1133 u64 hena
= (u64
)rd32(hw
, I40E_PFQF_HENA(0)) |
1134 ((u64
)rd32(hw
, I40E_PFQF_HENA(1)) << 32);
1136 /* RSS does not support anything other than hashing
1137 * to queues on src and dst IPs and ports
1139 if (nfc
->data
& ~(RXH_IP_SRC
| RXH_IP_DST
|
1140 RXH_L4_B_0_1
| RXH_L4_B_2_3
))
1143 /* We need at least the IP SRC and DEST fields for hashing */
1144 if (!(nfc
->data
& RXH_IP_SRC
) ||
1145 !(nfc
->data
& RXH_IP_DST
))
1148 switch (nfc
->flow_type
) {
1150 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
1152 hena
&= ~((u64
)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP
);
1154 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
1155 hena
|= ((u64
)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP
);
1162 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
1164 hena
&= ~((u64
)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP
);
1166 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
1167 hena
|= ((u64
)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP
);
1174 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
1177 ~(((u64
)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP
) |
1178 ((u64
)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP
) |
1179 ((u64
)1 << I40E_FILTER_PCTYPE_FRAG_IPV4
));
1181 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
1183 (((u64
)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP
) |
1184 ((u64
)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP
) |
1185 ((u64
)1 << I40E_FILTER_PCTYPE_FRAG_IPV4
));
1192 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
1195 ~(((u64
)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP
) |
1196 ((u64
)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP
) |
1197 ((u64
)1 << I40E_FILTER_PCTYPE_FRAG_IPV6
));
1199 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
1201 (((u64
)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP
) |
1202 ((u64
)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP
) |
1203 ((u64
)1 << I40E_FILTER_PCTYPE_FRAG_IPV6
));
1209 case AH_ESP_V4_FLOW
:
1213 if ((nfc
->data
& RXH_L4_B_0_1
) ||
1214 (nfc
->data
& RXH_L4_B_2_3
))
1216 hena
|= ((u64
)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER
);
1218 case AH_ESP_V6_FLOW
:
1222 if ((nfc
->data
& RXH_L4_B_0_1
) ||
1223 (nfc
->data
& RXH_L4_B_2_3
))
1225 hena
|= ((u64
)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER
);
1228 hena
|= ((u64
)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER
) |
1229 ((u64
)1 << I40E_FILTER_PCTYPE_FRAG_IPV4
);
1232 hena
|= ((u64
)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER
) |
1233 ((u64
)1 << I40E_FILTER_PCTYPE_FRAG_IPV6
);
1239 wr32(hw
, I40E_PFQF_HENA(0), (u32
)hena
);
1240 wr32(hw
, I40E_PFQF_HENA(1), (u32
)(hena
>> 32));
1246 #define IP_HEADER_OFFSET 14
1248 * i40e_add_del_fdir_udpv4 - Add/Remove UDPv4 Flow Director filters for
1249 * a specific flow spec
1250 * @vsi: pointer to the targeted VSI
1251 * @fd_data: the flow director data required from the FDir descriptor
1252 * @ethtool_rx_flow_spec: the flow spec
1253 * @add: true adds a filter, false removes it
1255 * Returns 0 if the filters were successfully added or removed
1257 static int i40e_add_del_fdir_udpv4(struct i40e_vsi
*vsi
,
1258 struct i40e_fdir_data
*fd_data
,
1259 struct ethtool_rx_flow_spec
*fsp
, bool add
)
1261 struct i40e_pf
*pf
= vsi
->back
;
1268 ip
= (struct iphdr
*)(fd_data
->raw_packet
+ IP_HEADER_OFFSET
);
1269 udp
= (struct udphdr
*)(fd_data
->raw_packet
+ IP_HEADER_OFFSET
1270 + sizeof(struct iphdr
));
1272 ip
->saddr
= fsp
->h_u
.tcp_ip4_spec
.ip4src
;
1273 ip
->daddr
= fsp
->h_u
.tcp_ip4_spec
.ip4dst
;
1274 udp
->source
= fsp
->h_u
.tcp_ip4_spec
.psrc
;
1275 udp
->dest
= fsp
->h_u
.tcp_ip4_spec
.pdst
;
1277 for (i
= I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP
;
1278 i
<= I40E_FILTER_PCTYPE_NONF_IPV4_UDP
; i
++) {
1279 fd_data
->pctype
= i
;
1280 ret
= i40e_program_fdir_filter(fd_data
, pf
, add
);
1283 dev_info(&pf
->pdev
->dev
,
1284 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1285 fd_data
->pctype
, ret
);
1288 dev_info(&pf
->pdev
->dev
,
1289 "Filter OK for PCTYPE %d (ret = %d)\n",
1290 fd_data
->pctype
, ret
);
1294 return err
? -EOPNOTSUPP
: 0;
1298 * i40e_add_del_fdir_tcpv4 - Add/Remove TCPv4 Flow Director filters for
1299 * a specific flow spec
1300 * @vsi: pointer to the targeted VSI
1301 * @fd_data: the flow director data required from the FDir descriptor
1302 * @ethtool_rx_flow_spec: the flow spec
1303 * @add: true adds a filter, false removes it
1305 * Returns 0 if the filters were successfully added or removed
1307 static int i40e_add_del_fdir_tcpv4(struct i40e_vsi
*vsi
,
1308 struct i40e_fdir_data
*fd_data
,
1309 struct ethtool_rx_flow_spec
*fsp
, bool add
)
1311 struct i40e_pf
*pf
= vsi
->back
;
1317 ip
= (struct iphdr
*)(fd_data
->raw_packet
+ IP_HEADER_OFFSET
);
1318 tcp
= (struct tcphdr
*)(fd_data
->raw_packet
+ IP_HEADER_OFFSET
1319 + sizeof(struct iphdr
));
1321 ip
->daddr
= fsp
->h_u
.tcp_ip4_spec
.ip4dst
;
1322 tcp
->dest
= fsp
->h_u
.tcp_ip4_spec
.pdst
;
1324 fd_data
->pctype
= I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN
;
1325 ret
= i40e_program_fdir_filter(fd_data
, pf
, add
);
1328 dev_info(&pf
->pdev
->dev
,
1329 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1330 fd_data
->pctype
, ret
);
1333 dev_info(&pf
->pdev
->dev
, "Filter OK for PCTYPE %d (ret = %d)\n",
1334 fd_data
->pctype
, ret
);
1337 ip
->saddr
= fsp
->h_u
.tcp_ip4_spec
.ip4src
;
1338 tcp
->source
= fsp
->h_u
.tcp_ip4_spec
.psrc
;
1340 fd_data
->pctype
= I40E_FILTER_PCTYPE_NONF_IPV4_TCP
;
1342 ret
= i40e_program_fdir_filter(fd_data
, pf
, add
);
1344 dev_info(&pf
->pdev
->dev
,
1345 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1346 fd_data
->pctype
, ret
);
1349 dev_info(&pf
->pdev
->dev
, "Filter OK for PCTYPE %d (ret = %d)\n",
1350 fd_data
->pctype
, ret
);
1353 return err
? -EOPNOTSUPP
: 0;
1357 * i40e_add_del_fdir_sctpv4 - Add/Remove SCTPv4 Flow Director filters for
1358 * a specific flow spec
1359 * @vsi: pointer to the targeted VSI
1360 * @fd_data: the flow director data required from the FDir descriptor
1361 * @ethtool_rx_flow_spec: the flow spec
1362 * @add: true adds a filter, false removes it
1364 * Returns 0 if the filters were successfully added or removed
1366 static int i40e_add_del_fdir_sctpv4(struct i40e_vsi
*vsi
,
1367 struct i40e_fdir_data
*fd_data
,
1368 struct ethtool_rx_flow_spec
*fsp
, bool add
)
1374 * i40e_add_del_fdir_ipv4 - Add/Remove IPv4 Flow Director filters for
1375 * a specific flow spec
1376 * @vsi: pointer to the targeted VSI
1377 * @fd_data: the flow director data required for the FDir descriptor
1378 * @fsp: the ethtool flow spec
1379 * @add: true adds a filter, false removes it
1381 * Returns 0 if the filters were successfully added or removed
1383 static int i40e_add_del_fdir_ipv4(struct i40e_vsi
*vsi
,
1384 struct i40e_fdir_data
*fd_data
,
1385 struct ethtool_rx_flow_spec
*fsp
, bool add
)
1387 struct i40e_pf
*pf
= vsi
->back
;
1393 ip
= (struct iphdr
*)(fd_data
->raw_packet
+ IP_HEADER_OFFSET
);
1395 ip
->saddr
= fsp
->h_u
.usr_ip4_spec
.ip4src
;
1396 ip
->daddr
= fsp
->h_u
.usr_ip4_spec
.ip4dst
;
1397 ip
->protocol
= fsp
->h_u
.usr_ip4_spec
.proto
;
1399 for (i
= I40E_FILTER_PCTYPE_NONF_IPV4_OTHER
;
1400 i
<= I40E_FILTER_PCTYPE_FRAG_IPV4
; i
++) {
1401 fd_data
->pctype
= i
;
1402 ret
= i40e_program_fdir_filter(fd_data
, pf
, add
);
1405 dev_info(&pf
->pdev
->dev
,
1406 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1407 fd_data
->pctype
, ret
);
1410 dev_info(&pf
->pdev
->dev
,
1411 "Filter OK for PCTYPE %d (ret = %d)\n",
1412 fd_data
->pctype
, ret
);
1416 return err
? -EOPNOTSUPP
: 0;
1420 * i40e_add_del_fdir_ethtool - Add/Remove Flow Director filters for
1421 * a specific flow spec based on their protocol
1422 * @vsi: pointer to the targeted VSI
1423 * @cmd: command to get or set RX flow classification rules
1424 * @add: true adds a filter, false removes it
1426 * Returns 0 if the filters were successfully added or removed
1428 static int i40e_add_del_fdir_ethtool(struct i40e_vsi
*vsi
,
1429 struct ethtool_rxnfc
*cmd
, bool add
)
1431 struct i40e_fdir_data fd_data
;
1434 struct ethtool_rx_flow_spec
*fsp
=
1435 (struct ethtool_rx_flow_spec
*)&cmd
->fs
;
1442 if ((fsp
->ring_cookie
!= RX_CLS_FLOW_DISC
) &&
1443 (fsp
->ring_cookie
>= vsi
->num_queue_pairs
))
1446 /* Populate the Flow Director that we have at the moment
1447 * and allocate the raw packet buffer for the calling functions
1449 fd_data
.raw_packet
= kzalloc(I40E_FDIR_MAX_RAW_PACKET_LOOKUP
,
1452 if (!fd_data
.raw_packet
) {
1453 dev_info(&pf
->pdev
->dev
, "Could not allocate memory\n");
1457 fd_data
.q_index
= fsp
->ring_cookie
;
1458 fd_data
.flex_off
= 0;
1460 fd_data
.dest_vsi
= vsi
->id
;
1461 fd_data
.dest_ctl
= 0;
1462 fd_data
.fd_status
= 0;
1463 fd_data
.cnt_index
= 0;
1466 switch (fsp
->flow_type
& ~FLOW_EXT
) {
1468 ret
= i40e_add_del_fdir_tcpv4(vsi
, &fd_data
, fsp
, add
);
1471 ret
= i40e_add_del_fdir_udpv4(vsi
, &fd_data
, fsp
, add
);
1474 ret
= i40e_add_del_fdir_sctpv4(vsi
, &fd_data
, fsp
, add
);
1477 ret
= i40e_add_del_fdir_ipv4(vsi
, &fd_data
, fsp
, add
);
1480 switch (fsp
->h_u
.usr_ip4_spec
.proto
) {
1482 ret
= i40e_add_del_fdir_tcpv4(vsi
, &fd_data
, fsp
, add
);
1485 ret
= i40e_add_del_fdir_udpv4(vsi
, &fd_data
, fsp
, add
);
1488 ret
= i40e_add_del_fdir_sctpv4(vsi
, &fd_data
, fsp
, add
);
1491 ret
= i40e_add_del_fdir_ipv4(vsi
, &fd_data
, fsp
, add
);
1496 dev_info(&pf
->pdev
->dev
, "Could not specify spec type\n");
1500 kfree(fd_data
.raw_packet
);
1501 fd_data
.raw_packet
= NULL
;
1506 * i40e_set_rxnfc - command to set RX flow classification rules
1507 * @netdev: network interface device structure
1508 * @cmd: ethtool rxnfc command
1510 * Returns Success if the command is supported.
1512 static int i40e_set_rxnfc(struct net_device
*netdev
, struct ethtool_rxnfc
*cmd
)
1514 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1515 struct i40e_vsi
*vsi
= np
->vsi
;
1516 struct i40e_pf
*pf
= vsi
->back
;
1517 int ret
= -EOPNOTSUPP
;
1521 ret
= i40e_set_rss_hash_opt(pf
, cmd
);
1523 case ETHTOOL_SRXCLSRLINS
:
1524 ret
= i40e_add_del_fdir_ethtool(vsi
, cmd
, true);
1526 case ETHTOOL_SRXCLSRLDEL
:
1527 ret
= i40e_add_del_fdir_ethtool(vsi
, cmd
, false);
1537 * i40e_max_channels - get Max number of combined channels supported
1540 static unsigned int i40e_max_channels(struct i40e_vsi
*vsi
)
1542 /* TODO: This code assumes DCB and FD is disabled for now. */
1543 return vsi
->alloc_queue_pairs
;
1547 * i40e_get_channels - Get the current channels enabled and max supported etc.
1548 * @netdev: network interface device structure
1549 * @ch: ethtool channels structure
1551 * We don't support separate tx and rx queues as channels. The other count
1552 * represents how many queues are being used for control. max_combined counts
1553 * how many queue pairs we can support. They may not be mapped 1 to 1 with
1554 * q_vectors since we support a lot more queue pairs than q_vectors.
1556 static void i40e_get_channels(struct net_device
*dev
,
1557 struct ethtool_channels
*ch
)
1559 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
1560 struct i40e_vsi
*vsi
= np
->vsi
;
1561 struct i40e_pf
*pf
= vsi
->back
;
1563 /* report maximum channels */
1564 ch
->max_combined
= i40e_max_channels(vsi
);
1566 /* report info for other vector */
1567 ch
->other_count
= (pf
->flags
& I40E_FLAG_FDIR_ENABLED
) ? 1 : 0;
1568 ch
->max_other
= ch
->other_count
;
1570 /* Note: This code assumes DCB is disabled for now. */
1571 ch
->combined_count
= vsi
->num_queue_pairs
;
1575 * i40e_set_channels - Set the new channels count.
1576 * @netdev: network interface device structure
1577 * @ch: ethtool channels structure
1579 * The new channels count may not be the same as requested by the user
1580 * since it gets rounded down to a power of 2 value.
1582 static int i40e_set_channels(struct net_device
*dev
,
1583 struct ethtool_channels
*ch
)
1585 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
1586 unsigned int count
= ch
->combined_count
;
1587 struct i40e_vsi
*vsi
= np
->vsi
;
1588 struct i40e_pf
*pf
= vsi
->back
;
1591 /* We do not support setting channels for any other VSI at present */
1592 if (vsi
->type
!= I40E_VSI_MAIN
)
1595 /* verify they are not requesting separate vectors */
1596 if (!count
|| ch
->rx_count
|| ch
->tx_count
)
1599 /* verify other_count has not changed */
1600 if (ch
->other_count
!= ((pf
->flags
& I40E_FLAG_FDIR_ENABLED
) ? 1 : 0))
1603 /* verify the number of channels does not exceed hardware limits */
1604 if (count
> i40e_max_channels(vsi
))
1607 /* update feature limits from largest to smallest supported values */
1608 /* TODO: Flow director limit, DCB etc */
1611 if (count
> pf
->rss_size_max
)
1612 count
= pf
->rss_size_max
;
1614 /* use rss_reconfig to rebuild with new queue count and update traffic
1615 * class queue mapping
1617 new_count
= i40e_reconfig_rss_queues(pf
, count
);
1624 static const struct ethtool_ops i40e_ethtool_ops
= {
1625 .get_settings
= i40e_get_settings
,
1626 .get_drvinfo
= i40e_get_drvinfo
,
1627 .get_regs_len
= i40e_get_regs_len
,
1628 .get_regs
= i40e_get_regs
,
1629 .nway_reset
= i40e_nway_reset
,
1630 .get_link
= ethtool_op_get_link
,
1631 .get_wol
= i40e_get_wol
,
1632 .set_wol
= i40e_set_wol
,
1633 .get_eeprom_len
= i40e_get_eeprom_len
,
1634 .get_eeprom
= i40e_get_eeprom
,
1635 .get_ringparam
= i40e_get_ringparam
,
1636 .set_ringparam
= i40e_set_ringparam
,
1637 .get_pauseparam
= i40e_get_pauseparam
,
1638 .get_msglevel
= i40e_get_msglevel
,
1639 .set_msglevel
= i40e_set_msglevel
,
1640 .get_rxnfc
= i40e_get_rxnfc
,
1641 .set_rxnfc
= i40e_set_rxnfc
,
1642 .self_test
= i40e_diag_test
,
1643 .get_strings
= i40e_get_strings
,
1644 .set_phys_id
= i40e_set_phys_id
,
1645 .get_sset_count
= i40e_get_sset_count
,
1646 .get_ethtool_stats
= i40e_get_ethtool_stats
,
1647 .get_coalesce
= i40e_get_coalesce
,
1648 .set_coalesce
= i40e_set_coalesce
,
1649 .get_channels
= i40e_get_channels
,
1650 .set_channels
= i40e_set_channels
,
1651 .get_ts_info
= i40e_get_ts_info
,
1654 void i40e_set_ethtool_ops(struct net_device
*netdev
)
1656 SET_ETHTOOL_OPS(netdev
, &i40e_ethtool_ops
);