Skip to content

Commit dc645da

Browse files
jbrandebJeff Kirsher
authored andcommitted
i40e: implement VF stats NDO
Implement the VF stats gathering via the kernel via ndo_get_vf_stats(). The driver will show per-VF stats in the output of the command: ip -s link show dev <PF> Testing Hints: ip -s link show dev eth0 will return non-zero VF stats. ... vf 0 MAC 00:55:aa:00:55:aa, spoof checking on, link-state enable, trust off RX: bytes packets mcast bcast 128000 1000 104 104 TX: bytes packets 128000 1000 Signed-off-by: Jesse Brandeburg <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent 3df5b9a commit dc645da

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

drivers/net/ethernet/intel/i40e/i40e_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12870,6 +12870,7 @@ static const struct net_device_ops i40e_netdev_ops = {
1287012870
.ndo_set_features = i40e_set_features,
1287112871
.ndo_set_vf_mac = i40e_ndo_set_vf_mac,
1287212872
.ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
12873+
.ndo_get_vf_stats = i40e_get_vf_stats,
1287312874
.ndo_set_vf_rate = i40e_ndo_set_vf_bw,
1287412875
.ndo_get_vf_config = i40e_ndo_get_vf_config,
1287512876
.ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,

drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4524,3 +4524,51 @@ int i40e_ndo_set_vf_trust(struct net_device *netdev, int vf_id, bool setting)
45244524
clear_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state);
45254525
return ret;
45264526
}
4527+
4528+
/**
4529+
* i40e_get_vf_stats - populate some stats for the VF
4530+
* @netdev: the netdev of the PF
4531+
* @vf_id: the host OS identifier (0-127)
4532+
* @vf_stats: pointer to the OS memory to be initialized
4533+
*/
4534+
int i40e_get_vf_stats(struct net_device *netdev, int vf_id,
4535+
struct ifla_vf_stats *vf_stats)
4536+
{
4537+
struct i40e_netdev_priv *np = netdev_priv(netdev);
4538+
struct i40e_pf *pf = np->vsi->back;
4539+
struct i40e_eth_stats *stats;
4540+
struct i40e_vsi *vsi;
4541+
struct i40e_vf *vf;
4542+
4543+
/* validate the request */
4544+
if (i40e_validate_vf(pf, vf_id))
4545+
return -EINVAL;
4546+
4547+
vf = &pf->vf[vf_id];
4548+
if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
4549+
dev_err(&pf->pdev->dev, "VF %d in reset. Try again.\n", vf_id);
4550+
return -EBUSY;
4551+
}
4552+
4553+
vsi = pf->vsi[vf->lan_vsi_idx];
4554+
if (!vsi)
4555+
return -EINVAL;
4556+
4557+
i40e_update_eth_stats(vsi);
4558+
stats = &vsi->eth_stats;
4559+
4560+
memset(vf_stats, 0, sizeof(*vf_stats));
4561+
4562+
vf_stats->rx_packets = stats->rx_unicast + stats->rx_broadcast +
4563+
stats->rx_multicast;
4564+
vf_stats->tx_packets = stats->tx_unicast + stats->tx_broadcast +
4565+
stats->tx_multicast;
4566+
vf_stats->rx_bytes = stats->rx_bytes;
4567+
vf_stats->tx_bytes = stats->tx_bytes;
4568+
vf_stats->broadcast = stats->rx_broadcast;
4569+
vf_stats->multicast = stats->rx_multicast;
4570+
vf_stats->rx_dropped = stats->rx_discards;
4571+
vf_stats->tx_dropped = stats->tx_discards;
4572+
4573+
return 0;
4574+
}

drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,7 @@ int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable);
138138

139139
void i40e_vc_notify_link_state(struct i40e_pf *pf);
140140
void i40e_vc_notify_reset(struct i40e_pf *pf);
141+
int i40e_get_vf_stats(struct net_device *netdev, int vf_id,
142+
struct ifla_vf_stats *vf_stats);
141143

142144
#endif /* _I40E_VIRTCHNL_PF_H_ */

0 commit comments

Comments
 (0)