xref: /openbmc/linux/drivers/misc/cxl/hcalls.c (revision e7a801ad154593e9fed2e0de6820eb266db6766b)
1444c4ba4SChristophe Lombard /*
2444c4ba4SChristophe Lombard  * Copyright 2015 IBM Corp.
3444c4ba4SChristophe Lombard  *
4444c4ba4SChristophe Lombard  * This program is free software; you can redistribute it and/or
5444c4ba4SChristophe Lombard  * modify it under the terms of the GNU General Public License
6444c4ba4SChristophe Lombard  * as published by the Free Software Foundation; either version
7444c4ba4SChristophe Lombard  * 2 of the License, or (at your option) any later version.
8444c4ba4SChristophe Lombard  */
9444c4ba4SChristophe Lombard 
10444c4ba4SChristophe Lombard 
11444c4ba4SChristophe Lombard #include <linux/compiler.h>
12444c4ba4SChristophe Lombard #include <linux/types.h>
13444c4ba4SChristophe Lombard #include <linux/delay.h>
14444c4ba4SChristophe Lombard #include <asm/byteorder.h>
15444c4ba4SChristophe Lombard #include "hcalls.h"
16*e7a801adSChristophe Lombard #include "trace.h"
17444c4ba4SChristophe Lombard 
18444c4ba4SChristophe Lombard #define CXL_HCALL_TIMEOUT 60000
19444c4ba4SChristophe Lombard #define CXL_HCALL_TIMEOUT_DOWNLOAD 120000
20444c4ba4SChristophe Lombard 
21444c4ba4SChristophe Lombard #define H_ATTACH_CA_PROCESS    0x344
22444c4ba4SChristophe Lombard #define H_CONTROL_CA_FUNCTION  0x348
23444c4ba4SChristophe Lombard #define H_DETACH_CA_PROCESS    0x34C
24444c4ba4SChristophe Lombard #define H_COLLECT_CA_INT_INFO  0x350
25444c4ba4SChristophe Lombard #define H_CONTROL_CA_FAULTS    0x354
26444c4ba4SChristophe Lombard #define H_DOWNLOAD_CA_FUNCTION 0x35C
27444c4ba4SChristophe Lombard #define H_DOWNLOAD_CA_FACILITY 0x364
28444c4ba4SChristophe Lombard #define H_CONTROL_CA_FACILITY  0x368
29444c4ba4SChristophe Lombard 
30444c4ba4SChristophe Lombard #define H_CONTROL_CA_FUNCTION_RESET                   1 /* perform a reset */
31444c4ba4SChristophe Lombard #define H_CONTROL_CA_FUNCTION_SUSPEND_PROCESS         2 /* suspend a process from being executed */
32444c4ba4SChristophe Lombard #define H_CONTROL_CA_FUNCTION_RESUME_PROCESS          3 /* resume a process to be executed */
33444c4ba4SChristophe Lombard #define H_CONTROL_CA_FUNCTION_READ_ERR_STATE          4 /* read the error state */
34444c4ba4SChristophe Lombard #define H_CONTROL_CA_FUNCTION_GET_AFU_ERR             5 /* collect the AFU error buffer */
35444c4ba4SChristophe Lombard #define H_CONTROL_CA_FUNCTION_GET_CONFIG              6 /* collect configuration record */
36444c4ba4SChristophe Lombard #define H_CONTROL_CA_FUNCTION_GET_DOWNLOAD_STATE      7 /* query to return download status */
37444c4ba4SChristophe Lombard #define H_CONTROL_CA_FUNCTION_TERMINATE_PROCESS       8 /* terminate the process before completion */
38444c4ba4SChristophe Lombard #define H_CONTROL_CA_FUNCTION_COLLECT_VPD             9 /* collect VPD */
39444c4ba4SChristophe Lombard #define H_CONTROL_CA_FUNCTION_GET_FUNCTION_ERR_INT   11 /* read the function-wide error data based on an interrupt */
40444c4ba4SChristophe Lombard #define H_CONTROL_CA_FUNCTION_ACK_FUNCTION_ERR_INT   12 /* acknowledge function-wide error data based on an interrupt */
41444c4ba4SChristophe Lombard #define H_CONTROL_CA_FUNCTION_GET_ERROR_LOG          13 /* retrieve the Platform Log ID (PLID) of an error log */
42444c4ba4SChristophe Lombard 
43444c4ba4SChristophe Lombard #define H_CONTROL_CA_FAULTS_RESPOND_PSL         1
44444c4ba4SChristophe Lombard #define H_CONTROL_CA_FAULTS_RESPOND_AFU         2
45444c4ba4SChristophe Lombard 
46444c4ba4SChristophe Lombard #define H_CONTROL_CA_FACILITY_RESET             1 /* perform a reset */
47444c4ba4SChristophe Lombard #define H_CONTROL_CA_FACILITY_COLLECT_VPD       2 /* collect VPD */
48444c4ba4SChristophe Lombard 
49444c4ba4SChristophe Lombard #define H_DOWNLOAD_CA_FACILITY_DOWNLOAD         1 /* download adapter image */
50444c4ba4SChristophe Lombard #define H_DOWNLOAD_CA_FACILITY_VALIDATE         2 /* validate adapter image */
51444c4ba4SChristophe Lombard 
52444c4ba4SChristophe Lombard 
53444c4ba4SChristophe Lombard #define _CXL_LOOP_HCALL(call, rc, retbuf, fn, ...)			\
54444c4ba4SChristophe Lombard 	{								\
55444c4ba4SChristophe Lombard 		unsigned int delay, total_delay = 0;			\
56444c4ba4SChristophe Lombard 		u64 token = 0;						\
57444c4ba4SChristophe Lombard 									\
58444c4ba4SChristophe Lombard 		memset(retbuf, 0, sizeof(retbuf));			\
59444c4ba4SChristophe Lombard 		while (1) {						\
60444c4ba4SChristophe Lombard 			rc = call(fn, retbuf, __VA_ARGS__, token);	\
61444c4ba4SChristophe Lombard 			token = retbuf[0];				\
62444c4ba4SChristophe Lombard 			if (rc != H_BUSY && !H_IS_LONG_BUSY(rc))	\
63444c4ba4SChristophe Lombard 				break;					\
64444c4ba4SChristophe Lombard 									\
65444c4ba4SChristophe Lombard 			if (rc == H_BUSY)				\
66444c4ba4SChristophe Lombard 				delay = 10;				\
67444c4ba4SChristophe Lombard 			else						\
68444c4ba4SChristophe Lombard 				delay = get_longbusy_msecs(rc);		\
69444c4ba4SChristophe Lombard 									\
70444c4ba4SChristophe Lombard 			total_delay += delay;				\
71444c4ba4SChristophe Lombard 			if (total_delay > CXL_HCALL_TIMEOUT) {		\
72444c4ba4SChristophe Lombard 				WARN(1, "Warning: Giving up waiting for CXL hcall " \
73444c4ba4SChristophe Lombard 					"%#x after %u msec\n", fn, total_delay); \
74444c4ba4SChristophe Lombard 				rc = H_BUSY;				\
75444c4ba4SChristophe Lombard 				break;					\
76444c4ba4SChristophe Lombard 			}						\
77444c4ba4SChristophe Lombard 			msleep(delay);					\
78444c4ba4SChristophe Lombard 		}							\
79444c4ba4SChristophe Lombard 	}
80444c4ba4SChristophe Lombard #define CXL_H_WAIT_UNTIL_DONE(...)  _CXL_LOOP_HCALL(plpar_hcall, __VA_ARGS__)
81444c4ba4SChristophe Lombard #define CXL_H9_WAIT_UNTIL_DONE(...) _CXL_LOOP_HCALL(plpar_hcall9, __VA_ARGS__)
82444c4ba4SChristophe Lombard 
83444c4ba4SChristophe Lombard #define _PRINT_MSG(rc, format, ...)					\
84444c4ba4SChristophe Lombard 	{								\
85444c4ba4SChristophe Lombard 		if ((rc != H_SUCCESS) && (rc != H_CONTINUE))		\
86444c4ba4SChristophe Lombard 			pr_err(format, __VA_ARGS__);			\
87444c4ba4SChristophe Lombard 		else							\
88444c4ba4SChristophe Lombard 			pr_devel(format, __VA_ARGS__);			\
89444c4ba4SChristophe Lombard 	}								\
90444c4ba4SChristophe Lombard 
91444c4ba4SChristophe Lombard 
92444c4ba4SChristophe Lombard static char *afu_op_names[] = {
93444c4ba4SChristophe Lombard 	"UNKNOWN_OP",		/* 0 undefined */
94444c4ba4SChristophe Lombard 	"RESET",		/* 1 */
95444c4ba4SChristophe Lombard 	"SUSPEND_PROCESS",	/* 2 */
96444c4ba4SChristophe Lombard 	"RESUME_PROCESS",	/* 3 */
97444c4ba4SChristophe Lombard 	"READ_ERR_STATE",	/* 4 */
98444c4ba4SChristophe Lombard 	"GET_AFU_ERR",		/* 5 */
99444c4ba4SChristophe Lombard 	"GET_CONFIG",		/* 6 */
100444c4ba4SChristophe Lombard 	"GET_DOWNLOAD_STATE",	/* 7 */
101444c4ba4SChristophe Lombard 	"TERMINATE_PROCESS",	/* 8 */
102444c4ba4SChristophe Lombard 	"COLLECT_VPD",		/* 9 */
103444c4ba4SChristophe Lombard 	"UNKNOWN_OP",		/* 10 undefined */
104444c4ba4SChristophe Lombard 	"GET_FUNCTION_ERR_INT",	/* 11 */
105444c4ba4SChristophe Lombard 	"ACK_FUNCTION_ERR_INT",	/* 12 */
106444c4ba4SChristophe Lombard 	"GET_ERROR_LOG",	/* 13 */
107444c4ba4SChristophe Lombard };
108444c4ba4SChristophe Lombard 
109444c4ba4SChristophe Lombard static char *control_adapter_op_names[] = {
110444c4ba4SChristophe Lombard 	"UNKNOWN_OP",		/* 0 undefined */
111444c4ba4SChristophe Lombard 	"RESET",		/* 1 */
112444c4ba4SChristophe Lombard 	"COLLECT_VPD",		/* 2 */
113444c4ba4SChristophe Lombard };
114444c4ba4SChristophe Lombard 
115444c4ba4SChristophe Lombard static char *download_op_names[] = {
116444c4ba4SChristophe Lombard 	"UNKNOWN_OP",		/* 0 undefined */
117444c4ba4SChristophe Lombard 	"DOWNLOAD",		/* 1 */
118444c4ba4SChristophe Lombard 	"VALIDATE",		/* 2 */
119444c4ba4SChristophe Lombard };
120444c4ba4SChristophe Lombard 
121444c4ba4SChristophe Lombard static char *op_str(unsigned int op, char *name_array[], int array_len)
122444c4ba4SChristophe Lombard {
123444c4ba4SChristophe Lombard 	if (op >= array_len)
124444c4ba4SChristophe Lombard 		return "UNKNOWN_OP";
125444c4ba4SChristophe Lombard 	return name_array[op];
126444c4ba4SChristophe Lombard }
127444c4ba4SChristophe Lombard 
128444c4ba4SChristophe Lombard #define OP_STR(op, name_array)      op_str(op, name_array, ARRAY_SIZE(name_array))
129444c4ba4SChristophe Lombard 
130444c4ba4SChristophe Lombard #define OP_STR_AFU(op)              OP_STR(op, afu_op_names)
131444c4ba4SChristophe Lombard #define OP_STR_CONTROL_ADAPTER(op)  OP_STR(op, control_adapter_op_names)
132444c4ba4SChristophe Lombard #define OP_STR_DOWNLOAD_ADAPTER(op) OP_STR(op, download_op_names)
133444c4ba4SChristophe Lombard 
134444c4ba4SChristophe Lombard 
135444c4ba4SChristophe Lombard long cxl_h_attach_process(u64 unit_address,
136444c4ba4SChristophe Lombard 			struct cxl_process_element_hcall *element,
137444c4ba4SChristophe Lombard 			u64 *process_token, u64 *mmio_addr, u64 *mmio_size)
138444c4ba4SChristophe Lombard {
139444c4ba4SChristophe Lombard 	unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
140444c4ba4SChristophe Lombard 	long rc;
141444c4ba4SChristophe Lombard 
142444c4ba4SChristophe Lombard 	CXL_H_WAIT_UNTIL_DONE(rc, retbuf, H_ATTACH_CA_PROCESS, unit_address, virt_to_phys(element));
143444c4ba4SChristophe Lombard 	_PRINT_MSG(rc, "cxl_h_attach_process(%#.16llx, %#.16lx): %li\n",
144444c4ba4SChristophe Lombard 		unit_address, virt_to_phys(element), rc);
145*e7a801adSChristophe Lombard 	trace_cxl_hcall_attach(unit_address, virt_to_phys(element), retbuf[0], retbuf[1], retbuf[2], rc);
146444c4ba4SChristophe Lombard 
147444c4ba4SChristophe Lombard 	pr_devel("token: 0x%.8lx mmio_addr: 0x%lx mmio_size: 0x%lx\nProcess Element Structure:\n",
148444c4ba4SChristophe Lombard 		retbuf[0], retbuf[1], retbuf[2]);
149444c4ba4SChristophe Lombard 	cxl_dump_debug_buffer(element, sizeof(*element));
150444c4ba4SChristophe Lombard 
151444c4ba4SChristophe Lombard 	switch (rc) {
152444c4ba4SChristophe Lombard 	case H_SUCCESS:       /* The process info is attached to the coherent platform function */
153444c4ba4SChristophe Lombard 		*process_token = retbuf[0];
154444c4ba4SChristophe Lombard 		if (mmio_addr)
155444c4ba4SChristophe Lombard 			*mmio_addr = retbuf[1];
156444c4ba4SChristophe Lombard 		if (mmio_size)
157444c4ba4SChristophe Lombard 			*mmio_size = retbuf[2];
158444c4ba4SChristophe Lombard 		return 0;
159444c4ba4SChristophe Lombard 	case H_PARAMETER:     /* An incorrect parameter was supplied. */
160444c4ba4SChristophe Lombard 	case H_FUNCTION:      /* The function is not supported. */
161444c4ba4SChristophe Lombard 		return -EINVAL;
162444c4ba4SChristophe Lombard 	case H_AUTHORITY:     /* The partition does not have authority to perform this hcall */
163444c4ba4SChristophe Lombard 	case H_RESOURCE:      /* The coherent platform function does not have enough additional resource to attach the process */
164444c4ba4SChristophe Lombard 	case H_HARDWARE:      /* A hardware event prevented the attach operation */
165444c4ba4SChristophe Lombard 	case H_STATE:         /* The coherent platform function is not in a valid state */
166444c4ba4SChristophe Lombard 	case H_BUSY:
167444c4ba4SChristophe Lombard 		return -EBUSY;
168444c4ba4SChristophe Lombard 	default:
169444c4ba4SChristophe Lombard 		WARN(1, "Unexpected return code: %lx", rc);
170444c4ba4SChristophe Lombard 		return -EINVAL;
171444c4ba4SChristophe Lombard 	}
172444c4ba4SChristophe Lombard }
173444c4ba4SChristophe Lombard 
174444c4ba4SChristophe Lombard /**
175444c4ba4SChristophe Lombard  * cxl_h_detach_process - Detach a process element from a coherent
176444c4ba4SChristophe Lombard  *                        platform function.
177444c4ba4SChristophe Lombard  */
178444c4ba4SChristophe Lombard long cxl_h_detach_process(u64 unit_address, u64 process_token)
179444c4ba4SChristophe Lombard {
180444c4ba4SChristophe Lombard 	unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
181444c4ba4SChristophe Lombard 	long rc;
182444c4ba4SChristophe Lombard 
183444c4ba4SChristophe Lombard 	CXL_H_WAIT_UNTIL_DONE(rc, retbuf, H_DETACH_CA_PROCESS, unit_address, process_token);
184444c4ba4SChristophe Lombard 	_PRINT_MSG(rc, "cxl_h_detach_process(%#.16llx, 0x%.8llx): %li\n", unit_address, process_token, rc);
185*e7a801adSChristophe Lombard 	trace_cxl_hcall_detach(unit_address, process_token, rc);
186444c4ba4SChristophe Lombard 
187444c4ba4SChristophe Lombard 	switch (rc) {
188444c4ba4SChristophe Lombard 	case H_SUCCESS:       /* The process was detached from the coherent platform function */
189444c4ba4SChristophe Lombard 		return 0;
190444c4ba4SChristophe Lombard 	case H_PARAMETER:     /* An incorrect parameter was supplied. */
191444c4ba4SChristophe Lombard 		return -EINVAL;
192444c4ba4SChristophe Lombard 	case H_AUTHORITY:     /* The partition does not have authority to perform this hcall */
193444c4ba4SChristophe Lombard 	case H_RESOURCE:      /* The function has page table mappings for MMIO */
194444c4ba4SChristophe Lombard 	case H_HARDWARE:      /* A hardware event prevented the detach operation */
195444c4ba4SChristophe Lombard 	case H_STATE:         /* The coherent platform function is not in a valid state */
196444c4ba4SChristophe Lombard 	case H_BUSY:
197444c4ba4SChristophe Lombard 		return -EBUSY;
198444c4ba4SChristophe Lombard 	default:
199444c4ba4SChristophe Lombard 		WARN(1, "Unexpected return code: %lx", rc);
200444c4ba4SChristophe Lombard 		return -EINVAL;
201444c4ba4SChristophe Lombard 	}
202444c4ba4SChristophe Lombard }
203444c4ba4SChristophe Lombard 
204444c4ba4SChristophe Lombard /**
205444c4ba4SChristophe Lombard  * cxl_h_control_function - This H_CONTROL_CA_FUNCTION hypervisor call allows
206444c4ba4SChristophe Lombard  *                          the partition to manipulate or query
207444c4ba4SChristophe Lombard  *                          certain coherent platform function behaviors.
208444c4ba4SChristophe Lombard  */
209444c4ba4SChristophe Lombard static long cxl_h_control_function(u64 unit_address, u64 op,
210444c4ba4SChristophe Lombard 				   u64 p1, u64 p2, u64 p3, u64 p4, u64 *out)
211444c4ba4SChristophe Lombard {
212444c4ba4SChristophe Lombard 	unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
213444c4ba4SChristophe Lombard 	long rc;
214444c4ba4SChristophe Lombard 
215444c4ba4SChristophe Lombard 	CXL_H9_WAIT_UNTIL_DONE(rc, retbuf, H_CONTROL_CA_FUNCTION, unit_address, op, p1, p2, p3, p4);
216444c4ba4SChristophe Lombard 	_PRINT_MSG(rc, "cxl_h_control_function(%#.16llx, %s(%#llx, %#llx, %#llx, %#llx, R4: %#lx)): %li\n",
217444c4ba4SChristophe Lombard 		unit_address, OP_STR_AFU(op), p1, p2, p3, p4, retbuf[0], rc);
218*e7a801adSChristophe Lombard 	trace_cxl_hcall_control_function(unit_address, OP_STR_AFU(op), p1, p2, p3, p4, retbuf[0], rc);
219444c4ba4SChristophe Lombard 
220444c4ba4SChristophe Lombard 	switch (rc) {
221444c4ba4SChristophe Lombard 	case H_SUCCESS:       /* The operation is completed for the coherent platform function */
222444c4ba4SChristophe Lombard 		if ((op == H_CONTROL_CA_FUNCTION_GET_FUNCTION_ERR_INT ||
223444c4ba4SChristophe Lombard 		     op == H_CONTROL_CA_FUNCTION_READ_ERR_STATE ||
224444c4ba4SChristophe Lombard 		     op == H_CONTROL_CA_FUNCTION_COLLECT_VPD))
225444c4ba4SChristophe Lombard 			*out = retbuf[0];
226444c4ba4SChristophe Lombard 		return 0;
227444c4ba4SChristophe Lombard 	case H_PARAMETER:     /* An incorrect parameter was supplied. */
228444c4ba4SChristophe Lombard 	case H_FUNCTION:      /* The function is not supported. */
229444c4ba4SChristophe Lombard 	case H_NOT_FOUND:     /* The operation supplied was not valid */
230444c4ba4SChristophe Lombard 	case H_NOT_AVAILABLE: /* The operation cannot be performed because the AFU has not been downloaded */
231444c4ba4SChristophe Lombard 	case H_SG_LIST:       /* An block list entry was invalid */
232444c4ba4SChristophe Lombard 		return -EINVAL;
233444c4ba4SChristophe Lombard 	case H_AUTHORITY:     /* The partition does not have authority to perform this hcall */
234444c4ba4SChristophe Lombard 	case H_RESOURCE:      /* The function has page table mappings for MMIO */
235444c4ba4SChristophe Lombard 	case H_HARDWARE:      /* A hardware event prevented the attach operation */
236444c4ba4SChristophe Lombard 	case H_STATE:         /* The coherent platform function is not in a valid state */
237444c4ba4SChristophe Lombard 	case H_BUSY:
238444c4ba4SChristophe Lombard 		return -EBUSY;
239444c4ba4SChristophe Lombard 	default:
240444c4ba4SChristophe Lombard 		WARN(1, "Unexpected return code: %lx", rc);
241444c4ba4SChristophe Lombard 		return -EINVAL;
242444c4ba4SChristophe Lombard 	}
243444c4ba4SChristophe Lombard }
244444c4ba4SChristophe Lombard 
245444c4ba4SChristophe Lombard /**
246444c4ba4SChristophe Lombard  * cxl_h_reset_afu - Perform a reset to the coherent platform function.
247444c4ba4SChristophe Lombard  */
248444c4ba4SChristophe Lombard long cxl_h_reset_afu(u64 unit_address)
249444c4ba4SChristophe Lombard {
250444c4ba4SChristophe Lombard 	return cxl_h_control_function(unit_address,
251444c4ba4SChristophe Lombard 				H_CONTROL_CA_FUNCTION_RESET,
252444c4ba4SChristophe Lombard 				0, 0, 0, 0,
253444c4ba4SChristophe Lombard 				NULL);
254444c4ba4SChristophe Lombard }
255444c4ba4SChristophe Lombard 
256444c4ba4SChristophe Lombard /**
257444c4ba4SChristophe Lombard  * cxl_h_suspend_process - Suspend a process from being executed
258444c4ba4SChristophe Lombard  * Parameter1 = process-token as returned from H_ATTACH_CA_PROCESS when
259444c4ba4SChristophe Lombard  *              process was attached.
260444c4ba4SChristophe Lombard  */
261444c4ba4SChristophe Lombard long cxl_h_suspend_process(u64 unit_address, u64 process_token)
262444c4ba4SChristophe Lombard {
263444c4ba4SChristophe Lombard 	return cxl_h_control_function(unit_address,
264444c4ba4SChristophe Lombard 				H_CONTROL_CA_FUNCTION_SUSPEND_PROCESS,
265444c4ba4SChristophe Lombard 				process_token, 0, 0, 0,
266444c4ba4SChristophe Lombard 				NULL);
267444c4ba4SChristophe Lombard }
268444c4ba4SChristophe Lombard 
269444c4ba4SChristophe Lombard /**
270444c4ba4SChristophe Lombard  * cxl_h_resume_process - Resume a process to be executed
271444c4ba4SChristophe Lombard  * Parameter1 = process-token as returned from H_ATTACH_CA_PROCESS when
272444c4ba4SChristophe Lombard  *              process was attached.
273444c4ba4SChristophe Lombard  */
274444c4ba4SChristophe Lombard long cxl_h_resume_process(u64 unit_address, u64 process_token)
275444c4ba4SChristophe Lombard {
276444c4ba4SChristophe Lombard 	return cxl_h_control_function(unit_address,
277444c4ba4SChristophe Lombard 				H_CONTROL_CA_FUNCTION_RESUME_PROCESS,
278444c4ba4SChristophe Lombard 				process_token, 0, 0, 0,
279444c4ba4SChristophe Lombard 				NULL);
280444c4ba4SChristophe Lombard }
281444c4ba4SChristophe Lombard 
282444c4ba4SChristophe Lombard /**
283444c4ba4SChristophe Lombard  * cxl_h_read_error_state - Checks the error state of the coherent
284444c4ba4SChristophe Lombard  *                          platform function.
285444c4ba4SChristophe Lombard  * R4 contains the error state
286444c4ba4SChristophe Lombard  */
287444c4ba4SChristophe Lombard long cxl_h_read_error_state(u64 unit_address, u64 *state)
288444c4ba4SChristophe Lombard {
289444c4ba4SChristophe Lombard 	return cxl_h_control_function(unit_address,
290444c4ba4SChristophe Lombard 				H_CONTROL_CA_FUNCTION_READ_ERR_STATE,
291444c4ba4SChristophe Lombard 				0, 0, 0, 0,
292444c4ba4SChristophe Lombard 				state);
293444c4ba4SChristophe Lombard }
294444c4ba4SChristophe Lombard 
295444c4ba4SChristophe Lombard /**
296444c4ba4SChristophe Lombard  * cxl_h_get_afu_err - collect the AFU error buffer
297444c4ba4SChristophe Lombard  * Parameter1 = byte offset into error buffer to retrieve, valid values
298444c4ba4SChristophe Lombard  *              are between 0 and (ibm,error-buffer-size - 1)
299444c4ba4SChristophe Lombard  * Parameter2 = 4K aligned real address of error buffer, to be filled in
300444c4ba4SChristophe Lombard  * Parameter3 = length of error buffer, valid values are 4K or less
301444c4ba4SChristophe Lombard  */
302444c4ba4SChristophe Lombard long cxl_h_get_afu_err(u64 unit_address, u64 offset,
303444c4ba4SChristophe Lombard 		u64 buf_address, u64 len)
304444c4ba4SChristophe Lombard {
305444c4ba4SChristophe Lombard 	return cxl_h_control_function(unit_address,
306444c4ba4SChristophe Lombard 				H_CONTROL_CA_FUNCTION_GET_AFU_ERR,
307444c4ba4SChristophe Lombard 				offset, buf_address, len, 0,
308444c4ba4SChristophe Lombard 				NULL);
309444c4ba4SChristophe Lombard }
310444c4ba4SChristophe Lombard 
311444c4ba4SChristophe Lombard /**
312444c4ba4SChristophe Lombard  * cxl_h_get_config - collect configuration record for the
313444c4ba4SChristophe Lombard  *                    coherent platform function
314444c4ba4SChristophe Lombard  * Parameter1 = # of configuration record to retrieve, valid values are
315444c4ba4SChristophe Lombard  *              between 0 and (ibm,#config-records - 1)
316444c4ba4SChristophe Lombard  * Parameter2 = byte offset into configuration record to retrieve,
317444c4ba4SChristophe Lombard  *              valid values are between 0 and (ibm,config-record-size - 1)
318444c4ba4SChristophe Lombard  * Parameter3 = 4K aligned real address of configuration record buffer,
319444c4ba4SChristophe Lombard  *              to be filled in
320444c4ba4SChristophe Lombard  * Parameter4 = length of configuration buffer, valid values are 4K or less
321444c4ba4SChristophe Lombard  */
322444c4ba4SChristophe Lombard long cxl_h_get_config(u64 unit_address, u64 cr_num, u64 offset,
323444c4ba4SChristophe Lombard 		u64 buf_address, u64 len)
324444c4ba4SChristophe Lombard {
325444c4ba4SChristophe Lombard 	return cxl_h_control_function(unit_address,
326444c4ba4SChristophe Lombard 				H_CONTROL_CA_FUNCTION_GET_CONFIG,
327444c4ba4SChristophe Lombard 				cr_num, offset, buf_address, len,
328444c4ba4SChristophe Lombard 				NULL);
329444c4ba4SChristophe Lombard }
330444c4ba4SChristophe Lombard 
331444c4ba4SChristophe Lombard /**
332444c4ba4SChristophe Lombard  * cxl_h_terminate_process - Terminate the process before completion
333444c4ba4SChristophe Lombard  * Parameter1 = process-token as returned from H_ATTACH_CA_PROCESS when
334444c4ba4SChristophe Lombard  *              process was attached.
335444c4ba4SChristophe Lombard  */
336444c4ba4SChristophe Lombard long cxl_h_terminate_process(u64 unit_address, u64 process_token)
337444c4ba4SChristophe Lombard {
338444c4ba4SChristophe Lombard 	return cxl_h_control_function(unit_address,
339444c4ba4SChristophe Lombard 				H_CONTROL_CA_FUNCTION_TERMINATE_PROCESS,
340444c4ba4SChristophe Lombard 				process_token, 0, 0, 0,
341444c4ba4SChristophe Lombard 				NULL);
342444c4ba4SChristophe Lombard }
343444c4ba4SChristophe Lombard 
344444c4ba4SChristophe Lombard /**
345444c4ba4SChristophe Lombard  * cxl_h_collect_vpd - Collect VPD for the coherent platform function.
346444c4ba4SChristophe Lombard  * Parameter1 = # of VPD record to retrieve, valid values are between 0
347444c4ba4SChristophe Lombard  *              and (ibm,#config-records - 1).
348444c4ba4SChristophe Lombard  * Parameter2 = 4K naturally aligned real buffer containing block
349444c4ba4SChristophe Lombard  *              list entries
350444c4ba4SChristophe Lombard  * Parameter3 = number of block list entries in the block list, valid
351444c4ba4SChristophe Lombard  *              values are between 0 and 256
352444c4ba4SChristophe Lombard  */
353444c4ba4SChristophe Lombard long cxl_h_collect_vpd(u64 unit_address, u64 record, u64 list_address,
354444c4ba4SChristophe Lombard 		       u64 num, u64 *out)
355444c4ba4SChristophe Lombard {
356444c4ba4SChristophe Lombard 	return cxl_h_control_function(unit_address,
357444c4ba4SChristophe Lombard 				H_CONTROL_CA_FUNCTION_COLLECT_VPD,
358444c4ba4SChristophe Lombard 				record, list_address, num, 0,
359444c4ba4SChristophe Lombard 				out);
360444c4ba4SChristophe Lombard }
361444c4ba4SChristophe Lombard 
362444c4ba4SChristophe Lombard /**
363444c4ba4SChristophe Lombard  * cxl_h_get_fn_error_interrupt - Read the function-wide error data based on an interrupt
364444c4ba4SChristophe Lombard  */
365444c4ba4SChristophe Lombard long cxl_h_get_fn_error_interrupt(u64 unit_address, u64 *reg)
366444c4ba4SChristophe Lombard {
367444c4ba4SChristophe Lombard 	return cxl_h_control_function(unit_address,
368444c4ba4SChristophe Lombard 				H_CONTROL_CA_FUNCTION_GET_FUNCTION_ERR_INT,
369444c4ba4SChristophe Lombard 				0, 0, 0, 0, reg);
370444c4ba4SChristophe Lombard }
371444c4ba4SChristophe Lombard 
372444c4ba4SChristophe Lombard /**
373444c4ba4SChristophe Lombard  * cxl_h_ack_fn_error_interrupt - Acknowledge function-wide error data
374444c4ba4SChristophe Lombard  *                                based on an interrupt
375444c4ba4SChristophe Lombard  * Parameter1 = value to write to the function-wide error interrupt register
376444c4ba4SChristophe Lombard  */
377444c4ba4SChristophe Lombard long cxl_h_ack_fn_error_interrupt(u64 unit_address, u64 value)
378444c4ba4SChristophe Lombard {
379444c4ba4SChristophe Lombard 	return cxl_h_control_function(unit_address,
380444c4ba4SChristophe Lombard 				H_CONTROL_CA_FUNCTION_ACK_FUNCTION_ERR_INT,
381444c4ba4SChristophe Lombard 				value, 0, 0, 0,
382444c4ba4SChristophe Lombard 				NULL);
383444c4ba4SChristophe Lombard }
384444c4ba4SChristophe Lombard 
385444c4ba4SChristophe Lombard /**
386444c4ba4SChristophe Lombard  * cxl_h_get_error_log - Retrieve the Platform Log ID (PLID) of
387444c4ba4SChristophe Lombard  *                       an error log
388444c4ba4SChristophe Lombard  */
389444c4ba4SChristophe Lombard long cxl_h_get_error_log(u64 unit_address, u64 value)
390444c4ba4SChristophe Lombard {
391444c4ba4SChristophe Lombard 	return cxl_h_control_function(unit_address,
392444c4ba4SChristophe Lombard 				H_CONTROL_CA_FUNCTION_GET_ERROR_LOG,
393444c4ba4SChristophe Lombard 				0, 0, 0, 0,
394444c4ba4SChristophe Lombard 				NULL);
395444c4ba4SChristophe Lombard }
396444c4ba4SChristophe Lombard 
397444c4ba4SChristophe Lombard /**
398444c4ba4SChristophe Lombard  * cxl_h_collect_int_info - Collect interrupt info about a coherent
399444c4ba4SChristophe Lombard  *                          platform function after an interrupt occurred.
400444c4ba4SChristophe Lombard  */
401444c4ba4SChristophe Lombard long cxl_h_collect_int_info(u64 unit_address, u64 process_token,
402444c4ba4SChristophe Lombard 			    struct cxl_irq_info *info)
403444c4ba4SChristophe Lombard {
404444c4ba4SChristophe Lombard 	long rc;
405444c4ba4SChristophe Lombard 
406444c4ba4SChristophe Lombard 	BUG_ON(sizeof(*info) != sizeof(unsigned long[PLPAR_HCALL9_BUFSIZE]));
407444c4ba4SChristophe Lombard 
408444c4ba4SChristophe Lombard 	rc = plpar_hcall9(H_COLLECT_CA_INT_INFO, (unsigned long *) info,
409444c4ba4SChristophe Lombard 			unit_address, process_token);
410444c4ba4SChristophe Lombard 	_PRINT_MSG(rc, "cxl_h_collect_int_info(%#.16llx, 0x%llx): %li\n",
411444c4ba4SChristophe Lombard 		unit_address, process_token, rc);
412*e7a801adSChristophe Lombard 	trace_cxl_hcall_collect_int_info(unit_address, process_token, rc);
413444c4ba4SChristophe Lombard 
414444c4ba4SChristophe Lombard 	switch (rc) {
415444c4ba4SChristophe Lombard 	case H_SUCCESS:     /* The interrupt info is returned in return registers. */
416444c4ba4SChristophe Lombard 		pr_devel("dsisr:%#llx, dar:%#llx, dsr:%#llx, pid:%u, tid:%u, afu_err:%#llx, errstat:%#llx\n",
417444c4ba4SChristophe Lombard 			info->dsisr, info->dar, info->dsr, info->pid,
418444c4ba4SChristophe Lombard 			info->tid, info->afu_err, info->errstat);
419444c4ba4SChristophe Lombard 		return 0;
420444c4ba4SChristophe Lombard 	case H_PARAMETER:   /* An incorrect parameter was supplied. */
421444c4ba4SChristophe Lombard 		return -EINVAL;
422444c4ba4SChristophe Lombard 	case H_AUTHORITY:   /* The partition does not have authority to perform this hcall. */
423444c4ba4SChristophe Lombard 	case H_HARDWARE:    /* A hardware event prevented the collection of the interrupt info.*/
424444c4ba4SChristophe Lombard 	case H_STATE:       /* The coherent platform function is not in a valid state to collect interrupt info. */
425444c4ba4SChristophe Lombard 		return -EBUSY;
426444c4ba4SChristophe Lombard 	default:
427444c4ba4SChristophe Lombard 		WARN(1, "Unexpected return code: %lx", rc);
428444c4ba4SChristophe Lombard 		return -EINVAL;
429444c4ba4SChristophe Lombard 	}
430444c4ba4SChristophe Lombard }
431444c4ba4SChristophe Lombard 
432444c4ba4SChristophe Lombard /**
433444c4ba4SChristophe Lombard  * cxl_h_control_faults - Control the operation of a coherent platform
434444c4ba4SChristophe Lombard  *                        function after a fault occurs.
435444c4ba4SChristophe Lombard  *
436444c4ba4SChristophe Lombard  * Parameters
437444c4ba4SChristophe Lombard  *    control-mask: value to control the faults
438444c4ba4SChristophe Lombard  *                  looks like PSL_TFC_An shifted >> 32
439444c4ba4SChristophe Lombard  *    reset-mask: mask to control reset of function faults
440444c4ba4SChristophe Lombard  *                Set reset_mask = 1 to reset PSL errors
441444c4ba4SChristophe Lombard  */
442444c4ba4SChristophe Lombard long cxl_h_control_faults(u64 unit_address, u64 process_token,
443444c4ba4SChristophe Lombard 			  u64 control_mask, u64 reset_mask)
444444c4ba4SChristophe Lombard {
445444c4ba4SChristophe Lombard 	unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
446444c4ba4SChristophe Lombard 	long rc;
447444c4ba4SChristophe Lombard 
448444c4ba4SChristophe Lombard 	memset(retbuf, 0, sizeof(retbuf));
449444c4ba4SChristophe Lombard 
450444c4ba4SChristophe Lombard 	rc = plpar_hcall(H_CONTROL_CA_FAULTS, retbuf, unit_address,
451444c4ba4SChristophe Lombard 			H_CONTROL_CA_FAULTS_RESPOND_PSL, process_token,
452444c4ba4SChristophe Lombard 			control_mask, reset_mask);
453444c4ba4SChristophe Lombard 	_PRINT_MSG(rc, "cxl_h_control_faults(%#.16llx, 0x%llx, %#llx, %#llx): %li (%#lx)\n",
454444c4ba4SChristophe Lombard 		unit_address, process_token, control_mask, reset_mask,
455444c4ba4SChristophe Lombard 		rc, retbuf[0]);
456*e7a801adSChristophe Lombard 	trace_cxl_hcall_control_faults(unit_address, process_token,
457*e7a801adSChristophe Lombard 				control_mask, reset_mask, retbuf[0], rc);
458444c4ba4SChristophe Lombard 
459444c4ba4SChristophe Lombard 	switch (rc) {
460444c4ba4SChristophe Lombard 	case H_SUCCESS:    /* Faults were successfully controlled for the function. */
461444c4ba4SChristophe Lombard 		return 0;
462444c4ba4SChristophe Lombard 	case H_PARAMETER:  /* An incorrect parameter was supplied. */
463444c4ba4SChristophe Lombard 		return -EINVAL;
464444c4ba4SChristophe Lombard 	case H_HARDWARE:   /* A hardware event prevented the control of faults. */
465444c4ba4SChristophe Lombard 	case H_STATE:      /* The function was in an invalid state. */
466444c4ba4SChristophe Lombard 	case H_AUTHORITY:  /* The partition does not have authority to perform this hcall; the coherent platform facilities may need to be licensed. */
467444c4ba4SChristophe Lombard 		return -EBUSY;
468444c4ba4SChristophe Lombard 	case H_FUNCTION:   /* The function is not supported */
469444c4ba4SChristophe Lombard 	case H_NOT_FOUND:  /* The operation supplied was not valid */
470444c4ba4SChristophe Lombard 		return -EINVAL;
471444c4ba4SChristophe Lombard 	default:
472444c4ba4SChristophe Lombard 		WARN(1, "Unexpected return code: %lx", rc);
473444c4ba4SChristophe Lombard 		return -EINVAL;
474444c4ba4SChristophe Lombard 	}
475444c4ba4SChristophe Lombard }
476444c4ba4SChristophe Lombard 
477444c4ba4SChristophe Lombard /**
478444c4ba4SChristophe Lombard  * cxl_h_control_facility - This H_CONTROL_CA_FACILITY hypervisor call
479444c4ba4SChristophe Lombard  *                          allows the partition to manipulate or query
480444c4ba4SChristophe Lombard  *                          certain coherent platform facility behaviors.
481444c4ba4SChristophe Lombard  */
482444c4ba4SChristophe Lombard static long cxl_h_control_facility(u64 unit_address, u64 op,
483444c4ba4SChristophe Lombard 				   u64 p1, u64 p2, u64 p3, u64 p4, u64 *out)
484444c4ba4SChristophe Lombard {
485444c4ba4SChristophe Lombard 	unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
486444c4ba4SChristophe Lombard 	long rc;
487444c4ba4SChristophe Lombard 
488444c4ba4SChristophe Lombard 	CXL_H9_WAIT_UNTIL_DONE(rc, retbuf, H_CONTROL_CA_FACILITY, unit_address, op, p1, p2, p3, p4);
489444c4ba4SChristophe Lombard 	_PRINT_MSG(rc, "cxl_h_control_facility(%#.16llx, %s(%#llx, %#llx, %#llx, %#llx, R4: %#lx)): %li\n",
490444c4ba4SChristophe Lombard 		unit_address, OP_STR_CONTROL_ADAPTER(op), p1, p2, p3, p4, retbuf[0], rc);
491*e7a801adSChristophe Lombard 	trace_cxl_hcall_control_facility(unit_address, OP_STR_CONTROL_ADAPTER(op), p1, p2, p3, p4, retbuf[0], rc);
492444c4ba4SChristophe Lombard 
493444c4ba4SChristophe Lombard 	switch (rc) {
494444c4ba4SChristophe Lombard 	case H_SUCCESS:       /* The operation is completed for the coherent platform facility */
495444c4ba4SChristophe Lombard 		if (op == H_CONTROL_CA_FACILITY_COLLECT_VPD)
496444c4ba4SChristophe Lombard 			*out = retbuf[0];
497444c4ba4SChristophe Lombard 		return 0;
498444c4ba4SChristophe Lombard 	case H_PARAMETER:     /* An incorrect parameter was supplied. */
499444c4ba4SChristophe Lombard 	case H_FUNCTION:      /* The function is not supported. */
500444c4ba4SChristophe Lombard 	case H_NOT_FOUND:     /* The operation supplied was not valid */
501444c4ba4SChristophe Lombard 	case H_NOT_AVAILABLE: /* The operation cannot be performed because the AFU has not been downloaded */
502444c4ba4SChristophe Lombard 	case H_SG_LIST:       /* An block list entry was invalid */
503444c4ba4SChristophe Lombard 		return -EINVAL;
504444c4ba4SChristophe Lombard 	case H_AUTHORITY:     /* The partition does not have authority to perform this hcall */
505444c4ba4SChristophe Lombard 	case H_RESOURCE:      /* The function has page table mappings for MMIO */
506444c4ba4SChristophe Lombard 	case H_HARDWARE:      /* A hardware event prevented the attach operation */
507444c4ba4SChristophe Lombard 	case H_STATE:         /* The coherent platform facility is not in a valid state */
508444c4ba4SChristophe Lombard 	case H_BUSY:
509444c4ba4SChristophe Lombard 		return -EBUSY;
510444c4ba4SChristophe Lombard 	default:
511444c4ba4SChristophe Lombard 		WARN(1, "Unexpected return code: %lx", rc);
512444c4ba4SChristophe Lombard 		return -EINVAL;
513444c4ba4SChristophe Lombard 	}
514444c4ba4SChristophe Lombard }
515444c4ba4SChristophe Lombard 
516444c4ba4SChristophe Lombard /**
517444c4ba4SChristophe Lombard  * cxl_h_reset_adapter - Perform a reset to the coherent platform facility.
518444c4ba4SChristophe Lombard  */
519444c4ba4SChristophe Lombard long cxl_h_reset_adapter(u64 unit_address)
520444c4ba4SChristophe Lombard {
521444c4ba4SChristophe Lombard 	return cxl_h_control_facility(unit_address,
522444c4ba4SChristophe Lombard 				H_CONTROL_CA_FACILITY_RESET,
523444c4ba4SChristophe Lombard 				0, 0, 0, 0,
524444c4ba4SChristophe Lombard 				NULL);
525444c4ba4SChristophe Lombard }
526444c4ba4SChristophe Lombard 
527444c4ba4SChristophe Lombard /**
528444c4ba4SChristophe Lombard  * cxl_h_collect_vpd - Collect VPD for the coherent platform function.
529444c4ba4SChristophe Lombard  * Parameter1 = 4K naturally aligned real buffer containing block
530444c4ba4SChristophe Lombard  *              list entries
531444c4ba4SChristophe Lombard  * Parameter2 = number of block list entries in the block list, valid
532444c4ba4SChristophe Lombard  *              values are between 0 and 256
533444c4ba4SChristophe Lombard  */
534444c4ba4SChristophe Lombard long cxl_h_collect_vpd_adapter(u64 unit_address, u64 list_address,
535444c4ba4SChristophe Lombard 			       u64 num, u64 *out)
536444c4ba4SChristophe Lombard {
537444c4ba4SChristophe Lombard 	return cxl_h_control_facility(unit_address,
538444c4ba4SChristophe Lombard 				H_CONTROL_CA_FACILITY_COLLECT_VPD,
539444c4ba4SChristophe Lombard 				list_address, num, 0, 0,
540444c4ba4SChristophe Lombard 				out);
541444c4ba4SChristophe Lombard }
542444c4ba4SChristophe Lombard 
543444c4ba4SChristophe Lombard /**
544444c4ba4SChristophe Lombard  * cxl_h_download_facility - This H_DOWNLOAD_CA_FACILITY
545444c4ba4SChristophe Lombard  *                    hypervisor call provide platform support for
546444c4ba4SChristophe Lombard  *                    downloading a base adapter image to the coherent
547444c4ba4SChristophe Lombard  *                    platform facility, and for validating the entire
548444c4ba4SChristophe Lombard  *                    image after the download.
549444c4ba4SChristophe Lombard  * Parameters
550444c4ba4SChristophe Lombard  *    op: operation to perform to the coherent platform function
551444c4ba4SChristophe Lombard  *      Download: operation = 1, the base image in the coherent platform
552444c4ba4SChristophe Lombard  *                               facility is first erased, and then
553444c4ba4SChristophe Lombard  *                               programmed using the image supplied
554444c4ba4SChristophe Lombard  *                               in the scatter/gather list.
555444c4ba4SChristophe Lombard  *      Validate: operation = 2, the base image in the coherent platform
556444c4ba4SChristophe Lombard  *                               facility is compared with the image
557444c4ba4SChristophe Lombard  *                               supplied in the scatter/gather list.
558444c4ba4SChristophe Lombard  *    list_address: 4K naturally aligned real buffer containing
559444c4ba4SChristophe Lombard  *                  scatter/gather list entries.
560444c4ba4SChristophe Lombard  *    num: number of block list entries in the scatter/gather list.
561444c4ba4SChristophe Lombard  */
562444c4ba4SChristophe Lombard static long cxl_h_download_facility(u64 unit_address, u64 op,
563444c4ba4SChristophe Lombard 				    u64 list_address, u64 num,
564444c4ba4SChristophe Lombard 				    u64 *out)
565444c4ba4SChristophe Lombard {
566444c4ba4SChristophe Lombard 	unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
567444c4ba4SChristophe Lombard 	unsigned int delay, total_delay = 0;
568444c4ba4SChristophe Lombard 	u64 token = 0;
569444c4ba4SChristophe Lombard 	long rc;
570444c4ba4SChristophe Lombard 
571444c4ba4SChristophe Lombard 	if (*out != 0)
572444c4ba4SChristophe Lombard 		token = *out;
573444c4ba4SChristophe Lombard 
574444c4ba4SChristophe Lombard 	memset(retbuf, 0, sizeof(retbuf));
575444c4ba4SChristophe Lombard 	while (1) {
576444c4ba4SChristophe Lombard 		rc = plpar_hcall(H_DOWNLOAD_CA_FACILITY, retbuf,
577444c4ba4SChristophe Lombard 				 unit_address, op, list_address, num,
578444c4ba4SChristophe Lombard 				 token);
579444c4ba4SChristophe Lombard 		token = retbuf[0];
580444c4ba4SChristophe Lombard 		if (rc != H_BUSY && !H_IS_LONG_BUSY(rc))
581444c4ba4SChristophe Lombard 			break;
582444c4ba4SChristophe Lombard 
583444c4ba4SChristophe Lombard 		if (rc != H_BUSY) {
584444c4ba4SChristophe Lombard 			delay = get_longbusy_msecs(rc);
585444c4ba4SChristophe Lombard 			total_delay += delay;
586444c4ba4SChristophe Lombard 			if (total_delay > CXL_HCALL_TIMEOUT_DOWNLOAD) {
587444c4ba4SChristophe Lombard 				WARN(1, "Warning: Giving up waiting for CXL hcall "
588444c4ba4SChristophe Lombard 					"%#x after %u msec\n",
589444c4ba4SChristophe Lombard 					H_DOWNLOAD_CA_FACILITY, total_delay);
590444c4ba4SChristophe Lombard 				rc = H_BUSY;
591444c4ba4SChristophe Lombard 				break;
592444c4ba4SChristophe Lombard 			}
593444c4ba4SChristophe Lombard 			msleep(delay);
594444c4ba4SChristophe Lombard 		}
595444c4ba4SChristophe Lombard 	}
596444c4ba4SChristophe Lombard 	_PRINT_MSG(rc, "cxl_h_download_facility(%#.16llx, %s(%#llx, %#llx), %#lx): %li\n",
597444c4ba4SChristophe Lombard 		 unit_address, OP_STR_DOWNLOAD_ADAPTER(op), list_address, num, retbuf[0], rc);
598*e7a801adSChristophe Lombard 	trace_cxl_hcall_download_facility(unit_address, OP_STR_DOWNLOAD_ADAPTER(op), list_address, num, retbuf[0], rc);
599444c4ba4SChristophe Lombard 
600444c4ba4SChristophe Lombard 	switch (rc) {
601444c4ba4SChristophe Lombard 	case H_SUCCESS:       /* The operation is completed for the coherent platform facility */
602444c4ba4SChristophe Lombard 		return 0;
603444c4ba4SChristophe Lombard 	case H_PARAMETER:     /* An incorrect parameter was supplied */
604444c4ba4SChristophe Lombard 	case H_FUNCTION:      /* The function is not supported. */
605444c4ba4SChristophe Lombard 	case H_SG_LIST:       /* An block list entry was invalid */
606444c4ba4SChristophe Lombard 	case H_BAD_DATA:      /* Image verification failed */
607444c4ba4SChristophe Lombard 		return -EINVAL;
608444c4ba4SChristophe Lombard 	case H_AUTHORITY:     /* The partition does not have authority to perform this hcall */
609444c4ba4SChristophe Lombard 	case H_RESOURCE:      /* The function has page table mappings for MMIO */
610444c4ba4SChristophe Lombard 	case H_HARDWARE:      /* A hardware event prevented the attach operation */
611444c4ba4SChristophe Lombard 	case H_STATE:         /* The coherent platform facility is not in a valid state */
612444c4ba4SChristophe Lombard 	case H_BUSY:
613444c4ba4SChristophe Lombard 		return -EBUSY;
614444c4ba4SChristophe Lombard 	case H_CONTINUE:
615444c4ba4SChristophe Lombard 		*out = retbuf[0];
616444c4ba4SChristophe Lombard 		return 1;  /* More data is needed for the complete image */
617444c4ba4SChristophe Lombard 	default:
618444c4ba4SChristophe Lombard 		WARN(1, "Unexpected return code: %lx", rc);
619444c4ba4SChristophe Lombard 		return -EINVAL;
620444c4ba4SChristophe Lombard 	}
621444c4ba4SChristophe Lombard }
622444c4ba4SChristophe Lombard 
623444c4ba4SChristophe Lombard /**
624444c4ba4SChristophe Lombard  * cxl_h_download_adapter_image - Download the base image to the coherent
625444c4ba4SChristophe Lombard  *                                platform facility.
626444c4ba4SChristophe Lombard  */
627444c4ba4SChristophe Lombard long cxl_h_download_adapter_image(u64 unit_address,
628444c4ba4SChristophe Lombard 				  u64 list_address, u64 num,
629444c4ba4SChristophe Lombard 				  u64 *out)
630444c4ba4SChristophe Lombard {
631444c4ba4SChristophe Lombard 	return cxl_h_download_facility(unit_address,
632444c4ba4SChristophe Lombard 				       H_DOWNLOAD_CA_FACILITY_DOWNLOAD,
633444c4ba4SChristophe Lombard 				       list_address, num, out);
634444c4ba4SChristophe Lombard }
635444c4ba4SChristophe Lombard 
636444c4ba4SChristophe Lombard /**
637444c4ba4SChristophe Lombard  * cxl_h_validate_adapter_image - Validate the base image in the coherent
638444c4ba4SChristophe Lombard  *                                platform facility.
639444c4ba4SChristophe Lombard  */
640444c4ba4SChristophe Lombard long cxl_h_validate_adapter_image(u64 unit_address,
641444c4ba4SChristophe Lombard 				  u64 list_address, u64 num,
642444c4ba4SChristophe Lombard 				  u64 *out)
643444c4ba4SChristophe Lombard {
644444c4ba4SChristophe Lombard 	return cxl_h_download_facility(unit_address,
645444c4ba4SChristophe Lombard 				       H_DOWNLOAD_CA_FACILITY_VALIDATE,
646444c4ba4SChristophe Lombard 				       list_address, num, out);
647444c4ba4SChristophe Lombard }
648