xref: /linux/arch/s390/include/asm/ap.h (revision 621cde16e49b3ecf7d59a8106a20aaebfb4a59a9)
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 
157a334a28SHeiko Carstens #include <linux/io.h>
16d09a307fSHeiko Carstens #include <asm/asm-extable.h>
177a334a28SHeiko Carstens 
18e7fc5146STony Krowiak /**
19e7fc5146STony Krowiak  * The ap_qid_t identifier of an ap queue.
20e7fc5146STony Krowiak  * If the AP facilities test (APFT) facility is available,
21e7fc5146STony Krowiak  * card and queue index are 8 bit values, otherwise
22e7fc5146STony Krowiak  * card index is 6 bit and queue index a 4 bit value.
23e7fc5146STony Krowiak  */
24e7fc5146STony Krowiak typedef unsigned int ap_qid_t;
25e7fc5146STony Krowiak 
26af4a7227SHarald Freudenberger #define AP_MKQID(_card, _queue) (((_card) & 0xff) << 8 | ((_queue) & 0xff))
27af4a7227SHarald Freudenberger #define AP_QID_CARD(_qid) (((_qid) >> 8) & 0xff)
28af4a7227SHarald Freudenberger #define AP_QID_QUEUE(_qid) ((_qid) & 0xff)
29e7fc5146STony Krowiak 
30e7fc5146STony Krowiak /**
31e7fc5146STony Krowiak  * struct ap_queue_status - Holds the AP queue status.
32e7fc5146STony Krowiak  * @queue_empty: Shows if queue is empty
33e7fc5146STony Krowiak  * @replies_waiting: Waiting replies
34e7fc5146STony Krowiak  * @queue_full: Is 1 if the queue is full
35e7fc5146STony Krowiak  * @irq_enabled: Shows if interrupts are enabled for the AP
36e7fc5146STony Krowiak  * @response_code: Holds the 8 bit response code
37e7fc5146STony Krowiak  *
38e7fc5146STony Krowiak  * The ap queue status word is returned by all three AP functions
39e7fc5146STony Krowiak  * (PQAP, NQAP and DQAP).  There's a set of flags in the first
40e7fc5146STony Krowiak  * byte, followed by a 1 byte response code.
41e7fc5146STony Krowiak  */
42e7fc5146STony Krowiak struct ap_queue_status {
43e7fc5146STony Krowiak 	unsigned int queue_empty	: 1;
44e7fc5146STony Krowiak 	unsigned int replies_waiting	: 1;
45e7fc5146STony Krowiak 	unsigned int queue_full		: 1;
462d72eaf0SHarald Freudenberger 	unsigned int			: 3;
472d72eaf0SHarald Freudenberger 	unsigned int async		: 1;
48e7fc5146STony Krowiak 	unsigned int irq_enabled	: 1;
49e7fc5146STony Krowiak 	unsigned int response_code	: 8;
502d72eaf0SHarald Freudenberger 	unsigned int			: 16;
51e7fc5146STony Krowiak };
52e7fc5146STony Krowiak 
53ebf95e88SHarald Freudenberger /*
54ebf95e88SHarald Freudenberger  * AP queue status reg union to access the reg1
55ebf95e88SHarald Freudenberger  * register with the lower 32 bits comprising the
56ebf95e88SHarald Freudenberger  * ap queue status.
57ebf95e88SHarald Freudenberger  */
58ebf95e88SHarald Freudenberger union ap_queue_status_reg {
59ebf95e88SHarald Freudenberger 	unsigned long value;
60ebf95e88SHarald Freudenberger 	struct {
61ebf95e88SHarald Freudenberger 		u32 _pad;
62ebf95e88SHarald Freudenberger 		struct ap_queue_status status;
63ebf95e88SHarald Freudenberger 	};
64ebf95e88SHarald Freudenberger };
65ebf95e88SHarald Freudenberger 
66e7fc5146STony Krowiak /**
67f1b0a434SHarald Freudenberger  * ap_intructions_available() - Test if AP instructions are available.
68f1b0a434SHarald Freudenberger  *
699b97e9f5SHarald Freudenberger  * Returns true if the AP instructions are installed, otherwise false.
70f1b0a434SHarald Freudenberger  */
ap_instructions_available(void)719b97e9f5SHarald Freudenberger static inline bool ap_instructions_available(void)
72f1b0a434SHarald Freudenberger {
73b9639b31SHeiko Carstens 	unsigned long reg0 = AP_MKQID(0, 0);
74b9639b31SHeiko Carstens 	unsigned long reg1 = 0;
75f1b0a434SHarald Freudenberger 
76f1b0a434SHarald Freudenberger 	asm volatile(
77b9639b31SHeiko Carstens 		"	lgr	0,%[reg0]\n"		/* qid into gr0 */
78b9639b31SHeiko Carstens 		"	lghi	1,0\n"			/* 0 into gr1 */
79b9639b31SHeiko Carstens 		"	lghi	2,0\n"			/* 0 into gr2 */
802d6c0008SHeiko Carstens 		"	.insn	rre,0xb2af0000,0,0\n"	/* PQAP(TAPQ) */
81b9639b31SHeiko Carstens 		"0:	la	%[reg1],1\n"		/* 1 into reg1 */
82f1b0a434SHarald Freudenberger 		"1:\n"
83f1b0a434SHarald Freudenberger 		EX_TABLE(0b, 1b)
84b9639b31SHeiko Carstens 		: [reg1] "+&d" (reg1)
85b9639b31SHeiko Carstens 		: [reg0] "d" (reg0)
86b9639b31SHeiko Carstens 		: "cc", "0", "1", "2");
879b97e9f5SHarald Freudenberger 	return reg1 != 0;
88f1b0a434SHarald Freudenberger }
89f1b0a434SHarald Freudenberger 
90211c06d8SHarald Freudenberger /* TAPQ register GR2 response struct */
91d4c53ae8SHarald Freudenberger struct ap_tapq_hwinfo {
92211c06d8SHarald Freudenberger 	union {
93211c06d8SHarald Freudenberger 		unsigned long value;
94211c06d8SHarald Freudenberger 		struct {
95211c06d8SHarald Freudenberger 			unsigned int fac    : 32; /* facility bits */
96211c06d8SHarald Freudenberger 			unsigned int apinfo : 32; /* ap type, ... */
97211c06d8SHarald Freudenberger 		};
98211c06d8SHarald Freudenberger 		struct {
99d4c53ae8SHarald Freudenberger 			unsigned int apsc  :  1; /* APSC */
100d4c53ae8SHarald Freudenberger 			unsigned int mex4k :  1; /* AP4KM */
101d4c53ae8SHarald Freudenberger 			unsigned int crt4k :  1; /* AP4KC */
102d4c53ae8SHarald Freudenberger 			unsigned int cca   :  1; /* D */
103d4c53ae8SHarald Freudenberger 			unsigned int accel :  1; /* A */
104d4c53ae8SHarald Freudenberger 			unsigned int ep11  :  1; /* X */
105d4c53ae8SHarald Freudenberger 			unsigned int apxa  :  1; /* APXA */
106211c06d8SHarald Freudenberger 			unsigned int	   :  1;
107211c06d8SHarald Freudenberger 			unsigned int class :  8;
108211c06d8SHarald Freudenberger 			unsigned int bs	   :  2; /* SE bind/assoc */
109211c06d8SHarald Freudenberger 			unsigned int	   : 14;
110211c06d8SHarald Freudenberger 			unsigned int at	   :  8; /* ap type */
111211c06d8SHarald Freudenberger 			unsigned int nd	   :  8; /* nr of domains */
112211c06d8SHarald Freudenberger 			unsigned int	   :  4;
113211c06d8SHarald Freudenberger 			unsigned int ml	   :  4; /* apxl ml */
114211c06d8SHarald Freudenberger 			unsigned int	   :  4;
115211c06d8SHarald Freudenberger 			unsigned int qd	   :  4; /* queue depth */
116211c06d8SHarald Freudenberger 		};
117211c06d8SHarald Freudenberger 	};
118211c06d8SHarald Freudenberger };
119211c06d8SHarald Freudenberger 
1202d72eaf0SHarald Freudenberger /*
1212d72eaf0SHarald Freudenberger  * Convenience defines to be used with the bs field from struct ap_tapq_gr2
1222d72eaf0SHarald Freudenberger  */
1232d72eaf0SHarald Freudenberger #define AP_BS_Q_USABLE		      0
1242d72eaf0SHarald Freudenberger #define AP_BS_Q_USABLE_NO_SECURE_KEY  1
1252d72eaf0SHarald Freudenberger #define AP_BS_Q_AVAIL_FOR_BINDING     2
1262d72eaf0SHarald Freudenberger #define AP_BS_Q_UNUSABLE	      3
1272d72eaf0SHarald Freudenberger 
128f1b0a434SHarald Freudenberger /**
129f1b0a434SHarald Freudenberger  * ap_tapq(): Test adjunct processor queue.
130f1b0a434SHarald Freudenberger  * @qid: The AP queue number
131d4c53ae8SHarald Freudenberger  * @info: Pointer to tapq hwinfo struct
132f1b0a434SHarald Freudenberger  *
133f1b0a434SHarald Freudenberger  * Returns AP queue status structure.
134f1b0a434SHarald Freudenberger  */
ap_tapq(ap_qid_t qid,struct ap_tapq_hwinfo * info)135d4c53ae8SHarald Freudenberger static inline struct ap_queue_status ap_tapq(ap_qid_t qid,
136d4c53ae8SHarald Freudenberger 					     struct ap_tapq_hwinfo *info)
137f1b0a434SHarald Freudenberger {
138ebf95e88SHarald Freudenberger 	union ap_queue_status_reg reg1;
139b9639b31SHeiko Carstens 	unsigned long reg2;
140f1b0a434SHarald Freudenberger 
141b9639b31SHeiko Carstens 	asm volatile(
142b9639b31SHeiko Carstens 		"	lgr	0,%[qid]\n"		/* qid into gr0 */
143b9639b31SHeiko Carstens 		"	lghi	2,0\n"			/* 0 into gr2 */
1442d6c0008SHeiko Carstens 		"	.insn	rre,0xb2af0000,0,0\n"	/* PQAP(TAPQ) */
145b9639b31SHeiko Carstens 		"	lgr	%[reg1],1\n"		/* gr1 (status) into reg1 */
146b9639b31SHeiko Carstens 		"	lgr	%[reg2],2\n"		/* gr2 into reg2 */
147ebf95e88SHarald Freudenberger 		: [reg1] "=&d" (reg1.value), [reg2] "=&d" (reg2)
148b9639b31SHeiko Carstens 		: [qid] "d" (qid)
149b9639b31SHeiko Carstens 		: "cc", "0", "1", "2");
150f1b0a434SHarald Freudenberger 	if (info)
151211c06d8SHarald Freudenberger 		info->value = reg2;
152ebf95e88SHarald Freudenberger 	return reg1.status;
153f1b0a434SHarald Freudenberger }
154f1b0a434SHarald Freudenberger 
155f1b0a434SHarald Freudenberger /**
156e7fc5146STony Krowiak  * ap_test_queue(): Test adjunct processor queue.
157e7fc5146STony Krowiak  * @qid: The AP queue number
158e7fc5146STony Krowiak  * @tbit: Test facilities bit
159211c06d8SHarald Freudenberger  * @info: Ptr to tapq gr2 struct
160e7fc5146STony Krowiak  *
161e7fc5146STony Krowiak  * Returns AP queue status structure.
162e7fc5146STony Krowiak  */
ap_test_queue(ap_qid_t qid,int tbit,struct ap_tapq_hwinfo * info)163211c06d8SHarald Freudenberger static inline struct ap_queue_status ap_test_queue(ap_qid_t qid, int tbit,
164d4c53ae8SHarald Freudenberger 						   struct ap_tapq_hwinfo *info)
165f1b0a434SHarald Freudenberger {
166f1b0a434SHarald Freudenberger 	if (tbit)
167f1b0a434SHarald Freudenberger 		qid |= 1UL << 23; /* set T bit*/
168f1b0a434SHarald Freudenberger 	return ap_tapq(qid, info);
169f1b0a434SHarald Freudenberger }
170e7fc5146STony Krowiak 
171f1b0a434SHarald Freudenberger /**
172f1b0a434SHarald Freudenberger  * ap_pqap_rapq(): Reset adjunct processor queue.
173f1b0a434SHarald Freudenberger  * @qid: The AP queue number
1744bdf3c39SHarald Freudenberger  * @fbit: if != 0 set F bit
175f1b0a434SHarald Freudenberger  *
176f1b0a434SHarald Freudenberger  * Returns AP queue status structure.
177f1b0a434SHarald Freudenberger  */
ap_rapq(ap_qid_t qid,int fbit)1784bdf3c39SHarald Freudenberger static inline struct ap_queue_status ap_rapq(ap_qid_t qid, int fbit)
179f1b0a434SHarald Freudenberger {
180b9639b31SHeiko Carstens 	unsigned long reg0 = qid | (1UL << 24);  /* fc 1UL is RAPQ */
181ebf95e88SHarald Freudenberger 	union ap_queue_status_reg reg1;
182f1b0a434SHarald Freudenberger 
1834bdf3c39SHarald Freudenberger 	if (fbit)
1844bdf3c39SHarald Freudenberger 		reg0 |= 1UL << 22;
1854bdf3c39SHarald Freudenberger 
186f1b0a434SHarald Freudenberger 	asm volatile(
187b9639b31SHeiko Carstens 		"	lgr	0,%[reg0]\n"		/* qid arg into gr0 */
1882d6c0008SHeiko Carstens 		"	.insn	rre,0xb2af0000,0,0\n"	/* PQAP(RAPQ) */
189b9639b31SHeiko Carstens 		"	lgr	%[reg1],1\n"		/* gr1 (status) into reg1 */
190ebf95e88SHarald Freudenberger 		: [reg1] "=&d" (reg1.value)
191b9639b31SHeiko Carstens 		: [reg0] "d" (reg0)
192b9639b31SHeiko Carstens 		: "cc", "0", "1");
193ebf95e88SHarald Freudenberger 	return reg1.status;
194f1b0a434SHarald Freudenberger }
195f1b0a434SHarald Freudenberger 
196f1b0a434SHarald Freudenberger /**
197f1b0a434SHarald Freudenberger  * ap_pqap_zapq(): Reset and zeroize adjunct processor queue.
198f1b0a434SHarald Freudenberger  * @qid: The AP queue number
1994bdf3c39SHarald Freudenberger  * @fbit: if != 0 set F bit
200f1b0a434SHarald Freudenberger  *
201f1b0a434SHarald Freudenberger  * Returns AP queue status structure.
202f1b0a434SHarald Freudenberger  */
ap_zapq(ap_qid_t qid,int fbit)2034bdf3c39SHarald Freudenberger static inline struct ap_queue_status ap_zapq(ap_qid_t qid, int fbit)
204f1b0a434SHarald Freudenberger {
205b9639b31SHeiko Carstens 	unsigned long reg0 = qid | (2UL << 24);  /* fc 2UL is ZAPQ */
206ebf95e88SHarald Freudenberger 	union ap_queue_status_reg reg1;
207f1b0a434SHarald Freudenberger 
2084bdf3c39SHarald Freudenberger 	if (fbit)
2094bdf3c39SHarald Freudenberger 		reg0 |= 1UL << 22;
2104bdf3c39SHarald Freudenberger 
211f1b0a434SHarald Freudenberger 	asm volatile(
212b9639b31SHeiko Carstens 		"	lgr	0,%[reg0]\n"		/* qid arg into gr0 */
2132d6c0008SHeiko Carstens 		"	.insn	rre,0xb2af0000,0,0\n"	/* PQAP(ZAPQ) */
214b9639b31SHeiko Carstens 		"	lgr	%[reg1],1\n"		/* gr1 (status) into reg1 */
215ebf95e88SHarald Freudenberger 		: [reg1] "=&d" (reg1.value)
216b9639b31SHeiko Carstens 		: [reg0] "d" (reg0)
217b9639b31SHeiko Carstens 		: "cc", "0", "1");
218ebf95e88SHarald Freudenberger 	return reg1.status;
219f1b0a434SHarald Freudenberger }
220f1b0a434SHarald Freudenberger 
221f1b0a434SHarald Freudenberger /**
222f1b0a434SHarald Freudenberger  * struct ap_config_info - convenience struct for AP crypto
223f1b0a434SHarald Freudenberger  * config info as returned by the ap_qci() function.
224f1b0a434SHarald Freudenberger  */
225050349b5SHarald Freudenberger struct ap_config_info {
226*8dec9cb9SHolger Dengler 	union {
227*8dec9cb9SHolger Dengler 		unsigned int flags;
228*8dec9cb9SHolger Dengler 		struct {
229050349b5SHarald Freudenberger 			unsigned int apsc	 : 1;	/* S bit */
230050349b5SHarald Freudenberger 			unsigned int apxa	 : 1;	/* N bit */
231050349b5SHarald Freudenberger 			unsigned int qact	 : 1;	/* C bit */
232050349b5SHarald Freudenberger 			unsigned int rc8a	 : 1;	/* R bit */
233f6047040SHarald Freudenberger 			unsigned int		 : 4;
234f6047040SHarald Freudenberger 			unsigned int apsb	 : 1;	/* B bit */
235f6047040SHarald Freudenberger 			unsigned int		 : 23;
236*8dec9cb9SHolger Dengler 		};
237*8dec9cb9SHolger Dengler 	};
238f6047040SHarald Freudenberger 	unsigned char na;		/* max # of APs - 1 */
239f6047040SHarald Freudenberger 	unsigned char nd;		/* max # of Domains - 1 */
240f6047040SHarald Freudenberger 	unsigned char _reserved0[10];
241050349b5SHarald Freudenberger 	unsigned int apm[8];		/* AP ID mask */
2427379e652SHarald Freudenberger 	unsigned int aqm[8];		/* AP (usage) queue mask */
2437379e652SHarald Freudenberger 	unsigned int adm[8];		/* AP (control) domain mask */
244f6047040SHarald Freudenberger 	unsigned char _reserved1[16];
245050349b5SHarald Freudenberger } __aligned(8);
246050349b5SHarald Freudenberger 
247f1b0a434SHarald Freudenberger /**
248f1b0a434SHarald Freudenberger  * ap_qci(): Get AP configuration data
249050349b5SHarald Freudenberger  *
250f1b0a434SHarald Freudenberger  * Returns 0 on success, or -EOPNOTSUPP.
251050349b5SHarald Freudenberger  */
ap_qci(struct ap_config_info * config)252f1b0a434SHarald Freudenberger static inline int ap_qci(struct ap_config_info *config)
253f1b0a434SHarald Freudenberger {
254b9639b31SHeiko Carstens 	unsigned long reg0 = 4UL << 24;  /* fc 4UL is QCI */
255b9639b31SHeiko Carstens 	unsigned long reg1 = -EOPNOTSUPP;
256b9639b31SHeiko Carstens 	struct ap_config_info *reg2 = config;
257f1b0a434SHarald Freudenberger 
258f1b0a434SHarald Freudenberger 	asm volatile(
259b9639b31SHeiko Carstens 		"	lgr	0,%[reg0]\n"		/* QCI fc into gr0 */
260b9639b31SHeiko Carstens 		"	lgr	2,%[reg2]\n"		/* ptr to config into gr2 */
2612d6c0008SHeiko Carstens 		"	.insn	rre,0xb2af0000,0,0\n"	/* PQAP(QCI) */
262b9639b31SHeiko Carstens 		"0:	la	%[reg1],0\n"		/* good case, QCI fc available */
263f1b0a434SHarald Freudenberger 		"1:\n"
264f1b0a434SHarald Freudenberger 		EX_TABLE(0b, 1b)
265b9639b31SHeiko Carstens 		: [reg1] "+&d" (reg1)
266b9639b31SHeiko Carstens 		: [reg0] "d" (reg0), [reg2] "d" (reg2)
267b9639b31SHeiko Carstens 		: "cc", "memory", "0", "2");
268f1b0a434SHarald Freudenberger 
269f1b0a434SHarald Freudenberger 	return reg1;
270f1b0a434SHarald Freudenberger }
271050349b5SHarald Freudenberger 
27246fde9a9SHarald Freudenberger /*
27346fde9a9SHarald Freudenberger  * struct ap_qirq_ctrl - convenient struct for easy invocation
274f1b0a434SHarald Freudenberger  * of the ap_aqic() function. This struct is passed as GR1
275f1b0a434SHarald Freudenberger  * parameter to the PQAP(AQIC) instruction. For details please
276f1b0a434SHarald Freudenberger  * see the AR documentation.
27746fde9a9SHarald Freudenberger  */
278ebf95e88SHarald Freudenberger union ap_qirq_ctrl {
279ebf95e88SHarald Freudenberger 	unsigned long value;
280ebf95e88SHarald Freudenberger 	struct {
281ebf95e88SHarald Freudenberger 		unsigned int	   : 8;
28246fde9a9SHarald Freudenberger 		unsigned int zone  : 8;	/* zone info */
28346fde9a9SHarald Freudenberger 		unsigned int ir	   : 1;	/* ir flag: enable (1) or disable (0) irq */
284ebf95e88SHarald Freudenberger 		unsigned int	   : 4;
28546fde9a9SHarald Freudenberger 		unsigned int gisc  : 3;	/* guest isc field */
286ebf95e88SHarald Freudenberger 		unsigned int	   : 6;
28746fde9a9SHarald Freudenberger 		unsigned int gf	   : 2;	/* gisa format */
288ebf95e88SHarald Freudenberger 		unsigned int	   : 1;
28946fde9a9SHarald Freudenberger 		unsigned int gisa  : 27;	/* gisa origin */
290ebf95e88SHarald Freudenberger 		unsigned int	   : 1;
29146fde9a9SHarald Freudenberger 		unsigned int isc   : 3;	/* irq sub class */
29246fde9a9SHarald Freudenberger 	};
293ebf95e88SHarald Freudenberger };
29446fde9a9SHarald Freudenberger 
29546fde9a9SHarald Freudenberger /**
296f1b0a434SHarald Freudenberger  * ap_aqic(): Control interruption for a specific AP.
29746fde9a9SHarald Freudenberger  * @qid: The AP queue number
298f1b0a434SHarald Freudenberger  * @qirqctrl: struct ap_qirq_ctrl (64 bit value)
29910e19d49SNicolin Chen  * @pa_ind: Physical address of the notification indicator byte
30046fde9a9SHarald Freudenberger  *
30146fde9a9SHarald Freudenberger  * Returns AP queue status.
30246fde9a9SHarald Freudenberger  */
ap_aqic(ap_qid_t qid,union ap_qirq_ctrl qirqctrl,phys_addr_t pa_ind)303f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_aqic(ap_qid_t qid,
304ebf95e88SHarald Freudenberger 					     union ap_qirq_ctrl qirqctrl,
30510e19d49SNicolin Chen 					     phys_addr_t pa_ind)
306f1b0a434SHarald Freudenberger {
307b9639b31SHeiko Carstens 	unsigned long reg0 = qid | (3UL << 24);  /* fc 3UL is AQIC */
308ebf95e88SHarald Freudenberger 	union ap_queue_status_reg reg1;
30910e19d49SNicolin Chen 	unsigned long reg2 = pa_ind;
310f1b0a434SHarald Freudenberger 
311ebf95e88SHarald Freudenberger 	reg1.value = qirqctrl.value;
312159491f3SHarald Freudenberger 
313f1b0a434SHarald Freudenberger 	asm volatile(
314b9639b31SHeiko Carstens 		"	lgr	0,%[reg0]\n"		/* qid param into gr0 */
315b9639b31SHeiko Carstens 		"	lgr	1,%[reg1]\n"		/* irq ctrl into gr1 */
316b9639b31SHeiko Carstens 		"	lgr	2,%[reg2]\n"		/* ni addr into gr2 */
3172d6c0008SHeiko Carstens 		"	.insn	rre,0xb2af0000,0,0\n"	/* PQAP(AQIC) */
318b9639b31SHeiko Carstens 		"	lgr	%[reg1],1\n"		/* gr1 (status) into reg1 */
319ebf95e88SHarald Freudenberger 		: [reg1] "+&d" (reg1.value)
320b9639b31SHeiko Carstens 		: [reg0] "d" (reg0), [reg2] "d" (reg2)
321394740d7SHalil Pasic 		: "cc", "memory", "0", "1", "2");
322159491f3SHarald Freudenberger 
323159491f3SHarald Freudenberger 	return reg1.status;
324f1b0a434SHarald Freudenberger }
325f1b0a434SHarald Freudenberger 
326f1b0a434SHarald Freudenberger /*
327f1b0a434SHarald Freudenberger  * union ap_qact_ap_info - used together with the
328f1b0a434SHarald Freudenberger  * ap_aqic() function to provide a convenient way
329f1b0a434SHarald Freudenberger  * to handle the ap info needed by the qact function.
330f1b0a434SHarald Freudenberger  */
331f1b0a434SHarald Freudenberger union ap_qact_ap_info {
332f1b0a434SHarald Freudenberger 	unsigned long val;
333f1b0a434SHarald Freudenberger 	struct {
334f1b0a434SHarald Freudenberger 		unsigned int	  : 3;
335f1b0a434SHarald Freudenberger 		unsigned int mode : 3;
336f1b0a434SHarald Freudenberger 		unsigned int	  : 26;
337f1b0a434SHarald Freudenberger 		unsigned int cat  : 8;
338f1b0a434SHarald Freudenberger 		unsigned int	  : 8;
339f1b0a434SHarald Freudenberger 		unsigned char ver[2];
340f1b0a434SHarald Freudenberger 	};
341f1b0a434SHarald Freudenberger };
342f1b0a434SHarald Freudenberger 
343f1b0a434SHarald Freudenberger /**
344cada938aSHeiko Carstens  * ap_qact(): Query AP compatibility type.
345f1b0a434SHarald Freudenberger  * @qid: The AP queue number
346f1b0a434SHarald Freudenberger  * @apinfo: On input the info about the AP queue. On output the
347f1b0a434SHarald Freudenberger  *	    alternate AP queue info provided by the qact function
348f1b0a434SHarald Freudenberger  *	    in GR2 is stored in.
349f1b0a434SHarald Freudenberger  *
350f1b0a434SHarald Freudenberger  * Returns AP queue status. Check response_code field for failures.
351f1b0a434SHarald Freudenberger  */
ap_qact(ap_qid_t qid,int ifbit,union ap_qact_ap_info * apinfo)352f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_qact(ap_qid_t qid, int ifbit,
353f1b0a434SHarald Freudenberger 					     union ap_qact_ap_info *apinfo)
354f1b0a434SHarald Freudenberger {
355b9639b31SHeiko Carstens 	unsigned long reg0 = qid | (5UL << 24) | ((ifbit & 0x01) << 22);
356ebf95e88SHarald Freudenberger 	union ap_queue_status_reg reg1;
357b9639b31SHeiko Carstens 	unsigned long reg2;
358f1b0a434SHarald Freudenberger 
359159491f3SHarald Freudenberger 	reg1.value = apinfo->val;
360159491f3SHarald Freudenberger 
361f1b0a434SHarald Freudenberger 	asm volatile(
362b9639b31SHeiko Carstens 		"	lgr	0,%[reg0]\n"		/* qid param into gr0 */
363b9639b31SHeiko Carstens 		"	lgr	1,%[reg1]\n"		/* qact in info into gr1 */
3642d6c0008SHeiko Carstens 		"	.insn	rre,0xb2af0000,0,0\n"	/* PQAP(QACT) */
365b9639b31SHeiko Carstens 		"	lgr	%[reg1],1\n"		/* gr1 (status) into reg1 */
366b9639b31SHeiko Carstens 		"	lgr	%[reg2],2\n"		/* qact out info into reg2 */
367ebf95e88SHarald Freudenberger 		: [reg1] "+&d" (reg1.value), [reg2] "=&d" (reg2)
368b9639b31SHeiko Carstens 		: [reg0] "d" (reg0)
369b9639b31SHeiko Carstens 		: "cc", "0", "1", "2");
370f1b0a434SHarald Freudenberger 	apinfo->val = reg2;
371159491f3SHarald Freudenberger 	return reg1.status;
372f1b0a434SHarald Freudenberger }
373f1b0a434SHarald Freudenberger 
374c81cf436SHarald Freudenberger /*
375c81cf436SHarald Freudenberger  * ap_bapq(): SE bind AP queue.
376c81cf436SHarald Freudenberger  * @qid: The AP queue number
377c81cf436SHarald Freudenberger  *
378c81cf436SHarald Freudenberger  * Returns AP queue status structure.
379c81cf436SHarald Freudenberger  *
380c81cf436SHarald Freudenberger  * Invoking this function in a non-SE environment
381c81cf436SHarald Freudenberger  * may case a specification exception.
382c81cf436SHarald Freudenberger  */
ap_bapq(ap_qid_t qid)383c81cf436SHarald Freudenberger static inline struct ap_queue_status ap_bapq(ap_qid_t qid)
384c81cf436SHarald Freudenberger {
385c81cf436SHarald Freudenberger 	unsigned long reg0 = qid | (7UL << 24);  /* fc 7 is BAPQ */
386c81cf436SHarald Freudenberger 	union ap_queue_status_reg reg1;
387c81cf436SHarald Freudenberger 
388c81cf436SHarald Freudenberger 	asm volatile(
389c81cf436SHarald Freudenberger 		"	lgr	0,%[reg0]\n"		/* qid arg into gr0 */
390c81cf436SHarald Freudenberger 		"	.insn	rre,0xb2af0000,0,0\n"	/* PQAP(BAPQ) */
391c81cf436SHarald Freudenberger 		"	lgr	%[reg1],1\n"		/* gr1 (status) into reg1 */
392c81cf436SHarald Freudenberger 		: [reg1] "=&d" (reg1.value)
393c81cf436SHarald Freudenberger 		: [reg0] "d" (reg0)
394c81cf436SHarald Freudenberger 		: "cc", "0", "1");
395c81cf436SHarald Freudenberger 
396c81cf436SHarald Freudenberger 	return reg1.status;
397c81cf436SHarald Freudenberger }
398c81cf436SHarald Freudenberger 
399c81cf436SHarald Freudenberger /*
400c81cf436SHarald Freudenberger  * ap_aapq(): SE associate AP queue.
401c81cf436SHarald Freudenberger  * @qid: The AP queue number
402c81cf436SHarald Freudenberger  * @sec_idx: The secret index
403c81cf436SHarald Freudenberger  *
404c81cf436SHarald Freudenberger  * Returns AP queue status structure.
405c81cf436SHarald Freudenberger  *
406c81cf436SHarald Freudenberger  * Invoking this function in a non-SE environment
407c81cf436SHarald Freudenberger  * may case a specification exception.
408c81cf436SHarald Freudenberger  */
ap_aapq(ap_qid_t qid,unsigned int sec_idx)409c81cf436SHarald Freudenberger static inline struct ap_queue_status ap_aapq(ap_qid_t qid, unsigned int sec_idx)
410c81cf436SHarald Freudenberger {
411c81cf436SHarald Freudenberger 	unsigned long reg0 = qid | (8UL << 24);  /* fc 8 is AAPQ */
412c81cf436SHarald Freudenberger 	unsigned long reg2 = sec_idx;
413c81cf436SHarald Freudenberger 	union ap_queue_status_reg reg1;
414c81cf436SHarald Freudenberger 
415c81cf436SHarald Freudenberger 	asm volatile(
416c81cf436SHarald Freudenberger 		"	lgr	0,%[reg0]\n"		/* qid arg into gr0 */
417c81cf436SHarald Freudenberger 		"	lgr	2,%[reg2]\n"		/* secret index into gr2 */
418c81cf436SHarald Freudenberger 		"	.insn	rre,0xb2af0000,0,0\n"	/* PQAP(AAPQ) */
419c81cf436SHarald Freudenberger 		"	lgr	%[reg1],1\n"		/* gr1 (status) into reg1 */
420c81cf436SHarald Freudenberger 		: [reg1] "=&d" (reg1.value)
421c81cf436SHarald Freudenberger 		: [reg0] "d" (reg0), [reg2] "d" (reg2)
422c81cf436SHarald Freudenberger 		: "cc", "0", "1", "2");
423c81cf436SHarald Freudenberger 
424c81cf436SHarald Freudenberger 	return reg1.status;
425c81cf436SHarald Freudenberger }
426c81cf436SHarald Freudenberger 
427f1b0a434SHarald Freudenberger /**
428f1b0a434SHarald Freudenberger  * ap_nqap(): Send message to adjunct processor queue.
429f1b0a434SHarald Freudenberger  * @qid: The AP queue number
430f1b0a434SHarald Freudenberger  * @psmid: The program supplied message identifier
431f1b0a434SHarald Freudenberger  * @msg: The message text
432f1b0a434SHarald Freudenberger  * @length: The message length
433f1b0a434SHarald Freudenberger  *
434f1b0a434SHarald Freudenberger  * Returns AP queue status structure.
435f1b0a434SHarald Freudenberger  * Condition code 1 on NQAP can't happen because the L bit is 1.
436f1b0a434SHarald Freudenberger  * Condition code 2 on NQAP also means the send is incomplete,
437f1b0a434SHarald Freudenberger  * because a segment boundary was reached. The NQAP is repeated.
438f1b0a434SHarald Freudenberger  */
ap_nqap(ap_qid_t qid,unsigned long long psmid,void * msg,size_t length)439f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_nqap(ap_qid_t qid,
440f1b0a434SHarald Freudenberger 					     unsigned long long psmid,
441f1b0a434SHarald Freudenberger 					     void *msg, size_t length)
442f1b0a434SHarald Freudenberger {
443b9639b31SHeiko Carstens 	unsigned long reg0 = qid | 0x40000000UL;  /* 0x4... is last msg part */
444b9639b31SHeiko Carstens 	union register_pair nqap_r1, nqap_r2;
445ebf95e88SHarald Freudenberger 	union ap_queue_status_reg reg1;
446b9639b31SHeiko Carstens 
447b9639b31SHeiko Carstens 	nqap_r1.even = (unsigned int)(psmid >> 32);
448b9639b31SHeiko Carstens 	nqap_r1.odd  = psmid & 0xffffffff;
449b9639b31SHeiko Carstens 	nqap_r2.even = (unsigned long)msg;
450b9639b31SHeiko Carstens 	nqap_r2.odd  = (unsigned long)length;
451f1b0a434SHarald Freudenberger 
452f1b0a434SHarald Freudenberger 	asm volatile (
453b9639b31SHeiko Carstens 		"	lgr	0,%[reg0]\n"  /* qid param in gr0 */
454b9639b31SHeiko Carstens 		"0:	.insn	rre,0xb2ad0000,%[nqap_r1],%[nqap_r2]\n"
455b9639b31SHeiko Carstens 		"	brc	2,0b\n"       /* handle partial completion */
456b9639b31SHeiko Carstens 		"	lgr	%[reg1],1\n"  /* gr1 (status) into reg1 */
457ebf95e88SHarald Freudenberger 		: [reg0] "+&d" (reg0), [reg1] "=&d" (reg1.value),
458b9639b31SHeiko Carstens 		  [nqap_r2] "+&d" (nqap_r2.pair)
459b9639b31SHeiko Carstens 		: [nqap_r1] "d" (nqap_r1.pair)
460b9639b31SHeiko Carstens 		: "cc", "memory", "0", "1");
461ebf95e88SHarald Freudenberger 	return reg1.status;
462f1b0a434SHarald Freudenberger }
463f1b0a434SHarald Freudenberger 
464f1b0a434SHarald Freudenberger /**
465f1b0a434SHarald Freudenberger  * ap_dqap(): Receive message from adjunct processor queue.
466f1b0a434SHarald Freudenberger  * @qid: The AP queue number
467f1b0a434SHarald Freudenberger  * @psmid: Pointer to program supplied message identifier
4688794c596SHarald Freudenberger  * @msg: Pointer to message buffer
4698794c596SHarald Freudenberger  * @msglen: Message buffer size
4708794c596SHarald Freudenberger  * @length: Pointer to length of actually written bytes
4718794c596SHarald Freudenberger  * @reslength: Residual length on return
4728794c596SHarald Freudenberger  * @resgr0: input: gr0 value (only used if != 0), output: residual gr0 content
473f1b0a434SHarald Freudenberger  *
474f1b0a434SHarald Freudenberger  * Returns AP queue status structure.
475f1b0a434SHarald Freudenberger  * Condition code 1 on DQAP means the receive has taken place
476f1b0a434SHarald Freudenberger  * but only partially.	The response is incomplete, hence the
477f1b0a434SHarald Freudenberger  * DQAP is repeated.
478f1b0a434SHarald Freudenberger  * Condition code 2 on DQAP also means the receive is incomplete,
479f1b0a434SHarald Freudenberger  * this time because a segment boundary was reached. Again, the
480f1b0a434SHarald Freudenberger  * DQAP is repeated.
481f1b0a434SHarald Freudenberger  * Note that gpr2 is used by the DQAP instruction to keep track of
482f1b0a434SHarald Freudenberger  * any 'residual' length, in case the instruction gets interrupted.
483f1b0a434SHarald Freudenberger  * Hence it gets zeroed before the instruction.
4841f0d22deSHarald Freudenberger  * If the message does not fit into the buffer, this function will
4851f0d22deSHarald Freudenberger  * return with a truncated message and the reply in the firmware queue
4861f0d22deSHarald Freudenberger  * is not removed. This is indicated to the caller with an
4871f0d22deSHarald Freudenberger  * ap_queue_status response_code value of all bits on (0xFF) and (if
4881f0d22deSHarald Freudenberger  * the reslength ptr is given) the remaining length is stored in
4891f0d22deSHarald Freudenberger  * *reslength and (if the resgr0 ptr is given) the updated gr0 value
4901f0d22deSHarald Freudenberger  * for further processing of this msg entry is stored in *resgr0. The
4911f0d22deSHarald Freudenberger  * caller needs to detect this situation and should invoke ap_dqap
4921f0d22deSHarald Freudenberger  * with a valid resgr0 ptr and a value in there != 0 to indicate that
4931f0d22deSHarald Freudenberger  * *resgr0 is to be used instead of qid to further process this entry.
494f1b0a434SHarald Freudenberger  */
ap_dqap(ap_qid_t qid,unsigned long * psmid,void * msg,size_t msglen,size_t * length,size_t * reslength,unsigned long * resgr0)495f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_dqap(ap_qid_t qid,
496003d248fSHarald Freudenberger 					     unsigned long *psmid,
4978794c596SHarald Freudenberger 					     void *msg, size_t msglen,
4988794c596SHarald Freudenberger 					     size_t *length,
4991f0d22deSHarald Freudenberger 					     size_t *reslength,
5001f0d22deSHarald Freudenberger 					     unsigned long *resgr0)
501f1b0a434SHarald Freudenberger {
5024516f355SHarald Freudenberger 	unsigned long reg0 = resgr0 && *resgr0 ? *resgr0 : qid | 0x80000000UL;
503ebf95e88SHarald Freudenberger 	union ap_queue_status_reg reg1;
5044516f355SHarald Freudenberger 	unsigned long reg2;
5054516f355SHarald Freudenberger 	union register_pair rp1, rp2;
5064516f355SHarald Freudenberger 
5074516f355SHarald Freudenberger 	rp1.even = 0UL;
5084516f355SHarald Freudenberger 	rp1.odd  = 0UL;
5094516f355SHarald Freudenberger 	rp2.even = (unsigned long)msg;
5108794c596SHarald Freudenberger 	rp2.odd  = (unsigned long)msglen;
511f1b0a434SHarald Freudenberger 
512f1b0a434SHarald Freudenberger 	asm volatile(
5134516f355SHarald Freudenberger 		"	lgr	0,%[reg0]\n"   /* qid param into gr0 */
5144516f355SHarald Freudenberger 		"	lghi	2,0\n"	       /* 0 into gr2 (res length) */
5154516f355SHarald Freudenberger 		"0:	ltgr	%N[rp2],%N[rp2]\n" /* check buf len */
5164516f355SHarald Freudenberger 		"	jz	2f\n"	       /* go out if buf len is 0 */
5174516f355SHarald Freudenberger 		"1:	.insn	rre,0xb2ae0000,%[rp1],%[rp2]\n"
5184516f355SHarald Freudenberger 		"	brc	6,0b\n"        /* handle partial complete */
5194516f355SHarald Freudenberger 		"2:	lgr	%[reg0],0\n"   /* gr0 (qid + info) into reg0 */
5204516f355SHarald Freudenberger 		"	lgr	%[reg1],1\n"   /* gr1 (status) into reg1 */
5214516f355SHarald Freudenberger 		"	lgr	%[reg2],2\n"   /* gr2 (res length) into reg2 */
522ebf95e88SHarald Freudenberger 		: [reg0] "+&d" (reg0), [reg1] "=&d" (reg1.value),
523ebf95e88SHarald Freudenberger 		  [reg2] "=&d" (reg2), [rp1] "+&d" (rp1.pair),
524ebf95e88SHarald Freudenberger 		  [rp2] "+&d" (rp2.pair)
5254516f355SHarald Freudenberger 		:
5264516f355SHarald Freudenberger 		: "cc", "memory", "0", "1", "2");
5271f0d22deSHarald Freudenberger 
5281f0d22deSHarald Freudenberger 	if (reslength)
5291f0d22deSHarald Freudenberger 		*reslength = reg2;
5304516f355SHarald Freudenberger 	if (reg2 != 0 && rp2.odd == 0) {
5311f0d22deSHarald Freudenberger 		/*
5321f0d22deSHarald Freudenberger 		 * Partially complete, status in gr1 is not set.
5331f0d22deSHarald Freudenberger 		 * Signal the caller that this dqap is only partially received
5341f0d22deSHarald Freudenberger 		 * with a special status response code 0xFF and *resgr0 updated
5351f0d22deSHarald Freudenberger 		 */
536ebf95e88SHarald Freudenberger 		reg1.status.response_code = 0xFF;
5371f0d22deSHarald Freudenberger 		if (resgr0)
5381f0d22deSHarald Freudenberger 			*resgr0 = reg0;
5391f0d22deSHarald Freudenberger 	} else {
540003d248fSHarald Freudenberger 		*psmid = (rp1.even << 32) + rp1.odd;
5411f0d22deSHarald Freudenberger 		if (resgr0)
5421f0d22deSHarald Freudenberger 			*resgr0 = 0;
5431f0d22deSHarald Freudenberger 	}
5441f0d22deSHarald Freudenberger 
5458794c596SHarald Freudenberger 	/* update *length with the nr of bytes stored into the msg buffer */
5468794c596SHarald Freudenberger 	if (length)
5478794c596SHarald Freudenberger 		*length = msglen - rp2.odd;
5488794c596SHarald Freudenberger 
549ebf95e88SHarald Freudenberger 	return reg1.status;
550f1b0a434SHarald Freudenberger }
55146fde9a9SHarald Freudenberger 
552e7fc5146STony Krowiak #endif /* _ASM_S390_AP_H_ */
553