cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

hclge_comm_tqp_stats.c (2987B)


      1// SPDX-License-Identifier: GPL-2.0+
      2// Copyright (c) 2021-2021 Hisilicon Limited.
      3
      4#include <linux/err.h>
      5
      6#include "hnae3.h"
      7#include "hclge_comm_cmd.h"
      8#include "hclge_comm_tqp_stats.h"
      9
     10u64 *hclge_comm_tqps_get_stats(struct hnae3_handle *handle, u64 *data)
     11{
     12	struct hnae3_knic_private_info *kinfo = &handle->kinfo;
     13	struct hclge_comm_tqp *tqp;
     14	u64 *buff = data;
     15	u16 i;
     16
     17	for (i = 0; i < kinfo->num_tqps; i++) {
     18		tqp = container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
     19		*buff++ = tqp->tqp_stats.rcb_tx_ring_pktnum_rcd;
     20	}
     21
     22	for (i = 0; i < kinfo->num_tqps; i++) {
     23		tqp = container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
     24		*buff++ = tqp->tqp_stats.rcb_rx_ring_pktnum_rcd;
     25	}
     26
     27	return buff;
     28}
     29
     30int hclge_comm_tqps_get_sset_count(struct hnae3_handle *handle)
     31{
     32	struct hnae3_knic_private_info *kinfo = &handle->kinfo;
     33
     34	return kinfo->num_tqps * HCLGE_COMM_QUEUE_PAIR_SIZE;
     35}
     36
     37u8 *hclge_comm_tqps_get_strings(struct hnae3_handle *handle, u8 *data)
     38{
     39	struct hnae3_knic_private_info *kinfo = &handle->kinfo;
     40	u8 *buff = data;
     41	u16 i;
     42
     43	for (i = 0; i < kinfo->num_tqps; i++) {
     44		struct hclge_comm_tqp *tqp =
     45			container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
     46		snprintf(buff, ETH_GSTRING_LEN, "txq%u_pktnum_rcd", tqp->index);
     47		buff += ETH_GSTRING_LEN;
     48	}
     49
     50	for (i = 0; i < kinfo->num_tqps; i++) {
     51		struct hclge_comm_tqp *tqp =
     52			container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
     53		snprintf(buff, ETH_GSTRING_LEN, "rxq%u_pktnum_rcd", tqp->index);
     54		buff += ETH_GSTRING_LEN;
     55	}
     56
     57	return buff;
     58}
     59
     60int hclge_comm_tqps_update_stats(struct hnae3_handle *handle,
     61				 struct hclge_comm_hw *hw)
     62{
     63	struct hnae3_knic_private_info *kinfo = &handle->kinfo;
     64	struct hclge_comm_tqp *tqp;
     65	struct hclge_desc desc;
     66	int ret;
     67	u16 i;
     68
     69	for (i = 0; i < kinfo->num_tqps; i++) {
     70		tqp = container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
     71		hclge_comm_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_RX_STATS,
     72						true);
     73
     74		desc.data[0] = cpu_to_le32(tqp->index);
     75		ret = hclge_comm_cmd_send(hw, &desc, 1);
     76		if (ret) {
     77			dev_err(&hw->cmq.csq.pdev->dev,
     78				"failed to get tqp stat, ret = %d, rx = %u.\n",
     79				ret, i);
     80			return ret;
     81		}
     82		tqp->tqp_stats.rcb_rx_ring_pktnum_rcd +=
     83			le32_to_cpu(desc.data[1]);
     84
     85		hclge_comm_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_TX_STATS,
     86						true);
     87
     88		desc.data[0] = cpu_to_le32(tqp->index & 0x1ff);
     89		ret = hclge_comm_cmd_send(hw, &desc, 1);
     90		if (ret) {
     91			dev_err(&hw->cmq.csq.pdev->dev,
     92				"failed to get tqp stat, ret = %d, tx = %u.\n",
     93				ret, i);
     94			return ret;
     95		}
     96		tqp->tqp_stats.rcb_tx_ring_pktnum_rcd +=
     97			le32_to_cpu(desc.data[1]);
     98	}
     99
    100	return 0;
    101}
    102
    103void hclge_comm_reset_tqp_stats(struct hnae3_handle *handle)
    104{
    105	struct hnae3_knic_private_info *kinfo = &handle->kinfo;
    106	struct hclge_comm_tqp *tqp;
    107	struct hnae3_queue *queue;
    108	u16 i;
    109
    110	for (i = 0; i < kinfo->num_tqps; i++) {
    111		queue = kinfo->tqp[i];
    112		tqp = container_of(queue, struct hclge_comm_tqp, q);
    113		memset(&tqp->tqp_stats, 0, sizeof(tqp->tqp_stats));
    114	}
    115}