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; 46*2d72eaf0SHarald Freudenberger unsigned int : 3; 47*2d72eaf0SHarald Freudenberger unsigned int async : 1; 48e7fc5146STony Krowiak unsigned int irq_enabled : 1; 49e7fc5146STony Krowiak unsigned int response_code : 8; 50*2d72eaf0SHarald 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 */ 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 */ 91211c06d8SHarald Freudenberger struct ap_tapq_gr2 { 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 { 99211c06d8SHarald Freudenberger unsigned int s : 1; /* APSC */ 100211c06d8SHarald Freudenberger unsigned int m : 1; /* AP4KM */ 101211c06d8SHarald Freudenberger unsigned int c : 1; /* AP4KC */ 102211c06d8SHarald Freudenberger unsigned int mode : 3; 103211c06d8SHarald Freudenberger unsigned int n : 1; /* APXA */ 104211c06d8SHarald Freudenberger unsigned int : 1; 105211c06d8SHarald Freudenberger unsigned int class : 8; 106211c06d8SHarald Freudenberger unsigned int bs : 2; /* SE bind/assoc */ 107211c06d8SHarald Freudenberger unsigned int : 14; 108211c06d8SHarald Freudenberger unsigned int at : 8; /* ap type */ 109211c06d8SHarald Freudenberger unsigned int nd : 8; /* nr of domains */ 110211c06d8SHarald Freudenberger unsigned int : 4; 111211c06d8SHarald Freudenberger unsigned int ml : 4; /* apxl ml */ 112211c06d8SHarald Freudenberger unsigned int : 4; 113211c06d8SHarald Freudenberger unsigned int qd : 4; /* queue depth */ 114211c06d8SHarald Freudenberger }; 115211c06d8SHarald Freudenberger }; 116211c06d8SHarald Freudenberger }; 117211c06d8SHarald Freudenberger 118*2d72eaf0SHarald Freudenberger /* 119*2d72eaf0SHarald Freudenberger * Convenience defines to be used with the bs field from struct ap_tapq_gr2 120*2d72eaf0SHarald Freudenberger */ 121*2d72eaf0SHarald Freudenberger #define AP_BS_Q_USABLE 0 122*2d72eaf0SHarald Freudenberger #define AP_BS_Q_USABLE_NO_SECURE_KEY 1 123*2d72eaf0SHarald Freudenberger #define AP_BS_Q_AVAIL_FOR_BINDING 2 124*2d72eaf0SHarald Freudenberger #define AP_BS_Q_UNUSABLE 3 125*2d72eaf0SHarald Freudenberger 126f1b0a434SHarald Freudenberger /** 127f1b0a434SHarald Freudenberger * ap_tapq(): Test adjunct processor queue. 128f1b0a434SHarald Freudenberger * @qid: The AP queue number 129f1b0a434SHarald Freudenberger * @info: Pointer to queue descriptor 130f1b0a434SHarald Freudenberger * 131f1b0a434SHarald Freudenberger * Returns AP queue status structure. 132f1b0a434SHarald Freudenberger */ 133211c06d8SHarald Freudenberger static inline struct ap_queue_status ap_tapq(ap_qid_t qid, struct ap_tapq_gr2 *info) 134f1b0a434SHarald Freudenberger { 135ebf95e88SHarald Freudenberger union ap_queue_status_reg reg1; 136b9639b31SHeiko Carstens unsigned long reg2; 137f1b0a434SHarald Freudenberger 138b9639b31SHeiko Carstens asm volatile( 139b9639b31SHeiko Carstens " lgr 0,%[qid]\n" /* qid into gr0 */ 140b9639b31SHeiko Carstens " lghi 2,0\n" /* 0 into gr2 */ 1412d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(TAPQ) */ 142b9639b31SHeiko Carstens " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 143b9639b31SHeiko Carstens " lgr %[reg2],2\n" /* gr2 into reg2 */ 144ebf95e88SHarald Freudenberger : [reg1] "=&d" (reg1.value), [reg2] "=&d" (reg2) 145b9639b31SHeiko Carstens : [qid] "d" (qid) 146b9639b31SHeiko Carstens : "cc", "0", "1", "2"); 147f1b0a434SHarald Freudenberger if (info) 148211c06d8SHarald Freudenberger info->value = reg2; 149ebf95e88SHarald Freudenberger return reg1.status; 150f1b0a434SHarald Freudenberger } 151f1b0a434SHarald Freudenberger 152f1b0a434SHarald Freudenberger /** 153e7fc5146STony Krowiak * ap_test_queue(): Test adjunct processor queue. 154e7fc5146STony Krowiak * @qid: The AP queue number 155e7fc5146STony Krowiak * @tbit: Test facilities bit 156211c06d8SHarald Freudenberger * @info: Ptr to tapq gr2 struct 157e7fc5146STony Krowiak * 158e7fc5146STony Krowiak * Returns AP queue status structure. 159e7fc5146STony Krowiak */ 160211c06d8SHarald Freudenberger static inline struct ap_queue_status ap_test_queue(ap_qid_t qid, int tbit, 161211c06d8SHarald Freudenberger struct ap_tapq_gr2 *info) 162f1b0a434SHarald Freudenberger { 163f1b0a434SHarald Freudenberger if (tbit) 164f1b0a434SHarald Freudenberger qid |= 1UL << 23; /* set T bit*/ 165f1b0a434SHarald Freudenberger return ap_tapq(qid, info); 166f1b0a434SHarald Freudenberger } 167e7fc5146STony Krowiak 168f1b0a434SHarald Freudenberger /** 169f1b0a434SHarald Freudenberger * ap_pqap_rapq(): Reset adjunct processor queue. 170f1b0a434SHarald Freudenberger * @qid: The AP queue number 1714bdf3c39SHarald Freudenberger * @fbit: if != 0 set F bit 172f1b0a434SHarald Freudenberger * 173f1b0a434SHarald Freudenberger * Returns AP queue status structure. 174f1b0a434SHarald Freudenberger */ 1754bdf3c39SHarald Freudenberger static inline struct ap_queue_status ap_rapq(ap_qid_t qid, int fbit) 176f1b0a434SHarald Freudenberger { 177b9639b31SHeiko Carstens unsigned long reg0 = qid | (1UL << 24); /* fc 1UL is RAPQ */ 178ebf95e88SHarald Freudenberger union ap_queue_status_reg reg1; 179f1b0a434SHarald Freudenberger 1804bdf3c39SHarald Freudenberger if (fbit) 1814bdf3c39SHarald Freudenberger reg0 |= 1UL << 22; 1824bdf3c39SHarald Freudenberger 183f1b0a434SHarald Freudenberger asm volatile( 184b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* qid arg into gr0 */ 1852d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(RAPQ) */ 186b9639b31SHeiko Carstens " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 187ebf95e88SHarald Freudenberger : [reg1] "=&d" (reg1.value) 188b9639b31SHeiko Carstens : [reg0] "d" (reg0) 189b9639b31SHeiko Carstens : "cc", "0", "1"); 190ebf95e88SHarald Freudenberger return reg1.status; 191f1b0a434SHarald Freudenberger } 192f1b0a434SHarald Freudenberger 193f1b0a434SHarald Freudenberger /** 194f1b0a434SHarald Freudenberger * ap_pqap_zapq(): Reset and zeroize adjunct processor queue. 195f1b0a434SHarald Freudenberger * @qid: The AP queue number 1964bdf3c39SHarald Freudenberger * @fbit: if != 0 set F bit 197f1b0a434SHarald Freudenberger * 198f1b0a434SHarald Freudenberger * Returns AP queue status structure. 199f1b0a434SHarald Freudenberger */ 2004bdf3c39SHarald Freudenberger static inline struct ap_queue_status ap_zapq(ap_qid_t qid, int fbit) 201f1b0a434SHarald Freudenberger { 202b9639b31SHeiko Carstens unsigned long reg0 = qid | (2UL << 24); /* fc 2UL is ZAPQ */ 203ebf95e88SHarald Freudenberger union ap_queue_status_reg reg1; 204f1b0a434SHarald Freudenberger 2054bdf3c39SHarald Freudenberger if (fbit) 2064bdf3c39SHarald Freudenberger reg0 |= 1UL << 22; 2074bdf3c39SHarald Freudenberger 208f1b0a434SHarald Freudenberger asm volatile( 209b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* qid arg into gr0 */ 2102d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(ZAPQ) */ 211b9639b31SHeiko Carstens " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 212ebf95e88SHarald Freudenberger : [reg1] "=&d" (reg1.value) 213b9639b31SHeiko Carstens : [reg0] "d" (reg0) 214b9639b31SHeiko Carstens : "cc", "0", "1"); 215ebf95e88SHarald Freudenberger return reg1.status; 216f1b0a434SHarald Freudenberger } 217f1b0a434SHarald Freudenberger 218f1b0a434SHarald Freudenberger /** 219f1b0a434SHarald Freudenberger * struct ap_config_info - convenience struct for AP crypto 220f1b0a434SHarald Freudenberger * config info as returned by the ap_qci() function. 221f1b0a434SHarald Freudenberger */ 222050349b5SHarald Freudenberger struct ap_config_info { 223050349b5SHarald Freudenberger unsigned int apsc : 1; /* S bit */ 224050349b5SHarald Freudenberger unsigned int apxa : 1; /* N bit */ 225050349b5SHarald Freudenberger unsigned int qact : 1; /* C bit */ 226050349b5SHarald Freudenberger unsigned int rc8a : 1; /* R bit */ 227f6047040SHarald Freudenberger unsigned int : 4; 228f6047040SHarald Freudenberger unsigned int apsb : 1; /* B bit */ 229f6047040SHarald Freudenberger unsigned int : 23; 230f6047040SHarald Freudenberger unsigned char na; /* max # of APs - 1 */ 231f6047040SHarald Freudenberger unsigned char nd; /* max # of Domains - 1 */ 232f6047040SHarald Freudenberger unsigned char _reserved0[10]; 233050349b5SHarald Freudenberger unsigned int apm[8]; /* AP ID mask */ 2347379e652SHarald Freudenberger unsigned int aqm[8]; /* AP (usage) queue mask */ 2357379e652SHarald Freudenberger unsigned int adm[8]; /* AP (control) domain mask */ 236f6047040SHarald Freudenberger unsigned char _reserved1[16]; 237050349b5SHarald Freudenberger } __aligned(8); 238050349b5SHarald Freudenberger 239f1b0a434SHarald Freudenberger /** 240f1b0a434SHarald Freudenberger * ap_qci(): Get AP configuration data 241050349b5SHarald Freudenberger * 242f1b0a434SHarald Freudenberger * Returns 0 on success, or -EOPNOTSUPP. 243050349b5SHarald Freudenberger */ 244f1b0a434SHarald Freudenberger static inline int ap_qci(struct ap_config_info *config) 245f1b0a434SHarald Freudenberger { 246b9639b31SHeiko Carstens unsigned long reg0 = 4UL << 24; /* fc 4UL is QCI */ 247b9639b31SHeiko Carstens unsigned long reg1 = -EOPNOTSUPP; 248b9639b31SHeiko Carstens struct ap_config_info *reg2 = config; 249f1b0a434SHarald Freudenberger 250f1b0a434SHarald Freudenberger asm volatile( 251b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* QCI fc into gr0 */ 252b9639b31SHeiko Carstens " lgr 2,%[reg2]\n" /* ptr to config into gr2 */ 2532d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(QCI) */ 254b9639b31SHeiko Carstens "0: la %[reg1],0\n" /* good case, QCI fc available */ 255f1b0a434SHarald Freudenberger "1:\n" 256f1b0a434SHarald Freudenberger EX_TABLE(0b, 1b) 257b9639b31SHeiko Carstens : [reg1] "+&d" (reg1) 258b9639b31SHeiko Carstens : [reg0] "d" (reg0), [reg2] "d" (reg2) 259b9639b31SHeiko Carstens : "cc", "memory", "0", "2"); 260f1b0a434SHarald Freudenberger 261f1b0a434SHarald Freudenberger return reg1; 262f1b0a434SHarald Freudenberger } 263050349b5SHarald Freudenberger 26446fde9a9SHarald Freudenberger /* 26546fde9a9SHarald Freudenberger * struct ap_qirq_ctrl - convenient struct for easy invocation 266f1b0a434SHarald Freudenberger * of the ap_aqic() function. This struct is passed as GR1 267f1b0a434SHarald Freudenberger * parameter to the PQAP(AQIC) instruction. For details please 268f1b0a434SHarald Freudenberger * see the AR documentation. 26946fde9a9SHarald Freudenberger */ 270ebf95e88SHarald Freudenberger union ap_qirq_ctrl { 271ebf95e88SHarald Freudenberger unsigned long value; 272ebf95e88SHarald Freudenberger struct { 273ebf95e88SHarald Freudenberger unsigned int : 8; 27446fde9a9SHarald Freudenberger unsigned int zone : 8; /* zone info */ 27546fde9a9SHarald Freudenberger unsigned int ir : 1; /* ir flag: enable (1) or disable (0) irq */ 276ebf95e88SHarald Freudenberger unsigned int : 4; 27746fde9a9SHarald Freudenberger unsigned int gisc : 3; /* guest isc field */ 278ebf95e88SHarald Freudenberger unsigned int : 6; 27946fde9a9SHarald Freudenberger unsigned int gf : 2; /* gisa format */ 280ebf95e88SHarald Freudenberger unsigned int : 1; 28146fde9a9SHarald Freudenberger unsigned int gisa : 27; /* gisa origin */ 282ebf95e88SHarald Freudenberger unsigned int : 1; 28346fde9a9SHarald Freudenberger unsigned int isc : 3; /* irq sub class */ 28446fde9a9SHarald Freudenberger }; 285ebf95e88SHarald Freudenberger }; 28646fde9a9SHarald Freudenberger 28746fde9a9SHarald Freudenberger /** 288f1b0a434SHarald Freudenberger * ap_aqic(): Control interruption for a specific AP. 28946fde9a9SHarald Freudenberger * @qid: The AP queue number 290f1b0a434SHarald Freudenberger * @qirqctrl: struct ap_qirq_ctrl (64 bit value) 29110e19d49SNicolin Chen * @pa_ind: Physical address of the notification indicator byte 29246fde9a9SHarald Freudenberger * 29346fde9a9SHarald Freudenberger * Returns AP queue status. 29446fde9a9SHarald Freudenberger */ 295f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_aqic(ap_qid_t qid, 296ebf95e88SHarald Freudenberger union ap_qirq_ctrl qirqctrl, 29710e19d49SNicolin Chen phys_addr_t pa_ind) 298f1b0a434SHarald Freudenberger { 299b9639b31SHeiko Carstens unsigned long reg0 = qid | (3UL << 24); /* fc 3UL is AQIC */ 300ebf95e88SHarald Freudenberger union ap_queue_status_reg reg1; 30110e19d49SNicolin Chen unsigned long reg2 = pa_ind; 302f1b0a434SHarald Freudenberger 303ebf95e88SHarald Freudenberger reg1.value = qirqctrl.value; 304159491f3SHarald Freudenberger 305f1b0a434SHarald Freudenberger asm volatile( 306b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* qid param into gr0 */ 307b9639b31SHeiko Carstens " lgr 1,%[reg1]\n" /* irq ctrl into gr1 */ 308b9639b31SHeiko Carstens " lgr 2,%[reg2]\n" /* ni addr into gr2 */ 3092d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(AQIC) */ 310b9639b31SHeiko Carstens " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 311ebf95e88SHarald Freudenberger : [reg1] "+&d" (reg1.value) 312b9639b31SHeiko Carstens : [reg0] "d" (reg0), [reg2] "d" (reg2) 313394740d7SHalil Pasic : "cc", "memory", "0", "1", "2"); 314159491f3SHarald Freudenberger 315159491f3SHarald Freudenberger return reg1.status; 316f1b0a434SHarald Freudenberger } 317f1b0a434SHarald Freudenberger 318f1b0a434SHarald Freudenberger /* 319f1b0a434SHarald Freudenberger * union ap_qact_ap_info - used together with the 320f1b0a434SHarald Freudenberger * ap_aqic() function to provide a convenient way 321f1b0a434SHarald Freudenberger * to handle the ap info needed by the qact function. 322f1b0a434SHarald Freudenberger */ 323f1b0a434SHarald Freudenberger union ap_qact_ap_info { 324f1b0a434SHarald Freudenberger unsigned long val; 325f1b0a434SHarald Freudenberger struct { 326f1b0a434SHarald Freudenberger unsigned int : 3; 327f1b0a434SHarald Freudenberger unsigned int mode : 3; 328f1b0a434SHarald Freudenberger unsigned int : 26; 329f1b0a434SHarald Freudenberger unsigned int cat : 8; 330f1b0a434SHarald Freudenberger unsigned int : 8; 331f1b0a434SHarald Freudenberger unsigned char ver[2]; 332f1b0a434SHarald Freudenberger }; 333f1b0a434SHarald Freudenberger }; 334f1b0a434SHarald Freudenberger 335f1b0a434SHarald Freudenberger /** 336f1b0a434SHarald Freudenberger * ap_qact(): Query AP combatibility type. 337f1b0a434SHarald Freudenberger * @qid: The AP queue number 338f1b0a434SHarald Freudenberger * @apinfo: On input the info about the AP queue. On output the 339f1b0a434SHarald Freudenberger * alternate AP queue info provided by the qact function 340f1b0a434SHarald Freudenberger * in GR2 is stored in. 341f1b0a434SHarald Freudenberger * 342f1b0a434SHarald Freudenberger * Returns AP queue status. Check response_code field for failures. 343f1b0a434SHarald Freudenberger */ 344f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_qact(ap_qid_t qid, int ifbit, 345f1b0a434SHarald Freudenberger union ap_qact_ap_info *apinfo) 346f1b0a434SHarald Freudenberger { 347b9639b31SHeiko Carstens unsigned long reg0 = qid | (5UL << 24) | ((ifbit & 0x01) << 22); 348ebf95e88SHarald Freudenberger union ap_queue_status_reg reg1; 349b9639b31SHeiko Carstens unsigned long reg2; 350f1b0a434SHarald Freudenberger 351159491f3SHarald Freudenberger reg1.value = apinfo->val; 352159491f3SHarald Freudenberger 353f1b0a434SHarald Freudenberger asm volatile( 354b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* qid param into gr0 */ 355b9639b31SHeiko Carstens " lgr 1,%[reg1]\n" /* qact in info into gr1 */ 3562d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(QACT) */ 357b9639b31SHeiko Carstens " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 358b9639b31SHeiko Carstens " lgr %[reg2],2\n" /* qact out info into reg2 */ 359ebf95e88SHarald Freudenberger : [reg1] "+&d" (reg1.value), [reg2] "=&d" (reg2) 360b9639b31SHeiko Carstens : [reg0] "d" (reg0) 361b9639b31SHeiko Carstens : "cc", "0", "1", "2"); 362f1b0a434SHarald Freudenberger apinfo->val = reg2; 363159491f3SHarald Freudenberger return reg1.status; 364f1b0a434SHarald Freudenberger } 365f1b0a434SHarald Freudenberger 366c81cf436SHarald Freudenberger /* 367c81cf436SHarald Freudenberger * ap_bapq(): SE bind AP queue. 368c81cf436SHarald Freudenberger * @qid: The AP queue number 369c81cf436SHarald Freudenberger * 370c81cf436SHarald Freudenberger * Returns AP queue status structure. 371c81cf436SHarald Freudenberger * 372c81cf436SHarald Freudenberger * Invoking this function in a non-SE environment 373c81cf436SHarald Freudenberger * may case a specification exception. 374c81cf436SHarald Freudenberger */ 375c81cf436SHarald Freudenberger static inline struct ap_queue_status ap_bapq(ap_qid_t qid) 376c81cf436SHarald Freudenberger { 377c81cf436SHarald Freudenberger unsigned long reg0 = qid | (7UL << 24); /* fc 7 is BAPQ */ 378c81cf436SHarald Freudenberger union ap_queue_status_reg reg1; 379c81cf436SHarald Freudenberger 380c81cf436SHarald Freudenberger asm volatile( 381c81cf436SHarald Freudenberger " lgr 0,%[reg0]\n" /* qid arg into gr0 */ 382c81cf436SHarald Freudenberger " .insn rre,0xb2af0000,0,0\n" /* PQAP(BAPQ) */ 383c81cf436SHarald Freudenberger " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 384c81cf436SHarald Freudenberger : [reg1] "=&d" (reg1.value) 385c81cf436SHarald Freudenberger : [reg0] "d" (reg0) 386c81cf436SHarald Freudenberger : "cc", "0", "1"); 387c81cf436SHarald Freudenberger 388c81cf436SHarald Freudenberger return reg1.status; 389c81cf436SHarald Freudenberger } 390c81cf436SHarald Freudenberger 391c81cf436SHarald Freudenberger /* 392c81cf436SHarald Freudenberger * ap_aapq(): SE associate AP queue. 393c81cf436SHarald Freudenberger * @qid: The AP queue number 394c81cf436SHarald Freudenberger * @sec_idx: The secret index 395c81cf436SHarald Freudenberger * 396c81cf436SHarald Freudenberger * Returns AP queue status structure. 397c81cf436SHarald Freudenberger * 398c81cf436SHarald Freudenberger * Invoking this function in a non-SE environment 399c81cf436SHarald Freudenberger * may case a specification exception. 400c81cf436SHarald Freudenberger */ 401c81cf436SHarald Freudenberger static inline struct ap_queue_status ap_aapq(ap_qid_t qid, unsigned int sec_idx) 402c81cf436SHarald Freudenberger { 403c81cf436SHarald Freudenberger unsigned long reg0 = qid | (8UL << 24); /* fc 8 is AAPQ */ 404c81cf436SHarald Freudenberger unsigned long reg2 = sec_idx; 405c81cf436SHarald Freudenberger union ap_queue_status_reg reg1; 406c81cf436SHarald Freudenberger 407c81cf436SHarald Freudenberger asm volatile( 408c81cf436SHarald Freudenberger " lgr 0,%[reg0]\n" /* qid arg into gr0 */ 409c81cf436SHarald Freudenberger " lgr 2,%[reg2]\n" /* secret index into gr2 */ 410c81cf436SHarald Freudenberger " .insn rre,0xb2af0000,0,0\n" /* PQAP(AAPQ) */ 411c81cf436SHarald Freudenberger " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 412c81cf436SHarald Freudenberger : [reg1] "=&d" (reg1.value) 413c81cf436SHarald Freudenberger : [reg0] "d" (reg0), [reg2] "d" (reg2) 414c81cf436SHarald Freudenberger : "cc", "0", "1", "2"); 415c81cf436SHarald Freudenberger 416c81cf436SHarald Freudenberger return reg1.status; 417c81cf436SHarald Freudenberger } 418c81cf436SHarald Freudenberger 419f1b0a434SHarald Freudenberger /** 420f1b0a434SHarald Freudenberger * ap_nqap(): Send message to adjunct processor queue. 421f1b0a434SHarald Freudenberger * @qid: The AP queue number 422f1b0a434SHarald Freudenberger * @psmid: The program supplied message identifier 423f1b0a434SHarald Freudenberger * @msg: The message text 424f1b0a434SHarald Freudenberger * @length: The message length 425f1b0a434SHarald Freudenberger * 426f1b0a434SHarald Freudenberger * Returns AP queue status structure. 427f1b0a434SHarald Freudenberger * Condition code 1 on NQAP can't happen because the L bit is 1. 428f1b0a434SHarald Freudenberger * Condition code 2 on NQAP also means the send is incomplete, 429f1b0a434SHarald Freudenberger * because a segment boundary was reached. The NQAP is repeated. 430f1b0a434SHarald Freudenberger */ 431f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_nqap(ap_qid_t qid, 432f1b0a434SHarald Freudenberger unsigned long long psmid, 433f1b0a434SHarald Freudenberger void *msg, size_t length) 434f1b0a434SHarald Freudenberger { 435b9639b31SHeiko Carstens unsigned long reg0 = qid | 0x40000000UL; /* 0x4... is last msg part */ 436b9639b31SHeiko Carstens union register_pair nqap_r1, nqap_r2; 437ebf95e88SHarald Freudenberger union ap_queue_status_reg reg1; 438b9639b31SHeiko Carstens 439b9639b31SHeiko Carstens nqap_r1.even = (unsigned int)(psmid >> 32); 440b9639b31SHeiko Carstens nqap_r1.odd = psmid & 0xffffffff; 441b9639b31SHeiko Carstens nqap_r2.even = (unsigned long)msg; 442b9639b31SHeiko Carstens nqap_r2.odd = (unsigned long)length; 443f1b0a434SHarald Freudenberger 444f1b0a434SHarald Freudenberger asm volatile ( 445b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* qid param in gr0 */ 446b9639b31SHeiko Carstens "0: .insn rre,0xb2ad0000,%[nqap_r1],%[nqap_r2]\n" 447b9639b31SHeiko Carstens " brc 2,0b\n" /* handle partial completion */ 448b9639b31SHeiko Carstens " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 449ebf95e88SHarald Freudenberger : [reg0] "+&d" (reg0), [reg1] "=&d" (reg1.value), 450b9639b31SHeiko Carstens [nqap_r2] "+&d" (nqap_r2.pair) 451b9639b31SHeiko Carstens : [nqap_r1] "d" (nqap_r1.pair) 452b9639b31SHeiko Carstens : "cc", "memory", "0", "1"); 453ebf95e88SHarald Freudenberger return reg1.status; 454f1b0a434SHarald Freudenberger } 455f1b0a434SHarald Freudenberger 456f1b0a434SHarald Freudenberger /** 457f1b0a434SHarald Freudenberger * ap_dqap(): Receive message from adjunct processor queue. 458f1b0a434SHarald Freudenberger * @qid: The AP queue number 459f1b0a434SHarald Freudenberger * @psmid: Pointer to program supplied message identifier 4608794c596SHarald Freudenberger * @msg: Pointer to message buffer 4618794c596SHarald Freudenberger * @msglen: Message buffer size 4628794c596SHarald Freudenberger * @length: Pointer to length of actually written bytes 4638794c596SHarald Freudenberger * @reslength: Residual length on return 4648794c596SHarald Freudenberger * @resgr0: input: gr0 value (only used if != 0), output: residual gr0 content 465f1b0a434SHarald Freudenberger * 466f1b0a434SHarald Freudenberger * Returns AP queue status structure. 467f1b0a434SHarald Freudenberger * Condition code 1 on DQAP means the receive has taken place 468f1b0a434SHarald Freudenberger * but only partially. The response is incomplete, hence the 469f1b0a434SHarald Freudenberger * DQAP is repeated. 470f1b0a434SHarald Freudenberger * Condition code 2 on DQAP also means the receive is incomplete, 471f1b0a434SHarald Freudenberger * this time because a segment boundary was reached. Again, the 472f1b0a434SHarald Freudenberger * DQAP is repeated. 473f1b0a434SHarald Freudenberger * Note that gpr2 is used by the DQAP instruction to keep track of 474f1b0a434SHarald Freudenberger * any 'residual' length, in case the instruction gets interrupted. 475f1b0a434SHarald Freudenberger * Hence it gets zeroed before the instruction. 4761f0d22deSHarald Freudenberger * If the message does not fit into the buffer, this function will 4771f0d22deSHarald Freudenberger * return with a truncated message and the reply in the firmware queue 4781f0d22deSHarald Freudenberger * is not removed. This is indicated to the caller with an 4791f0d22deSHarald Freudenberger * ap_queue_status response_code value of all bits on (0xFF) and (if 4801f0d22deSHarald Freudenberger * the reslength ptr is given) the remaining length is stored in 4811f0d22deSHarald Freudenberger * *reslength and (if the resgr0 ptr is given) the updated gr0 value 4821f0d22deSHarald Freudenberger * for further processing of this msg entry is stored in *resgr0. The 4831f0d22deSHarald Freudenberger * caller needs to detect this situation and should invoke ap_dqap 4841f0d22deSHarald Freudenberger * with a valid resgr0 ptr and a value in there != 0 to indicate that 4851f0d22deSHarald Freudenberger * *resgr0 is to be used instead of qid to further process this entry. 486f1b0a434SHarald Freudenberger */ 487f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_dqap(ap_qid_t qid, 488003d248fSHarald Freudenberger unsigned long *psmid, 4898794c596SHarald Freudenberger void *msg, size_t msglen, 4908794c596SHarald Freudenberger size_t *length, 4911f0d22deSHarald Freudenberger size_t *reslength, 4921f0d22deSHarald Freudenberger unsigned long *resgr0) 493f1b0a434SHarald Freudenberger { 4944516f355SHarald Freudenberger unsigned long reg0 = resgr0 && *resgr0 ? *resgr0 : qid | 0x80000000UL; 495ebf95e88SHarald Freudenberger union ap_queue_status_reg reg1; 4964516f355SHarald Freudenberger unsigned long reg2; 4974516f355SHarald Freudenberger union register_pair rp1, rp2; 4984516f355SHarald Freudenberger 4994516f355SHarald Freudenberger rp1.even = 0UL; 5004516f355SHarald Freudenberger rp1.odd = 0UL; 5014516f355SHarald Freudenberger rp2.even = (unsigned long)msg; 5028794c596SHarald Freudenberger rp2.odd = (unsigned long)msglen; 503f1b0a434SHarald Freudenberger 504f1b0a434SHarald Freudenberger asm volatile( 5054516f355SHarald Freudenberger " lgr 0,%[reg0]\n" /* qid param into gr0 */ 5064516f355SHarald Freudenberger " lghi 2,0\n" /* 0 into gr2 (res length) */ 5074516f355SHarald Freudenberger "0: ltgr %N[rp2],%N[rp2]\n" /* check buf len */ 5084516f355SHarald Freudenberger " jz 2f\n" /* go out if buf len is 0 */ 5094516f355SHarald Freudenberger "1: .insn rre,0xb2ae0000,%[rp1],%[rp2]\n" 5104516f355SHarald Freudenberger " brc 6,0b\n" /* handle partial complete */ 5114516f355SHarald Freudenberger "2: lgr %[reg0],0\n" /* gr0 (qid + info) into reg0 */ 5124516f355SHarald Freudenberger " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 5134516f355SHarald Freudenberger " lgr %[reg2],2\n" /* gr2 (res length) into reg2 */ 514ebf95e88SHarald Freudenberger : [reg0] "+&d" (reg0), [reg1] "=&d" (reg1.value), 515ebf95e88SHarald Freudenberger [reg2] "=&d" (reg2), [rp1] "+&d" (rp1.pair), 516ebf95e88SHarald Freudenberger [rp2] "+&d" (rp2.pair) 5174516f355SHarald Freudenberger : 5184516f355SHarald Freudenberger : "cc", "memory", "0", "1", "2"); 5191f0d22deSHarald Freudenberger 5201f0d22deSHarald Freudenberger if (reslength) 5211f0d22deSHarald Freudenberger *reslength = reg2; 5224516f355SHarald Freudenberger if (reg2 != 0 && rp2.odd == 0) { 5231f0d22deSHarald Freudenberger /* 5241f0d22deSHarald Freudenberger * Partially complete, status in gr1 is not set. 5251f0d22deSHarald Freudenberger * Signal the caller that this dqap is only partially received 5261f0d22deSHarald Freudenberger * with a special status response code 0xFF and *resgr0 updated 5271f0d22deSHarald Freudenberger */ 528ebf95e88SHarald Freudenberger reg1.status.response_code = 0xFF; 5291f0d22deSHarald Freudenberger if (resgr0) 5301f0d22deSHarald Freudenberger *resgr0 = reg0; 5311f0d22deSHarald Freudenberger } else { 532003d248fSHarald Freudenberger *psmid = (rp1.even << 32) + rp1.odd; 5331f0d22deSHarald Freudenberger if (resgr0) 5341f0d22deSHarald Freudenberger *resgr0 = 0; 5351f0d22deSHarald Freudenberger } 5361f0d22deSHarald Freudenberger 5378794c596SHarald Freudenberger /* update *length with the nr of bytes stored into the msg buffer */ 5388794c596SHarald Freudenberger if (length) 5398794c596SHarald Freudenberger *length = msglen - rp2.odd; 5408794c596SHarald Freudenberger 541ebf95e88SHarald Freudenberger return reg1.status; 542f1b0a434SHarald Freudenberger } 54346fde9a9SHarald Freudenberger 5440d9c038fSTony Krowiak /* 5450d9c038fSTony Krowiak * Interface to tell the AP bus code that a configuration 5460d9c038fSTony Krowiak * change has happened. The bus code should at least do 5470d9c038fSTony Krowiak * an ap bus resource rescan. 5480d9c038fSTony Krowiak */ 5490d9c038fSTony Krowiak #if IS_ENABLED(CONFIG_ZCRYPT) 5500d9c038fSTony Krowiak void ap_bus_cfg_chg(void); 5510d9c038fSTony Krowiak #else 552d09cb482SChengyang Fan static inline void ap_bus_cfg_chg(void){} 5530d9c038fSTony Krowiak #endif 5540d9c038fSTony Krowiak 555e7fc5146STony Krowiak #endif /* _ASM_S390_AP_H_ */ 556