Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 // Copyright (c) 2021-2021 Hisilicon Limited.
0003 
0004 #include <linux/err.h>
0005 
0006 #include "hnae3.h"
0007 #include "hclge_comm_cmd.h"
0008 #include "hclge_comm_tqp_stats.h"
0009 
0010 u64 *hclge_comm_tqps_get_stats(struct hnae3_handle *handle, u64 *data)
0011 {
0012     struct hnae3_knic_private_info *kinfo = &handle->kinfo;
0013     struct hclge_comm_tqp *tqp;
0014     u64 *buff = data;
0015     u16 i;
0016 
0017     for (i = 0; i < kinfo->num_tqps; i++) {
0018         tqp = container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
0019         *buff++ = tqp->tqp_stats.rcb_tx_ring_pktnum_rcd;
0020     }
0021 
0022     for (i = 0; i < kinfo->num_tqps; i++) {
0023         tqp = container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
0024         *buff++ = tqp->tqp_stats.rcb_rx_ring_pktnum_rcd;
0025     }
0026 
0027     return buff;
0028 }
0029 
0030 int hclge_comm_tqps_get_sset_count(struct hnae3_handle *handle)
0031 {
0032     struct hnae3_knic_private_info *kinfo = &handle->kinfo;
0033 
0034     return kinfo->num_tqps * HCLGE_COMM_QUEUE_PAIR_SIZE;
0035 }
0036 
0037 u8 *hclge_comm_tqps_get_strings(struct hnae3_handle *handle, u8 *data)
0038 {
0039     struct hnae3_knic_private_info *kinfo = &handle->kinfo;
0040     u8 *buff = data;
0041     u16 i;
0042 
0043     for (i = 0; i < kinfo->num_tqps; i++) {
0044         struct hclge_comm_tqp *tqp =
0045             container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
0046         snprintf(buff, ETH_GSTRING_LEN, "txq%u_pktnum_rcd", tqp->index);
0047         buff += ETH_GSTRING_LEN;
0048     }
0049 
0050     for (i = 0; i < kinfo->num_tqps; i++) {
0051         struct hclge_comm_tqp *tqp =
0052             container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
0053         snprintf(buff, ETH_GSTRING_LEN, "rxq%u_pktnum_rcd", tqp->index);
0054         buff += ETH_GSTRING_LEN;
0055     }
0056 
0057     return buff;
0058 }
0059 
0060 int hclge_comm_tqps_update_stats(struct hnae3_handle *handle,
0061                  struct hclge_comm_hw *hw)
0062 {
0063     struct hnae3_knic_private_info *kinfo = &handle->kinfo;
0064     struct hclge_comm_tqp *tqp;
0065     struct hclge_desc desc;
0066     int ret;
0067     u16 i;
0068 
0069     for (i = 0; i < kinfo->num_tqps; i++) {
0070         tqp = container_of(kinfo->tqp[i], struct hclge_comm_tqp, q);
0071         hclge_comm_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_RX_STATS,
0072                         true);
0073 
0074         desc.data[0] = cpu_to_le32(tqp->index);
0075         ret = hclge_comm_cmd_send(hw, &desc, 1);
0076         if (ret) {
0077             dev_err(&hw->cmq.csq.pdev->dev,
0078                 "failed to get tqp stat, ret = %d, rx = %u.\n",
0079                 ret, i);
0080             return ret;
0081         }
0082         tqp->tqp_stats.rcb_rx_ring_pktnum_rcd +=
0083             le32_to_cpu(desc.data[1]);
0084 
0085         hclge_comm_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_TX_STATS,
0086                         true);
0087 
0088         desc.data[0] = cpu_to_le32(tqp->index & 0x1ff);
0089         ret = hclge_comm_cmd_send(hw, &desc, 1);
0090         if (ret) {
0091             dev_err(&hw->cmq.csq.pdev->dev,
0092                 "failed to get tqp stat, ret = %d, tx = %u.\n",
0093                 ret, i);
0094             return ret;
0095         }
0096         tqp->tqp_stats.rcb_tx_ring_pktnum_rcd +=
0097             le32_to_cpu(desc.data[1]);
0098     }
0099 
0100     return 0;
0101 }
0102 
0103 void hclge_comm_reset_tqp_stats(struct hnae3_handle *handle)
0104 {
0105     struct hnae3_knic_private_info *kinfo = &handle->kinfo;
0106     struct hclge_comm_tqp *tqp;
0107     struct hnae3_queue *queue;
0108     u16 i;
0109 
0110     for (i = 0; i < kinfo->num_tqps; i++) {
0111         queue = kinfo->tqp[i];
0112         tqp = container_of(queue, struct hclge_comm_tqp, q);
0113         memset(&tqp->tqp_stats, 0, sizeof(tqp->tqp_stats));
0114     }
0115 }