| 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 |
|
| 10 |
u64 *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 |
EXPORT_SYMBOL_GPL(hclge_comm_tqps_get_stats); |
| 30 |
|
| 31 |
int hclge_comm_tqps_get_sset_count(struct hnae3_handle *handle) |
| 32 |
{ |
| 33 |
struct hnae3_knic_private_info *kinfo = &handle->kinfo; |
| 34 |
|
| 35 |
return kinfo->num_tqps * HCLGE_COMM_QUEUE_PAIR_SIZE; |
| 36 |
} |
| 37 |
EXPORT_SYMBOL_GPL(hclge_comm_tqps_get_sset_count); |
| 38 |
|
| 39 |
void hclge_comm_tqps_get_strings(struct hnae3_handle *handle, u8 **data) |
| 40 |
{ |
| 41 |
struct hnae3_knic_private_info *kinfo = &handle->kinfo; |
| 42 |
u16 i; |
| 43 |
|
| 44 |
for (i = 0; i < kinfo->num_tqps; i++) { |
| 45 |
struct hclge_comm_tqp *tqp = |
| 46 |
container_of(kinfo->tqp[i], struct hclge_comm_tqp, q); |
| 47 |
ethtool_sprintf(data, "txq%u_pktnum_rcd", tqp->index); |
| 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 |
ethtool_sprintf(data, "rxq%u_pktnum_rcd", tqp->index); |
| 54 |
} |
| 55 |
} |
| 56 |
EXPORT_SYMBOL_GPL(hclge_comm_tqps_get_strings); |
| 57 |
|
| 58 |
int hclge_comm_tqps_update_stats(struct hnae3_handle *handle, |
| 59 |
struct hclge_comm_hw *hw) |
| 60 |
{ |
| 61 |
struct hnae3_knic_private_info *kinfo = &handle->kinfo; |
| 62 |
struct hclge_comm_tqp *tqp; |
| 63 |
struct hclge_desc desc; |
| 64 |
int ret; |
| 65 |
u16 i; |
| 66 |
|
| 67 |
for (i = 0; i < kinfo->num_tqps; i++) { |
| 68 |
tqp = container_of(kinfo->tqp[i], struct hclge_comm_tqp, q); |
| 69 |
hclge_comm_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_RX_STATS, |
| 70 |
true); |
| 71 |
|
| 72 |
desc.data[0] = cpu_to_le32(tqp->index); |
| 73 |
ret = hclge_comm_cmd_send(hw, &desc, 1); |
| 74 |
if (ret) { |
| 75 |
dev_err(&hw->cmq.csq.pdev->dev, |
| 76 |
"failed to get tqp stat, ret = %d, rx = %u.\n", |
| 77 |
ret, i); |
| 78 |
return ret; |
| 79 |
} |
| 80 |
tqp->tqp_stats.rcb_rx_ring_pktnum_rcd += |
| 81 |
le32_to_cpu(desc.data[1]); |
| 82 |
|
| 83 |
hclge_comm_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_TX_STATS, |
| 84 |
true); |
| 85 |
|
| 86 |
desc.data[0] = cpu_to_le32(tqp->index); |
| 87 |
ret = hclge_comm_cmd_send(hw, &desc, 1); |
| 88 |
if (ret) { |
| 89 |
dev_err(&hw->cmq.csq.pdev->dev, |
| 90 |
"failed to get tqp stat, ret = %d, tx = %u.\n", |
| 91 |
ret, i); |
| 92 |
return ret; |
| 93 |
} |
| 94 |
tqp->tqp_stats.rcb_tx_ring_pktnum_rcd += |
| 95 |
le32_to_cpu(desc.data[1]); |
| 96 |
} |
| 97 |
|
| 98 |
return 0; |
| 99 |
} |
| 100 |
EXPORT_SYMBOL_GPL(hclge_comm_tqps_update_stats); |
| 101 |
|
| 102 |
void hclge_comm_reset_tqp_stats(struct hnae3_handle *handle) |
| 103 |
{ |
| 104 |
struct hnae3_knic_private_info *kinfo = &handle->kinfo; |
| 105 |
struct hclge_comm_tqp *tqp; |
| 106 |
struct hnae3_queue *queue; |
| 107 |
u16 i; |
| 108 |
|
| 109 |
for (i = 0; i < kinfo->num_tqps; i++) { |
| 110 |
queue = kinfo->tqp[i]; |
| 111 |
tqp = container_of(queue, struct hclge_comm_tqp, q); |
| 112 |
memset(&tqp->tqp_stats, 0, sizeof(tqp->tqp_stats)); |
| 113 |
} |
| 114 |
} |
| 115 |
EXPORT_SYMBOL_GPL(hclge_comm_reset_tqp_stats); |