Commit 01e611e3 authored by shaojijie's avatar shaojijie Committed by Jiantao Xiao
Browse files

net: hns3: add support clear mac statistics

driver inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I6QRKC


CVE: NA

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

Some scenes use the standard tools ethtool and ifconfig to query traffic
statistics in a specified period.To facilitate calculation, the driver
needs to clear the original statistics first. The patch provides an
customized interface for clearing MAC statistics.

Signed-off-by: default avatarshaojijie <shaojijie@huawei.com>
Signed-off-by: default avatarJiantao Xiao <xiaojiantao1@h-partners.com>
parent 18c7dc4f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ enum hnae3_ext_opcode {
	HNAE3_EXT_OPC_SET_NOTIFY_START,
	HNAE3_EXT_OPC_SET_TORUS_PARAM,
	HNAE3_EXT_OPC_GET_TORUS_PARAM,
	HNAE3_EXT_OPC_CLEAN_STATS64,
};

struct hnae3_pfc_storm_para {
+40 −0
Original line number Diff line number Diff line
@@ -174,3 +174,43 @@ int nic_get_torus_param(struct net_device *ndev, struct hnae3_torus_param *param
				  param, sizeof(*param));
}
EXPORT_SYMBOL(nic_get_torus_param);

int nic_clean_stats64(struct net_device *ndev, struct rtnl_link_stats64 *stats)
{
	struct hnae3_knic_private_info *kinfo;
	struct hns3_enet_ring *ring;
	struct hns3_nic_priv *priv;
	struct hnae3_handle *h;
	int i, ret;

	priv = netdev_priv(ndev);
	h = hns3_get_handle(ndev);
	kinfo = &h->kinfo;

	rtnl_lock();
	if (!test_bit(HNS3_NIC_STATE_INITED, &priv->state) ||
	    test_bit(HNS3_NIC_STATE_RESETTING, &priv->state)) {
		ret = -EBUSY;
		goto end_unlock;
	}

	ret = nic_invoke_pri_ops(ndev, HNAE3_EXT_OPC_CLEAN_STATS64,
				 NULL, 0);
	if (ret)
		goto end_unlock;

	for (i = 0; i < kinfo->num_tqps; i++) {
		ring = &priv->ring[i];
		memset(&ring->stats, 0, sizeof(struct ring_stats));
		ring = &priv->ring[i + kinfo->num_tqps];
		memset(&ring->stats, 0, sizeof(struct ring_stats));
	}

	memset(&ndev->stats, 0, sizeof(struct net_device_stats));
	netdev_info(ndev, "clean stats succ\n");

end_unlock:
	rtnl_unlock();
	return ret;
}
EXPORT_SYMBOL(nic_clean_stats64);
+1 −0
Original line number Diff line number Diff line
@@ -26,4 +26,5 @@ int nic_set_notify_pkt_param(struct net_device *ndev,
int nic_set_notify_pkt_start(struct net_device *ndev);
int nic_set_torus_param(struct net_device *ndev, struct hnae3_torus_param *param);
int nic_get_torus_param(struct net_device *ndev, struct hnae3_torus_param *param);
int nic_clean_stats64(struct net_device *ndev, struct rtnl_link_stats64 *stats);
#endif
+17 −0
Original line number Diff line number Diff line
@@ -336,6 +336,22 @@ static int hclge_get_torus_param(struct hclge_dev *hdev, void *data,
	return 0;
}

static int hclge_clean_stats64(struct hclge_dev *hdev, void *data,
			       size_t length)
{
	struct hnae3_knic_private_info *kinfo;
	struct hclge_comm_tqp *tqp;
	int i;

	kinfo = &hdev->vport[0].nic.kinfo;
	for (i = 0; i < kinfo->num_tqps; i++) {
		tqp = container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
		memset(&tqp->tqp_stats, 0, sizeof(struct hclge_comm_tqp_stats));
	}
	memset(&hdev->mac_stats, 0, sizeof(struct hclge_mac_stats));
	return 0;
}

static void hclge_ext_resotre_config(struct hclge_dev *hdev)
{
	if (hdev->reset_type != HNAE3_IMP_RESET &&
@@ -493,6 +509,7 @@ static const hclge_priv_ops_fn hclge_ext_func_arr[] = {
	[HNAE3_EXT_OPC_SET_NOTIFY_START] = hclge_set_notify_packet_start,
	[HNAE3_EXT_OPC_SET_TORUS_PARAM] = hclge_set_torus_param,
	[HNAE3_EXT_OPC_GET_TORUS_PARAM] = hclge_get_torus_param,
	[HNAE3_EXT_OPC_CLEAN_STATS64] = hclge_clean_stats64,
};

int hclge_ext_ops_handle(struct hnae3_handle *handle, int opcode,