net/hns3: fix register length when dumping registers
authorChengchang Tang <tangchengchang@huawei.com>
Thu, 14 Jan 2021 13:33:34 +0000 (21:33 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 19 Jan 2021 02:30:32 +0000 (03:30 +0100)
Currently, the reg length return by HNS3 is the total length of all the
registers. But for upper layer user, the total register length is the
length multiplied by width. This can lead to a waste of memory and print
some invalid information.

This patch corrects the length and width of the register.

Fixes: 936eda25e8da ("net/hns3: support dump register")
Cc: stable@dpdk.org
Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
Signed-off-by: Lijun Ou <oulijun@huawei.com>
drivers/net/hns3/hns3_regs.c

index b2cc599..32597fe 100644 (file)
@@ -104,6 +104,7 @@ hns3_get_regs_length(struct hns3_hw *hw, uint32_t *length)
        struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
        uint32_t cmdq_lines, common_lines, ring_lines, tqp_intr_lines;
        uint32_t regs_num_32_bit, regs_num_64_bit;
+       uint32_t dfx_reg_lines;
        uint32_t len;
        int ret;
 
@@ -117,7 +118,7 @@ hns3_get_regs_length(struct hns3_hw *hw, uint32_t *length)
        tqp_intr_lines = sizeof(tqp_intr_reg_addrs) / REG_LEN_PER_LINE + 1;
 
        len = (cmdq_lines + common_lines + ring_lines * hw->tqps_num +
-             tqp_intr_lines * hw->num_msi) * REG_LEN_PER_LINE;
+             tqp_intr_lines * hw->num_msi) * REG_NUM_PER_LINE;
 
        if (!hns->is_vf) {
                ret = hns3_get_regs_num(hw, &regs_num_32_bit, &regs_num_64_bit);
@@ -126,8 +127,11 @@ hns3_get_regs_length(struct hns3_hw *hw, uint32_t *length)
                                 ret);
                        return -ENOTSUP;
                }
-               len += regs_num_32_bit * sizeof(uint32_t) +
-                      regs_num_64_bit * sizeof(uint64_t);
+               dfx_reg_lines = regs_num_32_bit * sizeof(uint32_t) /
+                                       REG_LEN_PER_LINE + 1;
+               dfx_reg_lines += regs_num_64_bit * sizeof(uint64_t) /
+                                       REG_LEN_PER_LINE + 1;
+               len += dfx_reg_lines * REG_NUM_PER_LINE;
        }
 
        *length = len;