xref: /linux/drivers/soc/hisilicon/kunpeng_hccs.h (revision ad30469a841b50dbb541df4d6971d891f703c297)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /* Copyright (c) 2023 Hisilicon Limited. */
3 
4 #ifndef __KUNPENG_HCCS_H__
5 #define __KUNPENG_HCCS_H__
6 
7 /*
8  * |---------------  Chip0  ---------------|----------------  ChipN  -------------|
9  * |--------Die0-------|--------DieN-------|--------Die0-------|-------DieN-------|
10  * | P0 | P1 | P2 | P3 | P0 | P1 | P2 | P3 | P0 | P1 | P2 | P3 |P0 | P1 | P2 | P3 |
11  */
12 
13 /*
14  * This value cannot be 255, otherwise the loop of the multi-BD communication
15  * case cannot end.
16  */
17 #define HCCS_DIE_MAX_PORT_ID	254
18 
19 struct hccs_port_info {
20 	u8 port_id;
21 	u8 port_type;
22 	u8 lane_mode;
23 	bool enable; /* if the port is enabled */
24 	struct kobject kobj;
25 	bool dir_created;
26 	struct hccs_die_info *die; /* point to the die the port is located */
27 };
28 
29 struct hccs_die_info {
30 	u8 die_id;
31 	u8 port_num;
32 	u8 min_port_id;
33 	u8 max_port_id;
34 	struct hccs_port_info *ports;
35 	struct kobject kobj;
36 	bool dir_created;
37 	struct hccs_chip_info *chip; /* point to the chip the die is located */
38 };
39 
40 struct hccs_chip_info {
41 	u8 chip_id;
42 	u8 die_num;
43 	struct hccs_die_info *dies;
44 	struct kobject kobj;
45 	struct hccs_dev *hdev;
46 };
47 
48 struct hccs_mbox_client_info {
49 	struct mbox_client client;
50 	struct mbox_chan *mbox_chan;
51 	struct pcc_mbox_chan *pcc_chan;
52 	u64 deadline_us;
53 	void __iomem *pcc_comm_addr;
54 };
55 
56 struct hccs_dev {
57 	struct device *dev;
58 	struct acpi_device *acpi_dev;
59 	u64 caps;
60 	u8 chip_num;
61 	struct hccs_chip_info *chips;
62 	u8 chan_id;
63 	struct mutex lock;
64 	struct hccs_mbox_client_info cl_info;
65 };
66 
67 #define HCCS_SERDES_MODULE_CODE 0x32
68 enum hccs_subcmd_type {
69 	HCCS_GET_CHIP_NUM = 0x1,
70 	HCCS_GET_DIE_NUM,
71 	HCCS_GET_DIE_INFO,
72 	HCCS_GET_DIE_PORT_INFO,
73 	HCCS_GET_DEV_CAP,
74 	HCCS_GET_PORT_LINK_STATUS,
75 	HCCS_GET_PORT_CRC_ERR_CNT,
76 	HCCS_GET_DIE_PORTS_LANE_STA,
77 	HCCS_GET_DIE_PORTS_LINK_STA,
78 	HCCS_GET_DIE_PORTS_CRC_ERR_CNT,
79 	HCCS_SUB_CMD_MAX = 255,
80 };
81 
82 struct hccs_die_num_req_param {
83 	u8 chip_id;
84 };
85 
86 struct hccs_die_info_req_param {
87 	u8 chip_id;
88 	u8 die_idx;
89 };
90 
91 struct hccs_die_info_rsp_data {
92 	u8 die_id;
93 	u8 port_num;
94 	u8 min_port_id;
95 	u8 max_port_id;
96 };
97 
98 struct hccs_port_attr {
99 	u8 port_id;
100 	u8 port_type;
101 	u8 lane_mode;
102 	u8 enable : 1; /* if the port is enabled */
103 	u16 rsv[2];
104 };
105 
106 /*
107  * The common command request for getting the information of all HCCS port on
108  * specified DIE.
109  */
110 struct hccs_die_comm_req_param {
111 	u8 chip_id;
112 	u8 die_id; /* id in hardware */
113 };
114 
115 /* The common command request for getting the information of a specific port */
116 struct hccs_port_comm_req_param {
117 	u8 chip_id;
118 	u8 die_id;
119 	u8 port_id;
120 };
121 
122 #define HCCS_PORT_RESET         1
123 #define HCCS_PORT_SETUP         2
124 #define HCCS_PORT_CONFIG        3
125 #define HCCS_PORT_READY         4
126 struct hccs_link_status {
127 	u8 lane_mask; /* indicate which lanes are used. */
128 	u8 link_fsm : 3; /* link fsm, 1: reset 2: setup 3: config 4: link-up */
129 	u8 lane_num : 5; /* current lane number */
130 };
131 
132 struct hccs_req_head {
133 	u8 module_code; /* set to 0x32 for serdes */
134 	u8 start_id;
135 	u8 rsv[2];
136 };
137 
138 struct hccs_rsp_head {
139 	u8 data_len;
140 	u8 next_id;
141 	u8 rsv[2];
142 };
143 
144 struct hccs_fw_inner_head {
145 	u8 retStatus; /* 0: success, other: failure */
146 	u8 rsv[7];
147 };
148 
149 #define HCCS_PCC_SHARE_MEM_BYTES	64
150 #define HCCS_FW_INNER_HEAD_BYTES	8
151 #define HCCS_RSP_HEAD_BYTES		4
152 
153 #define HCCS_MAX_RSP_DATA_BYTES		(HCCS_PCC_SHARE_MEM_BYTES - \
154 					 HCCS_FW_INNER_HEAD_BYTES - \
155 					 HCCS_RSP_HEAD_BYTES)
156 #define HCCS_MAX_RSP_DATA_SIZE_MAX	(HCCS_MAX_RSP_DATA_BYTES / 4)
157 
158 /*
159  * Note: Actual available size of data field also depands on the PCC header
160  * bytes of the specific type. Driver needs to copy the response data in the
161  * communication space based on the real length.
162  */
163 struct hccs_rsp_desc {
164 	struct hccs_fw_inner_head fw_inner_head; /* 8 Bytes */
165 	struct hccs_rsp_head rsp_head; /* 4 Bytes */
166 	u32 data[HCCS_MAX_RSP_DATA_SIZE_MAX];
167 };
168 
169 #define HCCS_REQ_HEAD_BYTES		4
170 #define HCCS_MAX_REQ_DATA_BYTES		(HCCS_PCC_SHARE_MEM_BYTES - \
171 					 HCCS_REQ_HEAD_BYTES)
172 #define HCCS_MAX_REQ_DATA_SIZE_MAX	(HCCS_MAX_REQ_DATA_BYTES / 4)
173 
174 /*
175  * Note: Actual available size of data field also depands on the PCC header
176  * bytes of the specific type. Driver needs to copy the request data to the
177  * communication space based on the real length.
178  */
179 struct hccs_req_desc {
180 	struct hccs_req_head req_head; /* 4 Bytes */
181 	u32 data[HCCS_MAX_REQ_DATA_SIZE_MAX];
182 };
183 
184 struct hccs_desc {
185 	union {
186 		struct hccs_req_desc req;
187 		struct hccs_rsp_desc rsp;
188 	};
189 };
190 
191 #endif /* __KUNPENG_HCCS_H__ */
192