xref: /openbmc/linux/drivers/soc/hisilicon/kunpeng_hccs.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1886bdf9cSHuisong Li /* SPDX-License-Identifier: GPL-2.0+ */
2886bdf9cSHuisong Li /* Copyright (c) 2023 Hisilicon Limited. */
3886bdf9cSHuisong Li 
4886bdf9cSHuisong Li #ifndef __KUNPENG_HCCS_H__
5886bdf9cSHuisong Li #define __KUNPENG_HCCS_H__
6886bdf9cSHuisong Li 
7886bdf9cSHuisong Li /*
8886bdf9cSHuisong Li  * |---------------  Chip0  ---------------|----------------  ChipN  -------------|
9886bdf9cSHuisong Li  * |--------Die0-------|--------DieN-------|--------Die0-------|-------DieN-------|
10886bdf9cSHuisong Li  * | P0 | P1 | P2 | P3 | P0 | P1 | P2 | P3 | P0 | P1 | P2 | P3 |P0 | P1 | P2 | P3 |
11886bdf9cSHuisong Li  */
12886bdf9cSHuisong Li 
13886bdf9cSHuisong Li /*
14886bdf9cSHuisong Li  * This value cannot be 255, otherwise the loop of the multi-BD communication
15886bdf9cSHuisong Li  * case cannot end.
16886bdf9cSHuisong Li  */
17886bdf9cSHuisong Li #define HCCS_DIE_MAX_PORT_ID	254
18886bdf9cSHuisong Li 
19886bdf9cSHuisong Li struct hccs_port_info {
20886bdf9cSHuisong Li 	u8 port_id;
21886bdf9cSHuisong Li 	u8 port_type;
22886bdf9cSHuisong Li 	u8 lane_mode;
23886bdf9cSHuisong Li 	bool enable; /* if the port is enabled */
2447f7a255SHuisong Li 	struct kobject kobj;
2547f7a255SHuisong Li 	bool dir_created;
26886bdf9cSHuisong Li 	struct hccs_die_info *die; /* point to the die the port is located */
27886bdf9cSHuisong Li };
28886bdf9cSHuisong Li 
29886bdf9cSHuisong Li struct hccs_die_info {
30886bdf9cSHuisong Li 	u8 die_id;
31886bdf9cSHuisong Li 	u8 port_num;
32886bdf9cSHuisong Li 	u8 min_port_id;
33886bdf9cSHuisong Li 	u8 max_port_id;
34886bdf9cSHuisong Li 	struct hccs_port_info *ports;
3547f7a255SHuisong Li 	struct kobject kobj;
3647f7a255SHuisong Li 	bool dir_created;
37886bdf9cSHuisong Li 	struct hccs_chip_info *chip; /* point to the chip the die is located */
38886bdf9cSHuisong Li };
39886bdf9cSHuisong Li 
40886bdf9cSHuisong Li struct hccs_chip_info {
41886bdf9cSHuisong Li 	u8 chip_id;
42886bdf9cSHuisong Li 	u8 die_num;
43886bdf9cSHuisong Li 	struct hccs_die_info *dies;
4447f7a255SHuisong Li 	struct kobject kobj;
45886bdf9cSHuisong Li 	struct hccs_dev *hdev;
46886bdf9cSHuisong Li };
47886bdf9cSHuisong Li 
48886bdf9cSHuisong Li struct hccs_mbox_client_info {
49886bdf9cSHuisong Li 	struct mbox_client client;
50886bdf9cSHuisong Li 	struct mbox_chan *mbox_chan;
51886bdf9cSHuisong Li 	struct pcc_mbox_chan *pcc_chan;
52886bdf9cSHuisong Li 	u64 deadline_us;
53*7d661283SHuisong Li 	void __iomem *pcc_comm_addr;
54886bdf9cSHuisong Li };
55886bdf9cSHuisong Li 
56886bdf9cSHuisong Li struct hccs_dev {
57886bdf9cSHuisong Li 	struct device *dev;
58886bdf9cSHuisong Li 	struct acpi_device *acpi_dev;
59886bdf9cSHuisong Li 	u64 caps;
60886bdf9cSHuisong Li 	u8 chip_num;
61886bdf9cSHuisong Li 	struct hccs_chip_info *chips;
62886bdf9cSHuisong Li 	u8 chan_id;
63886bdf9cSHuisong Li 	struct mutex lock;
64886bdf9cSHuisong Li 	struct hccs_mbox_client_info cl_info;
65886bdf9cSHuisong Li };
66886bdf9cSHuisong Li 
67886bdf9cSHuisong Li #define HCCS_SERDES_MODULE_CODE 0x32
68886bdf9cSHuisong Li enum hccs_subcmd_type {
69886bdf9cSHuisong Li 	HCCS_GET_CHIP_NUM = 0x1,
70886bdf9cSHuisong Li 	HCCS_GET_DIE_NUM,
71886bdf9cSHuisong Li 	HCCS_GET_DIE_INFO,
72886bdf9cSHuisong Li 	HCCS_GET_DIE_PORT_INFO,
73886bdf9cSHuisong Li 	HCCS_GET_DEV_CAP,
74886bdf9cSHuisong Li 	HCCS_GET_PORT_LINK_STATUS,
75886bdf9cSHuisong Li 	HCCS_GET_PORT_CRC_ERR_CNT,
76886bdf9cSHuisong Li 	HCCS_GET_DIE_PORTS_LANE_STA,
77886bdf9cSHuisong Li 	HCCS_GET_DIE_PORTS_LINK_STA,
78886bdf9cSHuisong Li 	HCCS_GET_DIE_PORTS_CRC_ERR_CNT,
79886bdf9cSHuisong Li 	HCCS_SUB_CMD_MAX = 255,
80886bdf9cSHuisong Li };
81886bdf9cSHuisong Li 
82886bdf9cSHuisong Li struct hccs_die_num_req_param {
83886bdf9cSHuisong Li 	u8 chip_id;
84886bdf9cSHuisong Li };
85886bdf9cSHuisong Li 
86886bdf9cSHuisong Li struct hccs_die_info_req_param {
87886bdf9cSHuisong Li 	u8 chip_id;
88886bdf9cSHuisong Li 	u8 die_idx;
89886bdf9cSHuisong Li };
90886bdf9cSHuisong Li 
91886bdf9cSHuisong Li struct hccs_die_info_rsp_data {
92886bdf9cSHuisong Li 	u8 die_id;
93886bdf9cSHuisong Li 	u8 port_num;
94886bdf9cSHuisong Li 	u8 min_port_id;
95886bdf9cSHuisong Li 	u8 max_port_id;
96886bdf9cSHuisong Li };
97886bdf9cSHuisong Li 
98886bdf9cSHuisong Li struct hccs_port_attr {
99886bdf9cSHuisong Li 	u8 port_id;
100886bdf9cSHuisong Li 	u8 port_type;
101886bdf9cSHuisong Li 	u8 lane_mode;
102886bdf9cSHuisong Li 	u8 enable : 1; /* if the port is enabled */
103886bdf9cSHuisong Li 	u16 rsv[2];
104886bdf9cSHuisong Li };
105886bdf9cSHuisong Li 
106886bdf9cSHuisong Li /*
107886bdf9cSHuisong Li  * The common command request for getting the information of all HCCS port on
108886bdf9cSHuisong Li  * specified DIE.
109886bdf9cSHuisong Li  */
110886bdf9cSHuisong Li struct hccs_die_comm_req_param {
111886bdf9cSHuisong Li 	u8 chip_id;
112886bdf9cSHuisong Li 	u8 die_id; /* id in hardware */
113886bdf9cSHuisong Li };
114886bdf9cSHuisong Li 
11547f7a255SHuisong Li /* The common command request for getting the information of a specific port */
11647f7a255SHuisong Li struct hccs_port_comm_req_param {
11747f7a255SHuisong Li 	u8 chip_id;
11847f7a255SHuisong Li 	u8 die_id;
11947f7a255SHuisong Li 	u8 port_id;
12047f7a255SHuisong Li };
12147f7a255SHuisong Li 
12247f7a255SHuisong Li #define HCCS_PORT_RESET         1
12347f7a255SHuisong Li #define HCCS_PORT_SETUP         2
12447f7a255SHuisong Li #define HCCS_PORT_CONFIG        3
12547f7a255SHuisong Li #define HCCS_PORT_READY         4
12647f7a255SHuisong Li struct hccs_link_status {
12747f7a255SHuisong Li 	u8 lane_mask; /* indicate which lanes are used. */
12847f7a255SHuisong Li 	u8 link_fsm : 3; /* link fsm, 1: reset 2: setup 3: config 4: link-up */
12947f7a255SHuisong Li 	u8 lane_num : 5; /* current lane number */
13047f7a255SHuisong Li };
13147f7a255SHuisong Li 
132886bdf9cSHuisong Li struct hccs_req_head {
133886bdf9cSHuisong Li 	u8 module_code; /* set to 0x32 for serdes */
134886bdf9cSHuisong Li 	u8 start_id;
135886bdf9cSHuisong Li 	u8 rsv[2];
136886bdf9cSHuisong Li };
137886bdf9cSHuisong Li 
138886bdf9cSHuisong Li struct hccs_rsp_head {
139886bdf9cSHuisong Li 	u8 data_len;
140886bdf9cSHuisong Li 	u8 next_id;
141886bdf9cSHuisong Li 	u8 rsv[2];
142886bdf9cSHuisong Li };
143886bdf9cSHuisong Li 
144886bdf9cSHuisong Li struct hccs_fw_inner_head {
145886bdf9cSHuisong Li 	u8 retStatus; /* 0: success, other: failure */
146886bdf9cSHuisong Li 	u8 rsv[7];
147886bdf9cSHuisong Li };
148886bdf9cSHuisong Li 
149886bdf9cSHuisong Li #define HCCS_PCC_SHARE_MEM_BYTES	64
150886bdf9cSHuisong Li #define HCCS_FW_INNER_HEAD_BYTES	8
151886bdf9cSHuisong Li #define HCCS_RSP_HEAD_BYTES		4
152886bdf9cSHuisong Li 
153886bdf9cSHuisong Li #define HCCS_MAX_RSP_DATA_BYTES		(HCCS_PCC_SHARE_MEM_BYTES - \
154886bdf9cSHuisong Li 					 HCCS_FW_INNER_HEAD_BYTES - \
155886bdf9cSHuisong Li 					 HCCS_RSP_HEAD_BYTES)
156886bdf9cSHuisong Li #define HCCS_MAX_RSP_DATA_SIZE_MAX	(HCCS_MAX_RSP_DATA_BYTES / 4)
157886bdf9cSHuisong Li 
158886bdf9cSHuisong Li /*
159886bdf9cSHuisong Li  * Note: Actual available size of data field also depands on the PCC header
160886bdf9cSHuisong Li  * bytes of the specific type. Driver needs to copy the response data in the
161886bdf9cSHuisong Li  * communication space based on the real length.
162886bdf9cSHuisong Li  */
163886bdf9cSHuisong Li struct hccs_rsp_desc {
164886bdf9cSHuisong Li 	struct hccs_fw_inner_head fw_inner_head; /* 8 Bytes */
165886bdf9cSHuisong Li 	struct hccs_rsp_head rsp_head; /* 4 Bytes */
166886bdf9cSHuisong Li 	u32 data[HCCS_MAX_RSP_DATA_SIZE_MAX];
167886bdf9cSHuisong Li };
168886bdf9cSHuisong Li 
169886bdf9cSHuisong Li #define HCCS_REQ_HEAD_BYTES		4
170886bdf9cSHuisong Li #define HCCS_MAX_REQ_DATA_BYTES		(HCCS_PCC_SHARE_MEM_BYTES - \
171886bdf9cSHuisong Li 					 HCCS_REQ_HEAD_BYTES)
172886bdf9cSHuisong Li #define HCCS_MAX_REQ_DATA_SIZE_MAX	(HCCS_MAX_REQ_DATA_BYTES / 4)
173886bdf9cSHuisong Li 
174886bdf9cSHuisong Li /*
175886bdf9cSHuisong Li  * Note: Actual available size of data field also depands on the PCC header
176886bdf9cSHuisong Li  * bytes of the specific type. Driver needs to copy the request data to the
177886bdf9cSHuisong Li  * communication space based on the real length.
178886bdf9cSHuisong Li  */
179886bdf9cSHuisong Li struct hccs_req_desc {
180886bdf9cSHuisong Li 	struct hccs_req_head req_head; /* 4 Bytes */
181886bdf9cSHuisong Li 	u32 data[HCCS_MAX_REQ_DATA_SIZE_MAX];
182886bdf9cSHuisong Li };
183886bdf9cSHuisong Li 
184886bdf9cSHuisong Li struct hccs_desc {
185886bdf9cSHuisong Li 	union {
186886bdf9cSHuisong Li 		struct hccs_req_desc req;
187886bdf9cSHuisong Li 		struct hccs_rsp_desc rsp;
188886bdf9cSHuisong Li 	};
189886bdf9cSHuisong Li };
190886bdf9cSHuisong Li 
191886bdf9cSHuisong Li #endif /* __KUNPENG_HCCS_H__ */
192