Commit 59de65f6 authored by Jian Shen's avatar Jian Shen Committed by Jiantao Xiao
Browse files

net: hns3: add support for page_pool_get_stats

driver inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I8GK5Q


CVE: NA

----------------------------------------------------------------------

Add support for page_pool_get_stats, then the hns3 driver
can get page pool statistics by ethtool.

Signed-off-by: default avatarJian Shen <shenjian15@huawei.com>
parent 48c6a9ff
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -5290,6 +5290,11 @@ static void hns3_alloc_page_pool(struct hns3_enet_ring *ring)
	}
}

bool hns3_is_page_pool_enabled(void)
{
	return page_pool_enabled;
}

static int hns3_alloc_ring_memory(struct hns3_enet_ring *ring)
{
	int ret;
+1 −0
Original line number Diff line number Diff line
@@ -819,4 +819,5 @@ void hns3_cq_period_mode_init(struct hns3_nic_priv *priv,

void hns3_external_lb_prepare(struct net_device *ndev, bool if_running);
void hns3_external_lb_restore(struct net_device *ndev, bool if_running);
bool hns3_is_page_pool_enabled(void);
#endif
+33 −1
Original line number Diff line number Diff line
@@ -533,14 +533,19 @@ static int hns3_get_sset_count(struct net_device *netdev, int stringset)
{
	struct hnae3_handle *h = hns3_get_handle(netdev);
	const struct hnae3_ae_ops *ops = h->ae_algo->ops;
	int pp_stats_count = 0;

	if (!ops->get_sset_count)
		return -EOPNOTSUPP;

	switch (stringset) {
	case ETH_SS_STATS:
#ifdef CONFIG_PAGE_POOL_STATS
		if (hns3_is_page_pool_enabled())
			pp_stats_count = page_pool_ethtool_stats_get_count();
#endif
		return ((HNS3_TQP_STATS_COUNT * h->kinfo.num_tqps) +
			ops->get_sset_count(h, stringset));
			ops->get_sset_count(h, stringset) + pp_stats_count);

	case ETH_SS_TEST:
		return ops->get_sset_count(h, stringset);
@@ -608,6 +613,10 @@ static void hns3_get_strings(struct net_device *netdev, u32 stringset, u8 *data)

	switch (stringset) {
	case ETH_SS_STATS:
#ifdef CONFIG_PAGE_POOL_STATS
		if (hns3_is_page_pool_enabled())
			buff = page_pool_ethtool_stats_get_strings(buff);
#endif
		buff = hns3_get_strings_tqps(h, buff);
		ops->get_strings(h, stringset, (u8 *)buff);
		break;
@@ -655,6 +664,25 @@ static u64 *hns3_get_stats_tqps(struct hnae3_handle *handle, u64 *data)
	return data;
}

#ifdef CONFIG_PAGE_POOL_STATS
static u64 *hns3_ethtool_pp_stats(struct hnae3_handle *handle, u64 *data)
{
	struct hns3_nic_priv *priv = handle->priv;
	int ring_num = handle->kinfo.num_tqps;
	struct page_pool_stats stats = {0};
	struct page_pool *page_pool;
	int i;

	for (i = 0; i < ring_num; i++) {
		page_pool = priv->ring[i + ring_num].page_pool;
		if (page_pool)
			page_pool_get_stats(page_pool, &stats);
	}

	return page_pool_ethtool_stats_get(data, &stats);
}
#endif

/* hns3_get_stats - get detail statistics.
 * @netdev: net device
 * @stats: statistics info.
@@ -676,6 +704,10 @@ static void hns3_get_stats(struct net_device *netdev,
		return;
	}

#ifdef CONFIG_PAGE_POOL_STATS
	p = hns3_ethtool_pp_stats(h, p);
#endif

	h->ae_algo->ops->update_stats(h);

	/* get per-queue stats */