diff mbox series

[v2,net-next,11/26] sf100, sfx: implement generic XDP stats callbacks

Message ID 20211123163955.154512-12-alexandr.lobakin@intel.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: introduce and use generic XDP stats | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count fail Series longer than 15 patches (and no cover letter)
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/cc_maintainers success CCed 15 of 15 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 1
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 73 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Alexander Lobakin Nov. 23, 2021, 4:39 p.m. UTC
Export 4 per-channel XDP counters for both sf100 and sfx drivers
using generic XDP stats infra.

Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
Reviewed-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
---
 drivers/net/ethernet/sfc/ef100_netdev.c |  2 ++
 drivers/net/ethernet/sfc/efx.c          |  2 ++
 drivers/net/ethernet/sfc/efx_common.c   | 42 +++++++++++++++++++++++++
 drivers/net/ethernet/sfc/efx_common.h   |  3 ++
 4 files changed, 49 insertions(+)

--
2.33.1

Comments

Edward Cree Nov. 24, 2021, 9:59 a.m. UTC | #1
On 23/11/2021 16:39, Alexander Lobakin wrote:
> Export 4 per-channel XDP counters for both sf100 and sfx drivers
> using generic XDP stats infra.
> 
> Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
> Reviewed-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
The usual Subject: prefix for these drivers is sfc:
 (or occasionally sfc_ef100: for ef100-specific stuff).

> +int efx_get_xdp_stats_nch(const struct net_device *net_dev, u32 attr_id)
> +{
> +	const struct efx_nic *efx = netdev_priv(net_dev);
> +
> +	switch (attr_id) {
> +	case IFLA_XDP_XSTATS_TYPE_XDP:
> +		return efx->n_channels;
> +	default:
> +		return -EOPNOTSUPP;
> +	}
> +}
> +
> +int efx_get_xdp_stats(const struct net_device *net_dev, u32 attr_id,
> +		      void *attr_data)
> +{
> +	struct ifla_xdp_stats *xdp_stats = attr_data;
> +	struct efx_nic *efx = netdev_priv(net_dev);
> +	const struct efx_channel *channel;
> +
> +	switch (attr_id) {
> +	case IFLA_XDP_XSTATS_TYPE_XDP:
> +		break;
> +	default:
> +		return -EOPNOTSUPP;
> +	}
> +
> +	spin_lock_bh(&efx->stats_lock);
> +
> +	efx_for_each_channel(channel, efx) {
> +		xdp_stats->drop = channel->n_rx_xdp_drops;
> +		xdp_stats->errors = channel->n_rx_xdp_bad_drops;
> +		xdp_stats->redirect = channel->n_rx_xdp_redirect;
> +		xdp_stats->tx = channel->n_rx_xdp_tx;
> +
> +		xdp_stats++;
> +	}What guarantees that efx->n_channels won't change between these two
 calls, potentially overrunning the buffer?

-ed
diff mbox series

Patch

diff --git a/drivers/net/ethernet/sfc/ef100_netdev.c b/drivers/net/ethernet/sfc/ef100_netdev.c
index 67fe44db6b61..0367f7e043d8 100644
--- a/drivers/net/ethernet/sfc/ef100_netdev.c
+++ b/drivers/net/ethernet/sfc/ef100_netdev.c
@@ -219,6 +219,8 @@  static const struct net_device_ops ef100_netdev_ops = {
 	.ndo_start_xmit         = ef100_hard_start_xmit,
 	.ndo_tx_timeout         = efx_watchdog,
 	.ndo_get_stats64        = efx_net_stats,
+	.ndo_get_xdp_stats_nch  = efx_get_xdp_stats_nch,
+	.ndo_get_xdp_stats      = efx_get_xdp_stats,
 	.ndo_change_mtu         = efx_change_mtu,
 	.ndo_validate_addr      = eth_validate_addr,
 	.ndo_set_mac_address    = efx_set_mac_address,
diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c
index a8c252e2b252..a6a015c4d3b4 100644
--- a/drivers/net/ethernet/sfc/efx.c
+++ b/drivers/net/ethernet/sfc/efx.c
@@ -588,6 +588,8 @@  static const struct net_device_ops efx_netdev_ops = {
 	.ndo_open		= efx_net_open,
 	.ndo_stop		= efx_net_stop,
 	.ndo_get_stats64	= efx_net_stats,
+	.ndo_get_xdp_stats_nch	= efx_get_xdp_stats_nch,
+	.ndo_get_xdp_stats	= efx_get_xdp_stats,
 	.ndo_tx_timeout		= efx_watchdog,
 	.ndo_start_xmit		= efx_hard_start_xmit,
 	.ndo_validate_addr	= eth_validate_addr,
diff --git a/drivers/net/ethernet/sfc/efx_common.c b/drivers/net/ethernet/sfc/efx_common.c
index f187631b2c5c..c2bf79fd66b4 100644
--- a/drivers/net/ethernet/sfc/efx_common.c
+++ b/drivers/net/ethernet/sfc/efx_common.c
@@ -606,6 +606,48 @@  void efx_net_stats(struct net_device *net_dev, struct rtnl_link_stats64 *stats)
 	spin_unlock_bh(&efx->stats_lock);
 }

+int efx_get_xdp_stats_nch(const struct net_device *net_dev, u32 attr_id)
+{
+	const struct efx_nic *efx = netdev_priv(net_dev);
+
+	switch (attr_id) {
+	case IFLA_XDP_XSTATS_TYPE_XDP:
+		return efx->n_channels;
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+int efx_get_xdp_stats(const struct net_device *net_dev, u32 attr_id,
+		      void *attr_data)
+{
+	struct ifla_xdp_stats *xdp_stats = attr_data;
+	struct efx_nic *efx = netdev_priv(net_dev);
+	const struct efx_channel *channel;
+
+	switch (attr_id) {
+	case IFLA_XDP_XSTATS_TYPE_XDP:
+		break;
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	spin_lock_bh(&efx->stats_lock);
+
+	efx_for_each_channel(channel, efx) {
+		xdp_stats->drop = channel->n_rx_xdp_drops;
+		xdp_stats->errors = channel->n_rx_xdp_bad_drops;
+		xdp_stats->redirect = channel->n_rx_xdp_redirect;
+		xdp_stats->tx = channel->n_rx_xdp_tx;
+
+		xdp_stats++;
+	}
+
+	spin_unlock_bh(&efx->stats_lock);
+
+	return 0;
+}
+
 /* Push loopback/power/transmit disable settings to the PHY, and reconfigure
  * the MAC appropriately. All other PHY configuration changes are pushed
  * through phy_op->set_settings(), and pushed asynchronously to the MAC
diff --git a/drivers/net/ethernet/sfc/efx_common.h b/drivers/net/ethernet/sfc/efx_common.h
index 65513fd0cf6c..987d7c6608a2 100644
--- a/drivers/net/ethernet/sfc/efx_common.h
+++ b/drivers/net/ethernet/sfc/efx_common.h
@@ -32,6 +32,9 @@  void efx_start_all(struct efx_nic *efx);
 void efx_stop_all(struct efx_nic *efx);

 void efx_net_stats(struct net_device *net_dev, struct rtnl_link_stats64 *stats);
+int efx_get_xdp_stats_nch(const struct net_device *net_dev, u32 attr_id);
+int efx_get_xdp_stats(const struct net_device *net_dev, u32 attr_id,
+		      void *attr_data);

 int efx_create_reset_workqueue(void);
 void efx_queue_reset_work(struct efx_nic *efx);