xref: /linux/arch/s390/include/asm/ap.h (revision b9639b3155d9fac737742324443d3f36ff7abc7c)
19fa1db4cSMartin Schwidefsky /* SPDX-License-Identifier: GPL-2.0 */
2e7fc5146STony Krowiak /*
3e7fc5146STony Krowiak  * Adjunct processor (AP) interfaces
4e7fc5146STony Krowiak  *
5e7fc5146STony Krowiak  * Copyright IBM Corp. 2017
6e7fc5146STony Krowiak  *
7e7fc5146STony Krowiak  * Author(s): Tony Krowiak <akrowia@linux.vnet.ibm.com>
8e7fc5146STony Krowiak  *	      Martin Schwidefsky <schwidefsky@de.ibm.com>
9e7fc5146STony Krowiak  *	      Harald Freudenberger <freude@de.ibm.com>
10e7fc5146STony Krowiak  */
11e7fc5146STony Krowiak 
12e7fc5146STony Krowiak #ifndef _ASM_S390_AP_H_
13e7fc5146STony Krowiak #define _ASM_S390_AP_H_
14e7fc5146STony Krowiak 
15e7fc5146STony Krowiak /**
16e7fc5146STony Krowiak  * The ap_qid_t identifier of an ap queue.
17e7fc5146STony Krowiak  * If the AP facilities test (APFT) facility is available,
18e7fc5146STony Krowiak  * card and queue index are 8 bit values, otherwise
19e7fc5146STony Krowiak  * card index is 6 bit and queue index a 4 bit value.
20e7fc5146STony Krowiak  */
21e7fc5146STony Krowiak typedef unsigned int ap_qid_t;
22e7fc5146STony Krowiak 
23af4a7227SHarald Freudenberger #define AP_MKQID(_card, _queue) (((_card) & 0xff) << 8 | ((_queue) & 0xff))
24af4a7227SHarald Freudenberger #define AP_QID_CARD(_qid) (((_qid) >> 8) & 0xff)
25af4a7227SHarald Freudenberger #define AP_QID_QUEUE(_qid) ((_qid) & 0xff)
26e7fc5146STony Krowiak 
27e7fc5146STony Krowiak /**
28e7fc5146STony Krowiak  * struct ap_queue_status - Holds the AP queue status.
29e7fc5146STony Krowiak  * @queue_empty: Shows if queue is empty
30e7fc5146STony Krowiak  * @replies_waiting: Waiting replies
31e7fc5146STony Krowiak  * @queue_full: Is 1 if the queue is full
32e7fc5146STony Krowiak  * @irq_enabled: Shows if interrupts are enabled for the AP
33e7fc5146STony Krowiak  * @response_code: Holds the 8 bit response code
34e7fc5146STony Krowiak  *
35e7fc5146STony Krowiak  * The ap queue status word is returned by all three AP functions
36e7fc5146STony Krowiak  * (PQAP, NQAP and DQAP).  There's a set of flags in the first
37e7fc5146STony Krowiak  * byte, followed by a 1 byte response code.
38e7fc5146STony Krowiak  */
39e7fc5146STony Krowiak struct ap_queue_status {
40e7fc5146STony Krowiak 	unsigned int queue_empty	: 1;
41e7fc5146STony Krowiak 	unsigned int replies_waiting	: 1;
42e7fc5146STony Krowiak 	unsigned int queue_full		: 1;
43e7fc5146STony Krowiak 	unsigned int _pad1		: 4;
44e7fc5146STony Krowiak 	unsigned int irq_enabled	: 1;
45e7fc5146STony Krowiak 	unsigned int response_code	: 8;
46e7fc5146STony Krowiak 	unsigned int _pad2		: 16;
47e7fc5146STony Krowiak };
48e7fc5146STony Krowiak 
49e7fc5146STony Krowiak /**
50f1b0a434SHarald Freudenberger  * ap_intructions_available() - Test if AP instructions are available.
51f1b0a434SHarald Freudenberger  *
529b97e9f5SHarald Freudenberger  * Returns true if the AP instructions are installed, otherwise false.
53f1b0a434SHarald Freudenberger  */
549b97e9f5SHarald Freudenberger static inline bool ap_instructions_available(void)
55f1b0a434SHarald Freudenberger {
56*b9639b31SHeiko Carstens 	unsigned long reg0 = AP_MKQID(0, 0);
57*b9639b31SHeiko Carstens 	unsigned long reg1 = 0;
58f1b0a434SHarald Freudenberger 
59f1b0a434SHarald Freudenberger 	asm volatile(
60*b9639b31SHeiko Carstens 		"	lgr	0,%[reg0]\n"   /* qid into gr0 */
61*b9639b31SHeiko Carstens 		"	lghi	1,0\n"	       /* 0 into gr1 */
62*b9639b31SHeiko Carstens 		"	lghi	2,0\n"	       /* 0 into gr2 */
63f1b0a434SHarald Freudenberger 		"	.long	0xb2af0000\n"  /* PQAP(TAPQ) */
64*b9639b31SHeiko Carstens 		"0:	la	%[reg1],1\n"   /* 1 into reg1 */
65f1b0a434SHarald Freudenberger 		"1:\n"
66f1b0a434SHarald Freudenberger 		EX_TABLE(0b, 1b)
67*b9639b31SHeiko Carstens 		: [reg1] "+&d" (reg1)
68*b9639b31SHeiko Carstens 		: [reg0] "d" (reg0)
69*b9639b31SHeiko Carstens 		: "cc", "0", "1", "2");
709b97e9f5SHarald Freudenberger 	return reg1 != 0;
71f1b0a434SHarald Freudenberger }
72f1b0a434SHarald Freudenberger 
73f1b0a434SHarald Freudenberger /**
74f1b0a434SHarald Freudenberger  * ap_tapq(): Test adjunct processor queue.
75f1b0a434SHarald Freudenberger  * @qid: The AP queue number
76f1b0a434SHarald Freudenberger  * @info: Pointer to queue descriptor
77f1b0a434SHarald Freudenberger  *
78f1b0a434SHarald Freudenberger  * Returns AP queue status structure.
79f1b0a434SHarald Freudenberger  */
80f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_tapq(ap_qid_t qid, unsigned long *info)
81f1b0a434SHarald Freudenberger {
82*b9639b31SHeiko Carstens 	struct ap_queue_status reg1;
83*b9639b31SHeiko Carstens 	unsigned long reg2;
84f1b0a434SHarald Freudenberger 
85*b9639b31SHeiko Carstens 	asm volatile(
86*b9639b31SHeiko Carstens 		"	lgr	0,%[qid]\n"    /* qid into gr0 */
87*b9639b31SHeiko Carstens 		"	lghi	2,0\n"	       /* 0 into gr2 */
88*b9639b31SHeiko Carstens 		"	.long	0xb2af0000\n"  /* PQAP(TAPQ) */
89*b9639b31SHeiko Carstens 		"	lgr	%[reg1],1\n"   /* gr1 (status) into reg1 */
90*b9639b31SHeiko Carstens 		"	lgr	%[reg2],2\n"   /* gr2 into reg2 */
91*b9639b31SHeiko Carstens 		: [reg1] "=&d" (reg1), [reg2] "=&d" (reg2)
92*b9639b31SHeiko Carstens 		: [qid] "d" (qid)
93*b9639b31SHeiko Carstens 		: "cc", "0", "1", "2");
94f1b0a434SHarald Freudenberger 	if (info)
95f1b0a434SHarald Freudenberger 		*info = reg2;
96f1b0a434SHarald Freudenberger 	return reg1;
97f1b0a434SHarald Freudenberger }
98f1b0a434SHarald Freudenberger 
99f1b0a434SHarald Freudenberger /**
100e7fc5146STony Krowiak  * ap_test_queue(): Test adjunct processor queue.
101e7fc5146STony Krowiak  * @qid: The AP queue number
102e7fc5146STony Krowiak  * @tbit: Test facilities bit
103e7fc5146STony Krowiak  * @info: Pointer to queue descriptor
104e7fc5146STony Krowiak  *
105e7fc5146STony Krowiak  * Returns AP queue status structure.
106e7fc5146STony Krowiak  */
107f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_test_queue(ap_qid_t qid,
108e7fc5146STony Krowiak 						   int tbit,
109f1b0a434SHarald Freudenberger 						   unsigned long *info)
110f1b0a434SHarald Freudenberger {
111f1b0a434SHarald Freudenberger 	if (tbit)
112f1b0a434SHarald Freudenberger 		qid |= 1UL << 23; /* set T bit*/
113f1b0a434SHarald Freudenberger 	return ap_tapq(qid, info);
114f1b0a434SHarald Freudenberger }
115e7fc5146STony Krowiak 
116f1b0a434SHarald Freudenberger /**
117f1b0a434SHarald Freudenberger  * ap_pqap_rapq(): Reset adjunct processor queue.
118f1b0a434SHarald Freudenberger  * @qid: The AP queue number
119f1b0a434SHarald Freudenberger  *
120f1b0a434SHarald Freudenberger  * Returns AP queue status structure.
121f1b0a434SHarald Freudenberger  */
122f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_rapq(ap_qid_t qid)
123f1b0a434SHarald Freudenberger {
124*b9639b31SHeiko Carstens 	unsigned long reg0 = qid | (1UL << 24);  /* fc 1UL is RAPQ */
125*b9639b31SHeiko Carstens 	struct ap_queue_status reg1;
126f1b0a434SHarald Freudenberger 
127f1b0a434SHarald Freudenberger 	asm volatile(
128*b9639b31SHeiko Carstens 		"	lgr	0,%[reg0]\n"  /* qid arg into gr0 */
129*b9639b31SHeiko Carstens 		"	.long	0xb2af0000\n" /* PQAP(RAPQ) */
130*b9639b31SHeiko Carstens 		"	lgr	%[reg1],1\n"  /* gr1 (status) into reg1 */
131*b9639b31SHeiko Carstens 		: [reg1] "=&d" (reg1)
132*b9639b31SHeiko Carstens 		: [reg0] "d" (reg0)
133*b9639b31SHeiko Carstens 		: "cc", "0", "1");
134f1b0a434SHarald Freudenberger 	return reg1;
135f1b0a434SHarald Freudenberger }
136f1b0a434SHarald Freudenberger 
137f1b0a434SHarald Freudenberger /**
138f1b0a434SHarald Freudenberger  * ap_pqap_zapq(): Reset and zeroize adjunct processor queue.
139f1b0a434SHarald Freudenberger  * @qid: The AP queue number
140f1b0a434SHarald Freudenberger  *
141f1b0a434SHarald Freudenberger  * Returns AP queue status structure.
142f1b0a434SHarald Freudenberger  */
143f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_zapq(ap_qid_t qid)
144f1b0a434SHarald Freudenberger {
145*b9639b31SHeiko Carstens 	unsigned long reg0 = qid | (2UL << 24);  /* fc 2UL is ZAPQ */
146*b9639b31SHeiko Carstens 	struct ap_queue_status reg1;
147f1b0a434SHarald Freudenberger 
148f1b0a434SHarald Freudenberger 	asm volatile(
149*b9639b31SHeiko Carstens 		"	lgr	0,%[reg0]\n"   /* qid arg into gr0 */
150*b9639b31SHeiko Carstens 		"	.long	0xb2af0000\n"  /* PQAP(ZAPQ) */
151*b9639b31SHeiko Carstens 		"	lgr	%[reg1],1\n"   /* gr1 (status) into reg1 */
152*b9639b31SHeiko Carstens 		: [reg1] "=&d" (reg1)
153*b9639b31SHeiko Carstens 		: [reg0] "d" (reg0)
154*b9639b31SHeiko Carstens 		: "cc", "0", "1");
155f1b0a434SHarald Freudenberger 	return reg1;
156f1b0a434SHarald Freudenberger }
157f1b0a434SHarald Freudenberger 
158f1b0a434SHarald Freudenberger /**
159f1b0a434SHarald Freudenberger  * struct ap_config_info - convenience struct for AP crypto
160f1b0a434SHarald Freudenberger  * config info as returned by the ap_qci() function.
161f1b0a434SHarald Freudenberger  */
162050349b5SHarald Freudenberger struct ap_config_info {
163050349b5SHarald Freudenberger 	unsigned int apsc	 : 1;	/* S bit */
164050349b5SHarald Freudenberger 	unsigned int apxa	 : 1;	/* N bit */
165050349b5SHarald Freudenberger 	unsigned int qact	 : 1;	/* C bit */
166050349b5SHarald Freudenberger 	unsigned int rc8a	 : 1;	/* R bit */
167050349b5SHarald Freudenberger 	unsigned char _reserved1 : 4;
168050349b5SHarald Freudenberger 	unsigned char _reserved2[3];
169050349b5SHarald Freudenberger 	unsigned char Na;		/* max # of APs - 1 */
170050349b5SHarald Freudenberger 	unsigned char Nd;		/* max # of Domains - 1 */
171050349b5SHarald Freudenberger 	unsigned char _reserved3[10];
172050349b5SHarald Freudenberger 	unsigned int apm[8];		/* AP ID mask */
1737379e652SHarald Freudenberger 	unsigned int aqm[8];		/* AP (usage) queue mask */
1747379e652SHarald Freudenberger 	unsigned int adm[8];		/* AP (control) domain mask */
175050349b5SHarald Freudenberger 	unsigned char _reserved4[16];
176050349b5SHarald Freudenberger } __aligned(8);
177050349b5SHarald Freudenberger 
178f1b0a434SHarald Freudenberger /**
179f1b0a434SHarald Freudenberger  * ap_qci(): Get AP configuration data
180050349b5SHarald Freudenberger  *
181f1b0a434SHarald Freudenberger  * Returns 0 on success, or -EOPNOTSUPP.
182050349b5SHarald Freudenberger  */
183f1b0a434SHarald Freudenberger static inline int ap_qci(struct ap_config_info *config)
184f1b0a434SHarald Freudenberger {
185*b9639b31SHeiko Carstens 	unsigned long reg0 = 4UL << 24;  /* fc 4UL is QCI */
186*b9639b31SHeiko Carstens 	unsigned long reg1 = -EOPNOTSUPP;
187*b9639b31SHeiko Carstens 	struct ap_config_info *reg2 = config;
188f1b0a434SHarald Freudenberger 
189f1b0a434SHarald Freudenberger 	asm volatile(
190*b9639b31SHeiko Carstens 		"	lgr	0,%[reg0]\n"   /* QCI fc into gr0 */
191*b9639b31SHeiko Carstens 		"	lgr	2,%[reg2]\n"   /* ptr to config into gr2 */
192f1b0a434SHarald Freudenberger 		"	.long	0xb2af0000\n"  /* PQAP(QCI) */
193*b9639b31SHeiko Carstens 		"0:	la	%[reg1],0\n"   /* good case, QCI fc available */
194f1b0a434SHarald Freudenberger 		"1:\n"
195f1b0a434SHarald Freudenberger 		EX_TABLE(0b, 1b)
196*b9639b31SHeiko Carstens 		: [reg1] "+&d" (reg1)
197*b9639b31SHeiko Carstens 		: [reg0] "d" (reg0), [reg2] "d" (reg2)
198*b9639b31SHeiko Carstens 		: "cc", "memory", "0", "2");
199f1b0a434SHarald Freudenberger 
200f1b0a434SHarald Freudenberger 	return reg1;
201f1b0a434SHarald Freudenberger }
202050349b5SHarald Freudenberger 
20346fde9a9SHarald Freudenberger /*
20446fde9a9SHarald Freudenberger  * struct ap_qirq_ctrl - convenient struct for easy invocation
205f1b0a434SHarald Freudenberger  * of the ap_aqic() function. This struct is passed as GR1
206f1b0a434SHarald Freudenberger  * parameter to the PQAP(AQIC) instruction. For details please
207f1b0a434SHarald Freudenberger  * see the AR documentation.
20846fde9a9SHarald Freudenberger  */
20946fde9a9SHarald Freudenberger struct ap_qirq_ctrl {
21046fde9a9SHarald Freudenberger 	unsigned int _res1 : 8;
21146fde9a9SHarald Freudenberger 	unsigned int zone  : 8;	/* zone info */
21246fde9a9SHarald Freudenberger 	unsigned int ir    : 1;	/* ir flag: enable (1) or disable (0) irq */
21346fde9a9SHarald Freudenberger 	unsigned int _res2 : 4;
21446fde9a9SHarald Freudenberger 	unsigned int gisc  : 3;	/* guest isc field */
21546fde9a9SHarald Freudenberger 	unsigned int _res3 : 6;
21646fde9a9SHarald Freudenberger 	unsigned int gf    : 2;	/* gisa format */
21746fde9a9SHarald Freudenberger 	unsigned int _res4 : 1;
21846fde9a9SHarald Freudenberger 	unsigned int gisa  : 27;	/* gisa origin */
21946fde9a9SHarald Freudenberger 	unsigned int _res5 : 1;
22046fde9a9SHarald Freudenberger 	unsigned int isc   : 3;	/* irq sub class */
22146fde9a9SHarald Freudenberger };
22246fde9a9SHarald Freudenberger 
22346fde9a9SHarald Freudenberger /**
224f1b0a434SHarald Freudenberger  * ap_aqic(): Control interruption for a specific AP.
22546fde9a9SHarald Freudenberger  * @qid: The AP queue number
226f1b0a434SHarald Freudenberger  * @qirqctrl: struct ap_qirq_ctrl (64 bit value)
22746fde9a9SHarald Freudenberger  * @ind: The notification indicator byte
22846fde9a9SHarald Freudenberger  *
22946fde9a9SHarald Freudenberger  * Returns AP queue status.
23046fde9a9SHarald Freudenberger  */
231f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_aqic(ap_qid_t qid,
23246fde9a9SHarald Freudenberger 					     struct ap_qirq_ctrl qirqctrl,
233f1b0a434SHarald Freudenberger 					     void *ind)
234f1b0a434SHarald Freudenberger {
235*b9639b31SHeiko Carstens 	unsigned long reg0 = qid | (3UL << 24);  /* fc 3UL is AQIC */
236*b9639b31SHeiko Carstens 	union {
237159491f3SHarald Freudenberger 		unsigned long value;
238159491f3SHarald Freudenberger 		struct ap_qirq_ctrl qirqctrl;
239159491f3SHarald Freudenberger 		struct ap_queue_status status;
240*b9639b31SHeiko Carstens 	} reg1;
241*b9639b31SHeiko Carstens 	void *reg2 = ind;
242f1b0a434SHarald Freudenberger 
243159491f3SHarald Freudenberger 	reg1.qirqctrl = qirqctrl;
244159491f3SHarald Freudenberger 
245f1b0a434SHarald Freudenberger 	asm volatile(
246*b9639b31SHeiko Carstens 		"	lgr	0,%[reg0]\n"   /* qid param into gr0 */
247*b9639b31SHeiko Carstens 		"	lgr	1,%[reg1]\n"   /* irq ctrl into gr1 */
248*b9639b31SHeiko Carstens 		"	lgr	2,%[reg2]\n"   /* ni addr into gr2 */
249*b9639b31SHeiko Carstens 		"	.long	0xb2af0000\n"  /* PQAP(AQIC) */
250*b9639b31SHeiko Carstens 		"	lgr	%[reg1],1\n"   /* gr1 (status) into reg1 */
251*b9639b31SHeiko Carstens 		: [reg1] "+&d" (reg1)
252*b9639b31SHeiko Carstens 		: [reg0] "d" (reg0), [reg2] "d" (reg2)
253*b9639b31SHeiko Carstens 		: "cc", "0", "1", "2");
254159491f3SHarald Freudenberger 
255159491f3SHarald Freudenberger 	return reg1.status;
256f1b0a434SHarald Freudenberger }
257f1b0a434SHarald Freudenberger 
258f1b0a434SHarald Freudenberger /*
259f1b0a434SHarald Freudenberger  * union ap_qact_ap_info - used together with the
260f1b0a434SHarald Freudenberger  * ap_aqic() function to provide a convenient way
261f1b0a434SHarald Freudenberger  * to handle the ap info needed by the qact function.
262f1b0a434SHarald Freudenberger  */
263f1b0a434SHarald Freudenberger union ap_qact_ap_info {
264f1b0a434SHarald Freudenberger 	unsigned long val;
265f1b0a434SHarald Freudenberger 	struct {
266f1b0a434SHarald Freudenberger 		unsigned int	  : 3;
267f1b0a434SHarald Freudenberger 		unsigned int mode : 3;
268f1b0a434SHarald Freudenberger 		unsigned int	  : 26;
269f1b0a434SHarald Freudenberger 		unsigned int cat  : 8;
270f1b0a434SHarald Freudenberger 		unsigned int	  : 8;
271f1b0a434SHarald Freudenberger 		unsigned char ver[2];
272f1b0a434SHarald Freudenberger 	};
273f1b0a434SHarald Freudenberger };
274f1b0a434SHarald Freudenberger 
275f1b0a434SHarald Freudenberger /**
276f1b0a434SHarald Freudenberger  * ap_qact(): Query AP combatibility type.
277f1b0a434SHarald Freudenberger  * @qid: The AP queue number
278f1b0a434SHarald Freudenberger  * @apinfo: On input the info about the AP queue. On output the
279f1b0a434SHarald Freudenberger  *	    alternate AP queue info provided by the qact function
280f1b0a434SHarald Freudenberger  *	    in GR2 is stored in.
281f1b0a434SHarald Freudenberger  *
282f1b0a434SHarald Freudenberger  * Returns AP queue status. Check response_code field for failures.
283f1b0a434SHarald Freudenberger  */
284f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_qact(ap_qid_t qid, int ifbit,
285f1b0a434SHarald Freudenberger 					     union ap_qact_ap_info *apinfo)
286f1b0a434SHarald Freudenberger {
287*b9639b31SHeiko Carstens 	unsigned long reg0 = qid | (5UL << 24) | ((ifbit & 0x01) << 22);
288*b9639b31SHeiko Carstens 	union {
289159491f3SHarald Freudenberger 		unsigned long value;
290159491f3SHarald Freudenberger 		struct ap_queue_status status;
291*b9639b31SHeiko Carstens 	} reg1;
292*b9639b31SHeiko Carstens 	unsigned long reg2;
293f1b0a434SHarald Freudenberger 
294159491f3SHarald Freudenberger 	reg1.value = apinfo->val;
295159491f3SHarald Freudenberger 
296f1b0a434SHarald Freudenberger 	asm volatile(
297*b9639b31SHeiko Carstens 		"	lgr	0,%[reg0]\n"   /* qid param into gr0 */
298*b9639b31SHeiko Carstens 		"	lgr	1,%[reg1]\n"   /* qact in info into gr1 */
299*b9639b31SHeiko Carstens 		"	.long	0xb2af0000\n"  /* PQAP(QACT) */
300*b9639b31SHeiko Carstens 		"	lgr	%[reg1],1\n"   /* gr1 (status) into reg1 */
301*b9639b31SHeiko Carstens 		"	lgr	%[reg2],2\n"   /* qact out info into reg2 */
302*b9639b31SHeiko Carstens 		: [reg1] "+&d" (reg1), [reg2] "=&d" (reg2)
303*b9639b31SHeiko Carstens 		: [reg0] "d" (reg0)
304*b9639b31SHeiko Carstens 		: "cc", "0", "1", "2");
305f1b0a434SHarald Freudenberger 	apinfo->val = reg2;
306159491f3SHarald Freudenberger 	return reg1.status;
307f1b0a434SHarald Freudenberger }
308f1b0a434SHarald Freudenberger 
309f1b0a434SHarald Freudenberger /**
310f1b0a434SHarald Freudenberger  * ap_nqap(): Send message to adjunct processor queue.
311f1b0a434SHarald Freudenberger  * @qid: The AP queue number
312f1b0a434SHarald Freudenberger  * @psmid: The program supplied message identifier
313f1b0a434SHarald Freudenberger  * @msg: The message text
314f1b0a434SHarald Freudenberger  * @length: The message length
315f1b0a434SHarald Freudenberger  *
316f1b0a434SHarald Freudenberger  * Returns AP queue status structure.
317f1b0a434SHarald Freudenberger  * Condition code 1 on NQAP can't happen because the L bit is 1.
318f1b0a434SHarald Freudenberger  * Condition code 2 on NQAP also means the send is incomplete,
319f1b0a434SHarald Freudenberger  * because a segment boundary was reached. The NQAP is repeated.
320f1b0a434SHarald Freudenberger  */
321f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_nqap(ap_qid_t qid,
322f1b0a434SHarald Freudenberger 					     unsigned long long psmid,
323f1b0a434SHarald Freudenberger 					     void *msg, size_t length)
324f1b0a434SHarald Freudenberger {
325*b9639b31SHeiko Carstens 	unsigned long reg0 = qid | 0x40000000UL;  /* 0x4... is last msg part */
326*b9639b31SHeiko Carstens 	union register_pair nqap_r1, nqap_r2;
327*b9639b31SHeiko Carstens 	struct ap_queue_status reg1;
328*b9639b31SHeiko Carstens 
329*b9639b31SHeiko Carstens 	nqap_r1.even = (unsigned int)(psmid >> 32);
330*b9639b31SHeiko Carstens 	nqap_r1.odd  = psmid & 0xffffffff;
331*b9639b31SHeiko Carstens 	nqap_r2.even = (unsigned long)msg;
332*b9639b31SHeiko Carstens 	nqap_r2.odd  = (unsigned long)length;
333f1b0a434SHarald Freudenberger 
334f1b0a434SHarald Freudenberger 	asm volatile (
335*b9639b31SHeiko Carstens 		"	lgr	0,%[reg0]\n"  /* qid param in gr0 */
336*b9639b31SHeiko Carstens 		"0:	.insn	rre,0xb2ad0000,%[nqap_r1],%[nqap_r2]\n"
337*b9639b31SHeiko Carstens 		"	brc	2,0b\n"       /* handle partial completion */
338*b9639b31SHeiko Carstens 		"	lgr	%[reg1],1\n"  /* gr1 (status) into reg1 */
339*b9639b31SHeiko Carstens 		: [reg0] "+&d" (reg0), [reg1] "=&d" (reg1),
340*b9639b31SHeiko Carstens 		  [nqap_r2] "+&d" (nqap_r2.pair)
341*b9639b31SHeiko Carstens 		: [nqap_r1] "d" (nqap_r1.pair)
342*b9639b31SHeiko Carstens 		: "cc", "memory", "0", "1");
343f1b0a434SHarald Freudenberger 	return reg1;
344f1b0a434SHarald Freudenberger }
345f1b0a434SHarald Freudenberger 
346f1b0a434SHarald Freudenberger /**
347f1b0a434SHarald Freudenberger  * ap_dqap(): Receive message from adjunct processor queue.
348f1b0a434SHarald Freudenberger  * @qid: The AP queue number
349f1b0a434SHarald Freudenberger  * @psmid: Pointer to program supplied message identifier
350f1b0a434SHarald Freudenberger  * @msg: The message text
351f1b0a434SHarald Freudenberger  * @length: The message length
3521f0d22deSHarald Freudenberger  * @reslength: Resitual length on return
3531f0d22deSHarald Freudenberger  * @resgr0: input: gr0 value (only used if != 0), output: resitual gr0 content
354f1b0a434SHarald Freudenberger  *
355f1b0a434SHarald Freudenberger  * Returns AP queue status structure.
356f1b0a434SHarald Freudenberger  * Condition code 1 on DQAP means the receive has taken place
357f1b0a434SHarald Freudenberger  * but only partially.	The response is incomplete, hence the
358f1b0a434SHarald Freudenberger  * DQAP is repeated.
359f1b0a434SHarald Freudenberger  * Condition code 2 on DQAP also means the receive is incomplete,
360f1b0a434SHarald Freudenberger  * this time because a segment boundary was reached. Again, the
361f1b0a434SHarald Freudenberger  * DQAP is repeated.
362f1b0a434SHarald Freudenberger  * Note that gpr2 is used by the DQAP instruction to keep track of
363f1b0a434SHarald Freudenberger  * any 'residual' length, in case the instruction gets interrupted.
364f1b0a434SHarald Freudenberger  * Hence it gets zeroed before the instruction.
3651f0d22deSHarald Freudenberger  * If the message does not fit into the buffer, this function will
3661f0d22deSHarald Freudenberger  * return with a truncated message and the reply in the firmware queue
3671f0d22deSHarald Freudenberger  * is not removed. This is indicated to the caller with an
3681f0d22deSHarald Freudenberger  * ap_queue_status response_code value of all bits on (0xFF) and (if
3691f0d22deSHarald Freudenberger  * the reslength ptr is given) the remaining length is stored in
3701f0d22deSHarald Freudenberger  * *reslength and (if the resgr0 ptr is given) the updated gr0 value
3711f0d22deSHarald Freudenberger  * for further processing of this msg entry is stored in *resgr0. The
3721f0d22deSHarald Freudenberger  * caller needs to detect this situation and should invoke ap_dqap
3731f0d22deSHarald Freudenberger  * with a valid resgr0 ptr and a value in there != 0 to indicate that
3741f0d22deSHarald Freudenberger  * *resgr0 is to be used instead of qid to further process this entry.
375f1b0a434SHarald Freudenberger  */
376f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_dqap(ap_qid_t qid,
377f1b0a434SHarald Freudenberger 					     unsigned long long *psmid,
3781f0d22deSHarald Freudenberger 					     void *msg, size_t length,
3791f0d22deSHarald Freudenberger 					     size_t *reslength,
3801f0d22deSHarald Freudenberger 					     unsigned long *resgr0)
381f1b0a434SHarald Freudenberger {
3821f0d22deSHarald Freudenberger 	register unsigned long reg0 asm("0") =
3831f0d22deSHarald Freudenberger 		resgr0 && *resgr0 ? *resgr0 : qid | 0x80000000UL;
384f1b0a434SHarald Freudenberger 	register struct ap_queue_status reg1 asm ("1");
385f1b0a434SHarald Freudenberger 	register unsigned long reg2 asm("2") = 0UL;
386f1b0a434SHarald Freudenberger 	register unsigned long reg4 asm("4") = (unsigned long) msg;
387f1b0a434SHarald Freudenberger 	register unsigned long reg5 asm("5") = (unsigned long) length;
388f1b0a434SHarald Freudenberger 	register unsigned long reg6 asm("6") = 0UL;
389f1b0a434SHarald Freudenberger 	register unsigned long reg7 asm("7") = 0UL;
390f1b0a434SHarald Freudenberger 
391f1b0a434SHarald Freudenberger 	asm volatile(
3921f0d22deSHarald Freudenberger 		"0: ltgr  %[bl],%[bl]\n" /* if avail. buf len is 0 then */
3931f0d22deSHarald Freudenberger 		"   jz    2f\n"		 /* go out of this asm block */
3941f0d22deSHarald Freudenberger 		"1: .long 0xb2ae0064\n"  /* DQAP */
3951f0d22deSHarald Freudenberger 		"   brc   6,0b\n"	 /* if partially do again */
3961f0d22deSHarald Freudenberger 		"2:\n"
397f1b0a434SHarald Freudenberger 		: "+d" (reg0), "=d" (reg1), "+d" (reg2),
3981f0d22deSHarald Freudenberger 		  "+d" (reg4), [bl] "+d" (reg5), "+d" (reg6), "+d" (reg7)
399f1b0a434SHarald Freudenberger 		: : "cc", "memory");
4001f0d22deSHarald Freudenberger 
4011f0d22deSHarald Freudenberger 	if (reslength)
4021f0d22deSHarald Freudenberger 		*reslength = reg2;
4031f0d22deSHarald Freudenberger 	if (reg2 != 0 && reg5 == 0) {
4041f0d22deSHarald Freudenberger 		/*
4051f0d22deSHarald Freudenberger 		 * Partially complete, status in gr1 is not set.
4061f0d22deSHarald Freudenberger 		 * Signal the caller that this dqap is only partially received
4071f0d22deSHarald Freudenberger 		 * with a special status response code 0xFF and *resgr0 updated
4081f0d22deSHarald Freudenberger 		 */
4091f0d22deSHarald Freudenberger 		reg1.response_code = 0xFF;
4101f0d22deSHarald Freudenberger 		if (resgr0)
4111f0d22deSHarald Freudenberger 			*resgr0 = reg0;
4121f0d22deSHarald Freudenberger 	} else {
413f1b0a434SHarald Freudenberger 		*psmid = (((unsigned long long) reg6) << 32) + reg7;
4141f0d22deSHarald Freudenberger 		if (resgr0)
4151f0d22deSHarald Freudenberger 			*resgr0 = 0;
4161f0d22deSHarald Freudenberger 	}
4171f0d22deSHarald Freudenberger 
418f1b0a434SHarald Freudenberger 	return reg1;
419f1b0a434SHarald Freudenberger }
42046fde9a9SHarald Freudenberger 
4210d9c038fSTony Krowiak /*
4220d9c038fSTony Krowiak  * Interface to tell the AP bus code that a configuration
4230d9c038fSTony Krowiak  * change has happened. The bus code should at least do
4240d9c038fSTony Krowiak  * an ap bus resource rescan.
4250d9c038fSTony Krowiak  */
4260d9c038fSTony Krowiak #if IS_ENABLED(CONFIG_ZCRYPT)
4270d9c038fSTony Krowiak void ap_bus_cfg_chg(void);
4280d9c038fSTony Krowiak #else
429d09cb482SChengyang Fan static inline void ap_bus_cfg_chg(void){}
4300d9c038fSTony Krowiak #endif
4310d9c038fSTony Krowiak 
432e7fc5146STony Krowiak #endif /* _ASM_S390_AP_H_ */
433