xref: /openbmc/linux/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_regs.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1939ccd10SJijie Shao // SPDX-License-Identifier: GPL-2.0+
2939ccd10SJijie Shao // Copyright (c) 2023 Hisilicon Limited.
3939ccd10SJijie Shao 
4939ccd10SJijie Shao #include "hclgevf_main.h"
5939ccd10SJijie Shao #include "hclgevf_regs.h"
6939ccd10SJijie Shao #include "hnae3.h"
7939ccd10SJijie Shao 
8939ccd10SJijie Shao static const u32 cmdq_reg_addr_list[] = {HCLGE_COMM_NIC_CSQ_BASEADDR_L_REG,
9939ccd10SJijie Shao 					 HCLGE_COMM_NIC_CSQ_BASEADDR_H_REG,
10939ccd10SJijie Shao 					 HCLGE_COMM_NIC_CSQ_DEPTH_REG,
11939ccd10SJijie Shao 					 HCLGE_COMM_NIC_CSQ_TAIL_REG,
12939ccd10SJijie Shao 					 HCLGE_COMM_NIC_CSQ_HEAD_REG,
13939ccd10SJijie Shao 					 HCLGE_COMM_NIC_CRQ_BASEADDR_L_REG,
14939ccd10SJijie Shao 					 HCLGE_COMM_NIC_CRQ_BASEADDR_H_REG,
15939ccd10SJijie Shao 					 HCLGE_COMM_NIC_CRQ_DEPTH_REG,
16939ccd10SJijie Shao 					 HCLGE_COMM_NIC_CRQ_TAIL_REG,
17939ccd10SJijie Shao 					 HCLGE_COMM_NIC_CRQ_HEAD_REG,
18939ccd10SJijie Shao 					 HCLGE_COMM_VECTOR0_CMDQ_SRC_REG,
19939ccd10SJijie Shao 					 HCLGE_COMM_VECTOR0_CMDQ_STATE_REG,
20939ccd10SJijie Shao 					 HCLGE_COMM_CMDQ_INTR_EN_REG,
21939ccd10SJijie Shao 					 HCLGE_COMM_CMDQ_INTR_GEN_REG};
22939ccd10SJijie Shao 
23939ccd10SJijie Shao static const u32 common_reg_addr_list[] = {HCLGEVF_MISC_VECTOR_REG_BASE,
24939ccd10SJijie Shao 					   HCLGEVF_RST_ING,
25939ccd10SJijie Shao 					   HCLGEVF_GRO_EN_REG};
26939ccd10SJijie Shao 
27939ccd10SJijie Shao static const u32 ring_reg_addr_list[] = {HCLGEVF_RING_RX_ADDR_L_REG,
28939ccd10SJijie Shao 					 HCLGEVF_RING_RX_ADDR_H_REG,
29939ccd10SJijie Shao 					 HCLGEVF_RING_RX_BD_NUM_REG,
30939ccd10SJijie Shao 					 HCLGEVF_RING_RX_BD_LENGTH_REG,
31939ccd10SJijie Shao 					 HCLGEVF_RING_RX_MERGE_EN_REG,
32939ccd10SJijie Shao 					 HCLGEVF_RING_RX_TAIL_REG,
33939ccd10SJijie Shao 					 HCLGEVF_RING_RX_HEAD_REG,
34939ccd10SJijie Shao 					 HCLGEVF_RING_RX_FBD_NUM_REG,
35939ccd10SJijie Shao 					 HCLGEVF_RING_RX_OFFSET_REG,
36939ccd10SJijie Shao 					 HCLGEVF_RING_RX_FBD_OFFSET_REG,
37939ccd10SJijie Shao 					 HCLGEVF_RING_RX_STASH_REG,
38939ccd10SJijie Shao 					 HCLGEVF_RING_RX_BD_ERR_REG,
39939ccd10SJijie Shao 					 HCLGEVF_RING_TX_ADDR_L_REG,
40939ccd10SJijie Shao 					 HCLGEVF_RING_TX_ADDR_H_REG,
41939ccd10SJijie Shao 					 HCLGEVF_RING_TX_BD_NUM_REG,
42939ccd10SJijie Shao 					 HCLGEVF_RING_TX_PRIORITY_REG,
43939ccd10SJijie Shao 					 HCLGEVF_RING_TX_TC_REG,
44939ccd10SJijie Shao 					 HCLGEVF_RING_TX_MERGE_EN_REG,
45939ccd10SJijie Shao 					 HCLGEVF_RING_TX_TAIL_REG,
46939ccd10SJijie Shao 					 HCLGEVF_RING_TX_HEAD_REG,
47939ccd10SJijie Shao 					 HCLGEVF_RING_TX_FBD_NUM_REG,
48939ccd10SJijie Shao 					 HCLGEVF_RING_TX_OFFSET_REG,
49939ccd10SJijie Shao 					 HCLGEVF_RING_TX_EBD_NUM_REG,
50939ccd10SJijie Shao 					 HCLGEVF_RING_TX_EBD_OFFSET_REG,
51939ccd10SJijie Shao 					 HCLGEVF_RING_TX_BD_ERR_REG,
52939ccd10SJijie Shao 					 HCLGEVF_RING_EN_REG};
53939ccd10SJijie Shao 
54939ccd10SJijie Shao static const u32 tqp_intr_reg_addr_list[] = {HCLGEVF_TQP_INTR_CTRL_REG,
55939ccd10SJijie Shao 					     HCLGEVF_TQP_INTR_GL0_REG,
56939ccd10SJijie Shao 					     HCLGEVF_TQP_INTR_GL1_REG,
57939ccd10SJijie Shao 					     HCLGEVF_TQP_INTR_GL2_REG,
58939ccd10SJijie Shao 					     HCLGEVF_TQP_INTR_RL_REG};
59939ccd10SJijie Shao 
60*3ef5d70bSJijie Shao enum hclgevf_reg_tag {
61*3ef5d70bSJijie Shao 	HCLGEVF_REG_TAG_CMDQ = 0,
62*3ef5d70bSJijie Shao 	HCLGEVF_REG_TAG_COMMON,
63*3ef5d70bSJijie Shao 	HCLGEVF_REG_TAG_RING,
64*3ef5d70bSJijie Shao 	HCLGEVF_REG_TAG_TQP_INTR,
65*3ef5d70bSJijie Shao };
66*3ef5d70bSJijie Shao 
67*3ef5d70bSJijie Shao #pragma pack(4)
68*3ef5d70bSJijie Shao struct hclgevf_reg_tlv {
69*3ef5d70bSJijie Shao 	u16 tag;
70*3ef5d70bSJijie Shao 	u16 len;
71*3ef5d70bSJijie Shao };
72*3ef5d70bSJijie Shao 
73*3ef5d70bSJijie Shao struct hclgevf_reg_header {
74*3ef5d70bSJijie Shao 	u64 magic_number;
75*3ef5d70bSJijie Shao 	u8 is_vf;
76*3ef5d70bSJijie Shao 	u8 rsv[7];
77*3ef5d70bSJijie Shao };
78*3ef5d70bSJijie Shao 
79*3ef5d70bSJijie Shao #pragma pack()
80*3ef5d70bSJijie Shao 
81*3ef5d70bSJijie Shao #define HCLGEVF_REG_TLV_SIZE		sizeof(struct hclgevf_reg_tlv)
82*3ef5d70bSJijie Shao #define HCLGEVF_REG_HEADER_SIZE		sizeof(struct hclgevf_reg_header)
83*3ef5d70bSJijie Shao #define HCLGEVF_REG_TLV_SPACE		(sizeof(struct hclgevf_reg_tlv) / sizeof(u32))
84*3ef5d70bSJijie Shao #define HCLGEVF_REG_HEADER_SPACE	(sizeof(struct hclgevf_reg_header) / sizeof(u32))
85*3ef5d70bSJijie Shao #define HCLGEVF_REG_MAGIC_NUMBER	0x686e733372656773 /* meaning is hns3regs */
86*3ef5d70bSJijie Shao 
hclgevf_reg_get_header(void * data)87*3ef5d70bSJijie Shao static u32 hclgevf_reg_get_header(void *data)
88*3ef5d70bSJijie Shao {
89*3ef5d70bSJijie Shao 	struct hclgevf_reg_header *header = data;
90*3ef5d70bSJijie Shao 
91*3ef5d70bSJijie Shao 	header->magic_number = HCLGEVF_REG_MAGIC_NUMBER;
92*3ef5d70bSJijie Shao 	header->is_vf = 0x1;
93*3ef5d70bSJijie Shao 
94*3ef5d70bSJijie Shao 	return HCLGEVF_REG_HEADER_SPACE;
95*3ef5d70bSJijie Shao }
96*3ef5d70bSJijie Shao 
hclgevf_reg_get_tlv(u32 tag,u32 regs_num,void * data)97*3ef5d70bSJijie Shao static u32 hclgevf_reg_get_tlv(u32 tag, u32 regs_num, void *data)
98*3ef5d70bSJijie Shao {
99*3ef5d70bSJijie Shao 	struct hclgevf_reg_tlv *tlv = data;
100*3ef5d70bSJijie Shao 
101*3ef5d70bSJijie Shao 	tlv->tag = tag;
102*3ef5d70bSJijie Shao 	tlv->len = regs_num * sizeof(u32) + HCLGEVF_REG_TLV_SIZE;
103*3ef5d70bSJijie Shao 
104*3ef5d70bSJijie Shao 	return HCLGEVF_REG_TLV_SPACE;
105*3ef5d70bSJijie Shao }
106939ccd10SJijie Shao 
hclgevf_get_regs_len(struct hnae3_handle * handle)107939ccd10SJijie Shao int hclgevf_get_regs_len(struct hnae3_handle *handle)
108939ccd10SJijie Shao {
109939ccd10SJijie Shao 	struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
110*3ef5d70bSJijie Shao 	int cmdq_len, common_len, ring_len, tqp_intr_len;
111939ccd10SJijie Shao 
112*3ef5d70bSJijie Shao 	cmdq_len = HCLGEVF_REG_TLV_SIZE + sizeof(cmdq_reg_addr_list);
113*3ef5d70bSJijie Shao 	common_len = HCLGEVF_REG_TLV_SIZE + sizeof(common_reg_addr_list);
114*3ef5d70bSJijie Shao 	ring_len = HCLGEVF_REG_TLV_SIZE + sizeof(ring_reg_addr_list);
115*3ef5d70bSJijie Shao 	tqp_intr_len = HCLGEVF_REG_TLV_SIZE + sizeof(tqp_intr_reg_addr_list);
116939ccd10SJijie Shao 
117*3ef5d70bSJijie Shao 	/* return the total length of all register values */
118*3ef5d70bSJijie Shao 	return HCLGEVF_REG_HEADER_SIZE + cmdq_len + common_len +
119*3ef5d70bSJijie Shao 	       tqp_intr_len * (hdev->num_msi_used - 1) +
120*3ef5d70bSJijie Shao 	       ring_len * hdev->num_tqps;
121939ccd10SJijie Shao }
122939ccd10SJijie Shao 
hclgevf_get_regs(struct hnae3_handle * handle,u32 * version,void * data)123939ccd10SJijie Shao void hclgevf_get_regs(struct hnae3_handle *handle, u32 *version,
124939ccd10SJijie Shao 		      void *data)
125939ccd10SJijie Shao {
126939ccd10SJijie Shao #define HCLGEVF_RING_REG_OFFSET		0x200
127939ccd10SJijie Shao #define HCLGEVF_RING_INT_REG_OFFSET	0x4
128939ccd10SJijie Shao 
129939ccd10SJijie Shao 	struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
130*3ef5d70bSJijie Shao 	int i, j, reg_um;
131939ccd10SJijie Shao 	u32 *reg = data;
132939ccd10SJijie Shao 
133939ccd10SJijie Shao 	*version = hdev->fw_version;
134*3ef5d70bSJijie Shao 	reg += hclgevf_reg_get_header(reg);
135939ccd10SJijie Shao 
136939ccd10SJijie Shao 	/* fetching per-VF registers values from VF PCIe register space */
137939ccd10SJijie Shao 	reg_um = sizeof(cmdq_reg_addr_list) / sizeof(u32);
138*3ef5d70bSJijie Shao 	reg += hclgevf_reg_get_tlv(HCLGEVF_REG_TAG_CMDQ, reg_um, reg);
139939ccd10SJijie Shao 	for (i = 0; i < reg_um; i++)
140939ccd10SJijie Shao 		*reg++ = hclgevf_read_dev(&hdev->hw, cmdq_reg_addr_list[i]);
141939ccd10SJijie Shao 
142939ccd10SJijie Shao 	reg_um = sizeof(common_reg_addr_list) / sizeof(u32);
143*3ef5d70bSJijie Shao 	reg += hclgevf_reg_get_tlv(HCLGEVF_REG_TAG_COMMON, reg_um, reg);
144939ccd10SJijie Shao 	for (i = 0; i < reg_um; i++)
145939ccd10SJijie Shao 		*reg++ = hclgevf_read_dev(&hdev->hw, common_reg_addr_list[i]);
146939ccd10SJijie Shao 
147939ccd10SJijie Shao 	reg_um = sizeof(ring_reg_addr_list) / sizeof(u32);
148939ccd10SJijie Shao 	for (j = 0; j < hdev->num_tqps; j++) {
149*3ef5d70bSJijie Shao 		reg += hclgevf_reg_get_tlv(HCLGEVF_REG_TAG_RING, reg_um, reg);
150939ccd10SJijie Shao 		for (i = 0; i < reg_um; i++)
151939ccd10SJijie Shao 			*reg++ = hclgevf_read_dev(&hdev->hw,
152939ccd10SJijie Shao 						  ring_reg_addr_list[i] +
153939ccd10SJijie Shao 						  HCLGEVF_RING_REG_OFFSET * j);
154939ccd10SJijie Shao 	}
155939ccd10SJijie Shao 
156939ccd10SJijie Shao 	reg_um = sizeof(tqp_intr_reg_addr_list) / sizeof(u32);
157939ccd10SJijie Shao 	for (j = 0; j < hdev->num_msi_used - 1; j++) {
158*3ef5d70bSJijie Shao 		reg += hclgevf_reg_get_tlv(HCLGEVF_REG_TAG_TQP_INTR, reg_um, reg);
159939ccd10SJijie Shao 		for (i = 0; i < reg_um; i++)
160939ccd10SJijie Shao 			*reg++ = hclgevf_read_dev(&hdev->hw,
161939ccd10SJijie Shao 						  tqp_intr_reg_addr_list[i] +
162939ccd10SJijie Shao 						  HCLGEVF_RING_INT_REG_OFFSET * j);
163939ccd10SJijie Shao 	}
164939ccd10SJijie Shao }
165