Skip to content

Commit 5e5e148

Browse files
Jie Haiferruhy
authored andcommitted
net/hns3: refactor register dump
This patch refactors codes dumping registers from firmware. Signed-off-by: Jie Hai <[email protected]> Acked-by: Chengwen Feng <[email protected]>
1 parent 22a6e6e commit 5e5e148

File tree

1 file changed

+115
-88
lines changed

1 file changed

+115
-88
lines changed

drivers/net/hns3/hns3_regs.c

Lines changed: 115 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,93 @@ hns3_get_regs_num(struct hns3_hw *hw, uint32_t *regs_num_32_bit,
104104
return 0;
105105
}
106106

107+
static int
108+
hns3_get_32_64_regs_cnt(struct hns3_hw *hw, uint32_t *count)
109+
{
110+
uint32_t regs_num_32_bit, regs_num_64_bit;
111+
int ret;
112+
113+
ret = hns3_get_regs_num(hw, &regs_num_32_bit, &regs_num_64_bit);
114+
if (ret) {
115+
hns3_err(hw, "fail to get the number of registers, "
116+
"ret = %d.", ret);
117+
return ret;
118+
}
119+
120+
*count += regs_num_32_bit + regs_num_64_bit * HNS3_64_BIT_REG_OUTPUT_SIZE;
121+
return 0;
122+
}
123+
124+
static int
125+
hns3_get_dfx_reg_bd_num(struct hns3_hw *hw, uint32_t *bd_num_list,
126+
uint32_t list_size)
127+
{
128+
#define HNS3_GET_DFX_REG_BD_NUM_SIZE 4
129+
struct hns3_cmd_desc desc[HNS3_GET_DFX_REG_BD_NUM_SIZE];
130+
uint32_t index, desc_index;
131+
uint32_t bd_num;
132+
uint32_t i;
133+
int ret;
134+
135+
for (i = 0; i < HNS3_GET_DFX_REG_BD_NUM_SIZE - 1; i++) {
136+
hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_DFX_BD_NUM, true);
137+
desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
138+
}
139+
/* The last BD does not need a next flag */
140+
hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_DFX_BD_NUM, true);
141+
142+
ret = hns3_cmd_send(hw, desc, HNS3_GET_DFX_REG_BD_NUM_SIZE);
143+
if (ret) {
144+
hns3_err(hw, "fail to get dfx bd num, ret = %d.\n", ret);
145+
return ret;
146+
}
147+
148+
/* The first data in the first BD is a reserved field */
149+
for (i = 1; i <= list_size; i++) {
150+
desc_index = i / HNS3_CMD_DESC_DATA_NUM;
151+
index = i % HNS3_CMD_DESC_DATA_NUM;
152+
bd_num = rte_le_to_cpu_32(desc[desc_index].data[index]);
153+
bd_num_list[i - 1] = bd_num;
154+
}
155+
156+
return 0;
157+
}
158+
159+
static int
160+
hns3_get_dfx_reg_cnt(struct hns3_hw *hw, uint32_t *count)
161+
{
162+
int opcode_num = RTE_DIM(hns3_dfx_reg_opcode_list);
163+
uint32_t bd_num_list[opcode_num];
164+
int ret;
165+
int i;
166+
167+
ret = hns3_get_dfx_reg_bd_num(hw, bd_num_list, opcode_num);
168+
if (ret)
169+
return ret;
170+
171+
for (i = 0; i < opcode_num; i++)
172+
*count += bd_num_list[i] * HNS3_CMD_DESC_DATA_NUM;
173+
174+
return 0;
175+
}
176+
177+
static int
178+
hns3_get_firmware_reg_cnt(struct hns3_hw *hw, uint32_t *count)
179+
{
180+
int ret;
181+
182+
ret = hns3_get_32_64_regs_cnt(hw, count);
183+
if (ret < 0)
184+
return ret;
185+
186+
return hns3_get_dfx_reg_cnt(hw, count);
187+
}
188+
107189
static int
108190
hns3_get_regs_length(struct hns3_hw *hw, uint32_t *length)
109191
{
110192
struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
111-
uint32_t regs_num_32_bit, regs_num_64_bit;
112-
uint32_t dfx_reg_cnt;
193+
uint32_t dfx_reg_cnt = 0;
113194
uint32_t common_cnt;
114195
uint32_t len;
115196
int ret;
@@ -125,16 +206,7 @@ hns3_get_regs_length(struct hns3_hw *hw, uint32_t *length)
125206
len /= sizeof(uint32_t);
126207

127208
if (!hns->is_vf) {
128-
ret = hns3_get_regs_num(hw, &regs_num_32_bit, &regs_num_64_bit);
129-
if (ret) {
130-
hns3_err(hw, "fail to get the number of registers, "
131-
"ret = %d.", ret);
132-
return ret;
133-
}
134-
dfx_reg_cnt = regs_num_32_bit +
135-
regs_num_64_bit * HNS3_64_BIT_REG_OUTPUT_SIZE;
136-
137-
ret = hns3_get_dfx_reg_cnt(hw, &dfx_reg_cnt);
209+
ret = hns3_get_firmware_reg_cnt(hw, &dfx_reg_cnt);
138210
if (ret) {
139211
hns3_err(hw, "fail to get the number of dfx registers, "
140212
"ret = %d.", ret);
@@ -304,41 +376,6 @@ hns3_direct_access_regs(struct hns3_hw *hw, uint32_t *data)
304376
return data - origin_data_ptr;
305377
}
306378

307-
static int
308-
hns3_get_dfx_reg_bd_num(struct hns3_hw *hw, uint32_t *bd_num_list,
309-
uint32_t list_size)
310-
{
311-
#define HNS3_GET_DFX_REG_BD_NUM_SIZE 4
312-
struct hns3_cmd_desc desc[HNS3_GET_DFX_REG_BD_NUM_SIZE];
313-
uint32_t index, desc_index;
314-
uint32_t bd_num;
315-
uint32_t i;
316-
int ret;
317-
318-
for (i = 0; i < HNS3_GET_DFX_REG_BD_NUM_SIZE - 1; i++) {
319-
hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_DFX_BD_NUM, true);
320-
desc[i].flag |= rte_cpu_to_le_16(HNS3_CMD_FLAG_NEXT);
321-
}
322-
/* The last BD does not need a next flag */
323-
hns3_cmd_setup_basic_desc(&desc[i], HNS3_OPC_DFX_BD_NUM, true);
324-
325-
ret = hns3_cmd_send(hw, desc, HNS3_GET_DFX_REG_BD_NUM_SIZE);
326-
if (ret) {
327-
hns3_err(hw, "fail to get dfx bd num, ret = %d.\n", ret);
328-
return ret;
329-
}
330-
331-
/* The first data in the first BD is a reserved field */
332-
for (i = 1; i <= list_size; i++) {
333-
desc_index = i / HNS3_CMD_DESC_DATA_NUM;
334-
index = i % HNS3_CMD_DESC_DATA_NUM;
335-
bd_num = rte_le_to_cpu_32(desc[desc_index].data[index]);
336-
bd_num_list[i - 1] = bd_num;
337-
}
338-
339-
return 0;
340-
}
341-
342379
static int
343380
hns3_dfx_reg_cmd_send(struct hns3_hw *hw, struct hns3_cmd_desc *desc,
344381
int bd_num, uint32_t opcode)
@@ -379,24 +416,6 @@ hns3_dfx_reg_fetch_data(struct hns3_cmd_desc *desc, int bd_num, uint32_t *reg)
379416
return reg_num;
380417
}
381418

382-
static int
383-
hns3_get_dfx_reg_cnt(struct hns3_hw *hw, uint32_t *count)
384-
{
385-
int opcode_num = RTE_DIM(hns3_dfx_reg_opcode_list);
386-
uint32_t bd_num_list[opcode_num];
387-
int ret;
388-
int i;
389-
390-
ret = hns3_get_dfx_reg_bd_num(hw, bd_num_list, opcode_num);
391-
if (ret)
392-
return ret;
393-
394-
for (i = 0; i < opcode_num; i++)
395-
*count += bd_num_list[i] * HNS3_CMD_DESC_DATA_NUM;
396-
397-
return 0;
398-
}
399-
400419
static int
401420
hns3_get_dfx_regs(struct hns3_hw *hw, void **data)
402421
{
@@ -436,13 +455,41 @@ hns3_get_dfx_regs(struct hns3_hw *hw, void **data)
436455
return ret;
437456
}
438457

458+
static int
459+
hns3_get_regs_from_firmware(struct hns3_hw *hw, uint32_t *data)
460+
{
461+
uint32_t regs_num_32_bit;
462+
uint32_t regs_num_64_bit;
463+
int ret;
464+
465+
ret = hns3_get_regs_num(hw, &regs_num_32_bit, &regs_num_64_bit);
466+
if (ret) {
467+
hns3_err(hw, "Get register number failed, ret = %d", ret);
468+
return ret;
469+
}
470+
471+
ret = hns3_get_32_bit_regs(hw, regs_num_32_bit, data);
472+
if (ret) {
473+
hns3_err(hw, "Get 32 bit register failed, ret = %d", ret);
474+
return ret;
475+
}
476+
data += regs_num_32_bit;
477+
478+
ret = hns3_get_64_bit_regs(hw, regs_num_64_bit, data);
479+
if (ret) {
480+
hns3_err(hw, "Get 64 bit register failed, ret = %d", ret);
481+
return ret;
482+
}
483+
data += regs_num_64_bit * HNS3_64_BIT_REG_OUTPUT_SIZE;
484+
485+
return hns3_get_dfx_regs(hw, (void **)&data);
486+
}
487+
439488
int
440489
hns3_get_regs(struct rte_eth_dev *eth_dev, struct rte_dev_reg_info *regs)
441490
{
442491
struct hns3_adapter *hns = eth_dev->data->dev_private;
443492
struct hns3_hw *hw = &hns->hw;
444-
uint32_t regs_num_32_bit;
445-
uint32_t regs_num_64_bit;
446493
uint32_t length;
447494
uint32_t *data;
448495
int ret;
@@ -470,26 +517,6 @@ hns3_get_regs(struct rte_eth_dev *eth_dev, struct rte_dev_reg_info *regs)
470517
if (hns->is_vf)
471518
return 0;
472519

473-
ret = hns3_get_regs_num(hw, &regs_num_32_bit, &regs_num_64_bit);
474-
if (ret) {
475-
hns3_err(hw, "Get register number failed, ret = %d", ret);
476-
return ret;
477-
}
478-
479520
/* fetching PF common registers values from firmware */
480-
ret = hns3_get_32_bit_regs(hw, regs_num_32_bit, data);
481-
if (ret) {
482-
hns3_err(hw, "Get 32 bit register failed, ret = %d", ret);
483-
return ret;
484-
}
485-
data += regs_num_32_bit;
486-
487-
ret = hns3_get_64_bit_regs(hw, regs_num_64_bit, data);
488-
if (ret) {
489-
hns3_err(hw, "Get 64 bit register failed, ret = %d", ret);
490-
return ret;
491-
}
492-
data += regs_num_64_bit * HNS3_64_BIT_REG_OUTPUT_SIZE;
493-
494-
return hns3_get_dfx_regs(hw, (void **)&data);
521+
return hns3_get_regs_from_firmware(hw, data);
495522
}

0 commit comments

Comments
 (0)