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; 46e7fc5146STony Krowiak unsigned int _pad1 : 4; 47e7fc5146STony Krowiak unsigned int irq_enabled : 1; 48e7fc5146STony Krowiak unsigned int response_code : 8; 49e7fc5146STony Krowiak unsigned int _pad2 : 16; 50e7fc5146STony Krowiak }; 51e7fc5146STony Krowiak 52e7fc5146STony Krowiak /** 53f1b0a434SHarald Freudenberger * ap_intructions_available() - Test if AP instructions are available. 54f1b0a434SHarald Freudenberger * 559b97e9f5SHarald Freudenberger * Returns true if the AP instructions are installed, otherwise false. 56f1b0a434SHarald Freudenberger */ 579b97e9f5SHarald Freudenberger static inline bool ap_instructions_available(void) 58f1b0a434SHarald Freudenberger { 59b9639b31SHeiko Carstens unsigned long reg0 = AP_MKQID(0, 0); 60b9639b31SHeiko Carstens unsigned long reg1 = 0; 61f1b0a434SHarald Freudenberger 62f1b0a434SHarald Freudenberger asm volatile( 63b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* qid into gr0 */ 64b9639b31SHeiko Carstens " lghi 1,0\n" /* 0 into gr1 */ 65b9639b31SHeiko Carstens " lghi 2,0\n" /* 0 into gr2 */ 662d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(TAPQ) */ 67b9639b31SHeiko Carstens "0: la %[reg1],1\n" /* 1 into reg1 */ 68f1b0a434SHarald Freudenberger "1:\n" 69f1b0a434SHarald Freudenberger EX_TABLE(0b, 1b) 70b9639b31SHeiko Carstens : [reg1] "+&d" (reg1) 71b9639b31SHeiko Carstens : [reg0] "d" (reg0) 72b9639b31SHeiko Carstens : "cc", "0", "1", "2"); 739b97e9f5SHarald Freudenberger return reg1 != 0; 74f1b0a434SHarald Freudenberger } 75f1b0a434SHarald Freudenberger 76f1b0a434SHarald Freudenberger /** 77f1b0a434SHarald Freudenberger * ap_tapq(): Test adjunct processor queue. 78f1b0a434SHarald Freudenberger * @qid: The AP queue number 79f1b0a434SHarald Freudenberger * @info: Pointer to queue descriptor 80f1b0a434SHarald Freudenberger * 81f1b0a434SHarald Freudenberger * Returns AP queue status structure. 82f1b0a434SHarald Freudenberger */ 83f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_tapq(ap_qid_t qid, unsigned long *info) 84f1b0a434SHarald Freudenberger { 85b9639b31SHeiko Carstens struct ap_queue_status reg1; 86b9639b31SHeiko Carstens unsigned long reg2; 87f1b0a434SHarald Freudenberger 88b9639b31SHeiko Carstens asm volatile( 89b9639b31SHeiko Carstens " lgr 0,%[qid]\n" /* qid into gr0 */ 90b9639b31SHeiko Carstens " lghi 2,0\n" /* 0 into gr2 */ 912d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(TAPQ) */ 92b9639b31SHeiko Carstens " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 93b9639b31SHeiko Carstens " lgr %[reg2],2\n" /* gr2 into reg2 */ 94b9639b31SHeiko Carstens : [reg1] "=&d" (reg1), [reg2] "=&d" (reg2) 95b9639b31SHeiko Carstens : [qid] "d" (qid) 96b9639b31SHeiko Carstens : "cc", "0", "1", "2"); 97f1b0a434SHarald Freudenberger if (info) 98f1b0a434SHarald Freudenberger *info = reg2; 99f1b0a434SHarald Freudenberger return reg1; 100f1b0a434SHarald Freudenberger } 101f1b0a434SHarald Freudenberger 102f1b0a434SHarald Freudenberger /** 103e7fc5146STony Krowiak * ap_test_queue(): Test adjunct processor queue. 104e7fc5146STony Krowiak * @qid: The AP queue number 105e7fc5146STony Krowiak * @tbit: Test facilities bit 106e7fc5146STony Krowiak * @info: Pointer to queue descriptor 107e7fc5146STony Krowiak * 108e7fc5146STony Krowiak * Returns AP queue status structure. 109e7fc5146STony Krowiak */ 110f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_test_queue(ap_qid_t qid, 111e7fc5146STony Krowiak int tbit, 112f1b0a434SHarald Freudenberger unsigned long *info) 113f1b0a434SHarald Freudenberger { 114f1b0a434SHarald Freudenberger if (tbit) 115f1b0a434SHarald Freudenberger qid |= 1UL << 23; /* set T bit*/ 116f1b0a434SHarald Freudenberger return ap_tapq(qid, info); 117f1b0a434SHarald Freudenberger } 118e7fc5146STony Krowiak 119f1b0a434SHarald Freudenberger /** 120f1b0a434SHarald Freudenberger * ap_pqap_rapq(): Reset adjunct processor queue. 121f1b0a434SHarald Freudenberger * @qid: The AP queue number 122f1b0a434SHarald Freudenberger * 123f1b0a434SHarald Freudenberger * Returns AP queue status structure. 124f1b0a434SHarald Freudenberger */ 125f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_rapq(ap_qid_t qid) 126f1b0a434SHarald Freudenberger { 127b9639b31SHeiko Carstens unsigned long reg0 = qid | (1UL << 24); /* fc 1UL is RAPQ */ 128b9639b31SHeiko Carstens struct ap_queue_status reg1; 129f1b0a434SHarald Freudenberger 130f1b0a434SHarald Freudenberger asm volatile( 131b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* qid arg into gr0 */ 1322d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(RAPQ) */ 133b9639b31SHeiko Carstens " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 134b9639b31SHeiko Carstens : [reg1] "=&d" (reg1) 135b9639b31SHeiko Carstens : [reg0] "d" (reg0) 136b9639b31SHeiko Carstens : "cc", "0", "1"); 137f1b0a434SHarald Freudenberger return reg1; 138f1b0a434SHarald Freudenberger } 139f1b0a434SHarald Freudenberger 140f1b0a434SHarald Freudenberger /** 141f1b0a434SHarald Freudenberger * ap_pqap_zapq(): Reset and zeroize adjunct processor queue. 142f1b0a434SHarald Freudenberger * @qid: The AP queue number 143f1b0a434SHarald Freudenberger * 144f1b0a434SHarald Freudenberger * Returns AP queue status structure. 145f1b0a434SHarald Freudenberger */ 146f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_zapq(ap_qid_t qid) 147f1b0a434SHarald Freudenberger { 148b9639b31SHeiko Carstens unsigned long reg0 = qid | (2UL << 24); /* fc 2UL is ZAPQ */ 149b9639b31SHeiko Carstens struct ap_queue_status reg1; 150f1b0a434SHarald Freudenberger 151f1b0a434SHarald Freudenberger asm volatile( 152b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* qid arg into gr0 */ 1532d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(ZAPQ) */ 154b9639b31SHeiko Carstens " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 155b9639b31SHeiko Carstens : [reg1] "=&d" (reg1) 156b9639b31SHeiko Carstens : [reg0] "d" (reg0) 157b9639b31SHeiko Carstens : "cc", "0", "1"); 158f1b0a434SHarald Freudenberger return reg1; 159f1b0a434SHarald Freudenberger } 160f1b0a434SHarald Freudenberger 161f1b0a434SHarald Freudenberger /** 162f1b0a434SHarald Freudenberger * struct ap_config_info - convenience struct for AP crypto 163f1b0a434SHarald Freudenberger * config info as returned by the ap_qci() function. 164f1b0a434SHarald Freudenberger */ 165050349b5SHarald Freudenberger struct ap_config_info { 166050349b5SHarald Freudenberger unsigned int apsc : 1; /* S bit */ 167050349b5SHarald Freudenberger unsigned int apxa : 1; /* N bit */ 168050349b5SHarald Freudenberger unsigned int qact : 1; /* C bit */ 169050349b5SHarald Freudenberger unsigned int rc8a : 1; /* R bit */ 170050349b5SHarald Freudenberger unsigned char _reserved1 : 4; 171050349b5SHarald Freudenberger unsigned char _reserved2[3]; 172050349b5SHarald Freudenberger unsigned char Na; /* max # of APs - 1 */ 173050349b5SHarald Freudenberger unsigned char Nd; /* max # of Domains - 1 */ 174050349b5SHarald Freudenberger unsigned char _reserved3[10]; 175050349b5SHarald Freudenberger unsigned int apm[8]; /* AP ID mask */ 1767379e652SHarald Freudenberger unsigned int aqm[8]; /* AP (usage) queue mask */ 1777379e652SHarald Freudenberger unsigned int adm[8]; /* AP (control) domain mask */ 178050349b5SHarald Freudenberger unsigned char _reserved4[16]; 179050349b5SHarald Freudenberger } __aligned(8); 180050349b5SHarald Freudenberger 181f1b0a434SHarald Freudenberger /** 182f1b0a434SHarald Freudenberger * ap_qci(): Get AP configuration data 183050349b5SHarald Freudenberger * 184f1b0a434SHarald Freudenberger * Returns 0 on success, or -EOPNOTSUPP. 185050349b5SHarald Freudenberger */ 186f1b0a434SHarald Freudenberger static inline int ap_qci(struct ap_config_info *config) 187f1b0a434SHarald Freudenberger { 188b9639b31SHeiko Carstens unsigned long reg0 = 4UL << 24; /* fc 4UL is QCI */ 189b9639b31SHeiko Carstens unsigned long reg1 = -EOPNOTSUPP; 190b9639b31SHeiko Carstens struct ap_config_info *reg2 = config; 191f1b0a434SHarald Freudenberger 192f1b0a434SHarald Freudenberger asm volatile( 193b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* QCI fc into gr0 */ 194b9639b31SHeiko Carstens " lgr 2,%[reg2]\n" /* ptr to config into gr2 */ 1952d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(QCI) */ 196b9639b31SHeiko Carstens "0: la %[reg1],0\n" /* good case, QCI fc available */ 197f1b0a434SHarald Freudenberger "1:\n" 198f1b0a434SHarald Freudenberger EX_TABLE(0b, 1b) 199b9639b31SHeiko Carstens : [reg1] "+&d" (reg1) 200b9639b31SHeiko Carstens : [reg0] "d" (reg0), [reg2] "d" (reg2) 201b9639b31SHeiko Carstens : "cc", "memory", "0", "2"); 202f1b0a434SHarald Freudenberger 203f1b0a434SHarald Freudenberger return reg1; 204f1b0a434SHarald Freudenberger } 205050349b5SHarald Freudenberger 20646fde9a9SHarald Freudenberger /* 20746fde9a9SHarald Freudenberger * struct ap_qirq_ctrl - convenient struct for easy invocation 208f1b0a434SHarald Freudenberger * of the ap_aqic() function. This struct is passed as GR1 209f1b0a434SHarald Freudenberger * parameter to the PQAP(AQIC) instruction. For details please 210f1b0a434SHarald Freudenberger * see the AR documentation. 21146fde9a9SHarald Freudenberger */ 21246fde9a9SHarald Freudenberger struct ap_qirq_ctrl { 21346fde9a9SHarald Freudenberger unsigned int _res1 : 8; 21446fde9a9SHarald Freudenberger unsigned int zone : 8; /* zone info */ 21546fde9a9SHarald Freudenberger unsigned int ir : 1; /* ir flag: enable (1) or disable (0) irq */ 21646fde9a9SHarald Freudenberger unsigned int _res2 : 4; 21746fde9a9SHarald Freudenberger unsigned int gisc : 3; /* guest isc field */ 21846fde9a9SHarald Freudenberger unsigned int _res3 : 6; 21946fde9a9SHarald Freudenberger unsigned int gf : 2; /* gisa format */ 22046fde9a9SHarald Freudenberger unsigned int _res4 : 1; 22146fde9a9SHarald Freudenberger unsigned int gisa : 27; /* gisa origin */ 22246fde9a9SHarald Freudenberger unsigned int _res5 : 1; 22346fde9a9SHarald Freudenberger unsigned int isc : 3; /* irq sub class */ 22446fde9a9SHarald Freudenberger }; 22546fde9a9SHarald Freudenberger 22646fde9a9SHarald Freudenberger /** 227f1b0a434SHarald Freudenberger * ap_aqic(): Control interruption for a specific AP. 22846fde9a9SHarald Freudenberger * @qid: The AP queue number 229f1b0a434SHarald Freudenberger * @qirqctrl: struct ap_qirq_ctrl (64 bit value) 230*10e19d49SNicolin Chen * @pa_ind: Physical address of the notification indicator byte 23146fde9a9SHarald Freudenberger * 23246fde9a9SHarald Freudenberger * Returns AP queue status. 23346fde9a9SHarald Freudenberger */ 234f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_aqic(ap_qid_t qid, 23546fde9a9SHarald Freudenberger struct ap_qirq_ctrl qirqctrl, 236*10e19d49SNicolin Chen phys_addr_t pa_ind) 237f1b0a434SHarald Freudenberger { 238b9639b31SHeiko Carstens unsigned long reg0 = qid | (3UL << 24); /* fc 3UL is AQIC */ 239b9639b31SHeiko Carstens union { 240159491f3SHarald Freudenberger unsigned long value; 241159491f3SHarald Freudenberger struct ap_qirq_ctrl qirqctrl; 242159491f3SHarald Freudenberger struct ap_queue_status status; 243b9639b31SHeiko Carstens } reg1; 244*10e19d49SNicolin Chen unsigned long reg2 = pa_ind; 245f1b0a434SHarald Freudenberger 246159491f3SHarald Freudenberger reg1.qirqctrl = qirqctrl; 247159491f3SHarald Freudenberger 248f1b0a434SHarald Freudenberger asm volatile( 249b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* qid param into gr0 */ 250b9639b31SHeiko Carstens " lgr 1,%[reg1]\n" /* irq ctrl into gr1 */ 251b9639b31SHeiko Carstens " lgr 2,%[reg2]\n" /* ni addr into gr2 */ 2522d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(AQIC) */ 253b9639b31SHeiko Carstens " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 254b9639b31SHeiko Carstens : [reg1] "+&d" (reg1) 255b9639b31SHeiko Carstens : [reg0] "d" (reg0), [reg2] "d" (reg2) 256b9639b31SHeiko Carstens : "cc", "0", "1", "2"); 257159491f3SHarald Freudenberger 258159491f3SHarald Freudenberger return reg1.status; 259f1b0a434SHarald Freudenberger } 260f1b0a434SHarald Freudenberger 261f1b0a434SHarald Freudenberger /* 262f1b0a434SHarald Freudenberger * union ap_qact_ap_info - used together with the 263f1b0a434SHarald Freudenberger * ap_aqic() function to provide a convenient way 264f1b0a434SHarald Freudenberger * to handle the ap info needed by the qact function. 265f1b0a434SHarald Freudenberger */ 266f1b0a434SHarald Freudenberger union ap_qact_ap_info { 267f1b0a434SHarald Freudenberger unsigned long val; 268f1b0a434SHarald Freudenberger struct { 269f1b0a434SHarald Freudenberger unsigned int : 3; 270f1b0a434SHarald Freudenberger unsigned int mode : 3; 271f1b0a434SHarald Freudenberger unsigned int : 26; 272f1b0a434SHarald Freudenberger unsigned int cat : 8; 273f1b0a434SHarald Freudenberger unsigned int : 8; 274f1b0a434SHarald Freudenberger unsigned char ver[2]; 275f1b0a434SHarald Freudenberger }; 276f1b0a434SHarald Freudenberger }; 277f1b0a434SHarald Freudenberger 278f1b0a434SHarald Freudenberger /** 279f1b0a434SHarald Freudenberger * ap_qact(): Query AP combatibility type. 280f1b0a434SHarald Freudenberger * @qid: The AP queue number 281f1b0a434SHarald Freudenberger * @apinfo: On input the info about the AP queue. On output the 282f1b0a434SHarald Freudenberger * alternate AP queue info provided by the qact function 283f1b0a434SHarald Freudenberger * in GR2 is stored in. 284f1b0a434SHarald Freudenberger * 285f1b0a434SHarald Freudenberger * Returns AP queue status. Check response_code field for failures. 286f1b0a434SHarald Freudenberger */ 287f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_qact(ap_qid_t qid, int ifbit, 288f1b0a434SHarald Freudenberger union ap_qact_ap_info *apinfo) 289f1b0a434SHarald Freudenberger { 290b9639b31SHeiko Carstens unsigned long reg0 = qid | (5UL << 24) | ((ifbit & 0x01) << 22); 291b9639b31SHeiko Carstens union { 292159491f3SHarald Freudenberger unsigned long value; 293159491f3SHarald Freudenberger struct ap_queue_status status; 294b9639b31SHeiko Carstens } reg1; 295b9639b31SHeiko Carstens unsigned long reg2; 296f1b0a434SHarald Freudenberger 297159491f3SHarald Freudenberger reg1.value = apinfo->val; 298159491f3SHarald Freudenberger 299f1b0a434SHarald Freudenberger asm volatile( 300b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* qid param into gr0 */ 301b9639b31SHeiko Carstens " lgr 1,%[reg1]\n" /* qact in info into gr1 */ 3022d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(QACT) */ 303b9639b31SHeiko Carstens " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 304b9639b31SHeiko Carstens " lgr %[reg2],2\n" /* qact out info into reg2 */ 305b9639b31SHeiko Carstens : [reg1] "+&d" (reg1), [reg2] "=&d" (reg2) 306b9639b31SHeiko Carstens : [reg0] "d" (reg0) 307b9639b31SHeiko Carstens : "cc", "0", "1", "2"); 308f1b0a434SHarald Freudenberger apinfo->val = reg2; 309159491f3SHarald Freudenberger return reg1.status; 310f1b0a434SHarald Freudenberger } 311f1b0a434SHarald Freudenberger 312f1b0a434SHarald Freudenberger /** 313f1b0a434SHarald Freudenberger * ap_nqap(): Send message to adjunct processor queue. 314f1b0a434SHarald Freudenberger * @qid: The AP queue number 315f1b0a434SHarald Freudenberger * @psmid: The program supplied message identifier 316f1b0a434SHarald Freudenberger * @msg: The message text 317f1b0a434SHarald Freudenberger * @length: The message length 318f1b0a434SHarald Freudenberger * 319f1b0a434SHarald Freudenberger * Returns AP queue status structure. 320f1b0a434SHarald Freudenberger * Condition code 1 on NQAP can't happen because the L bit is 1. 321f1b0a434SHarald Freudenberger * Condition code 2 on NQAP also means the send is incomplete, 322f1b0a434SHarald Freudenberger * because a segment boundary was reached. The NQAP is repeated. 323f1b0a434SHarald Freudenberger */ 324f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_nqap(ap_qid_t qid, 325f1b0a434SHarald Freudenberger unsigned long long psmid, 326f1b0a434SHarald Freudenberger void *msg, size_t length) 327f1b0a434SHarald Freudenberger { 328b9639b31SHeiko Carstens unsigned long reg0 = qid | 0x40000000UL; /* 0x4... is last msg part */ 329b9639b31SHeiko Carstens union register_pair nqap_r1, nqap_r2; 330b9639b31SHeiko Carstens struct ap_queue_status reg1; 331b9639b31SHeiko Carstens 332b9639b31SHeiko Carstens nqap_r1.even = (unsigned int)(psmid >> 32); 333b9639b31SHeiko Carstens nqap_r1.odd = psmid & 0xffffffff; 334b9639b31SHeiko Carstens nqap_r2.even = (unsigned long)msg; 335b9639b31SHeiko Carstens nqap_r2.odd = (unsigned long)length; 336f1b0a434SHarald Freudenberger 337f1b0a434SHarald Freudenberger asm volatile ( 338b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* qid param in gr0 */ 339b9639b31SHeiko Carstens "0: .insn rre,0xb2ad0000,%[nqap_r1],%[nqap_r2]\n" 340b9639b31SHeiko Carstens " brc 2,0b\n" /* handle partial completion */ 341b9639b31SHeiko Carstens " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 342b9639b31SHeiko Carstens : [reg0] "+&d" (reg0), [reg1] "=&d" (reg1), 343b9639b31SHeiko Carstens [nqap_r2] "+&d" (nqap_r2.pair) 344b9639b31SHeiko Carstens : [nqap_r1] "d" (nqap_r1.pair) 345b9639b31SHeiko Carstens : "cc", "memory", "0", "1"); 346f1b0a434SHarald Freudenberger return reg1; 347f1b0a434SHarald Freudenberger } 348f1b0a434SHarald Freudenberger 349f1b0a434SHarald Freudenberger /** 350f1b0a434SHarald Freudenberger * ap_dqap(): Receive message from adjunct processor queue. 351f1b0a434SHarald Freudenberger * @qid: The AP queue number 352f1b0a434SHarald Freudenberger * @psmid: Pointer to program supplied message identifier 353f1b0a434SHarald Freudenberger * @msg: The message text 354f1b0a434SHarald Freudenberger * @length: The message length 3551f0d22deSHarald Freudenberger * @reslength: Resitual length on return 3561f0d22deSHarald Freudenberger * @resgr0: input: gr0 value (only used if != 0), output: resitual gr0 content 357f1b0a434SHarald Freudenberger * 358f1b0a434SHarald Freudenberger * Returns AP queue status structure. 359f1b0a434SHarald Freudenberger * Condition code 1 on DQAP means the receive has taken place 360f1b0a434SHarald Freudenberger * but only partially. The response is incomplete, hence the 361f1b0a434SHarald Freudenberger * DQAP is repeated. 362f1b0a434SHarald Freudenberger * Condition code 2 on DQAP also means the receive is incomplete, 363f1b0a434SHarald Freudenberger * this time because a segment boundary was reached. Again, the 364f1b0a434SHarald Freudenberger * DQAP is repeated. 365f1b0a434SHarald Freudenberger * Note that gpr2 is used by the DQAP instruction to keep track of 366f1b0a434SHarald Freudenberger * any 'residual' length, in case the instruction gets interrupted. 367f1b0a434SHarald Freudenberger * Hence it gets zeroed before the instruction. 3681f0d22deSHarald Freudenberger * If the message does not fit into the buffer, this function will 3691f0d22deSHarald Freudenberger * return with a truncated message and the reply in the firmware queue 3701f0d22deSHarald Freudenberger * is not removed. This is indicated to the caller with an 3711f0d22deSHarald Freudenberger * ap_queue_status response_code value of all bits on (0xFF) and (if 3721f0d22deSHarald Freudenberger * the reslength ptr is given) the remaining length is stored in 3731f0d22deSHarald Freudenberger * *reslength and (if the resgr0 ptr is given) the updated gr0 value 3741f0d22deSHarald Freudenberger * for further processing of this msg entry is stored in *resgr0. The 3751f0d22deSHarald Freudenberger * caller needs to detect this situation and should invoke ap_dqap 3761f0d22deSHarald Freudenberger * with a valid resgr0 ptr and a value in there != 0 to indicate that 3771f0d22deSHarald Freudenberger * *resgr0 is to be used instead of qid to further process this entry. 378f1b0a434SHarald Freudenberger */ 379f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_dqap(ap_qid_t qid, 380f1b0a434SHarald Freudenberger unsigned long long *psmid, 3811f0d22deSHarald Freudenberger void *msg, size_t length, 3821f0d22deSHarald Freudenberger size_t *reslength, 3831f0d22deSHarald Freudenberger unsigned long *resgr0) 384f1b0a434SHarald Freudenberger { 3854516f355SHarald Freudenberger unsigned long reg0 = resgr0 && *resgr0 ? *resgr0 : qid | 0x80000000UL; 3864516f355SHarald Freudenberger struct ap_queue_status reg1; 3874516f355SHarald Freudenberger unsigned long reg2; 3884516f355SHarald Freudenberger union register_pair rp1, rp2; 3894516f355SHarald Freudenberger 3904516f355SHarald Freudenberger rp1.even = 0UL; 3914516f355SHarald Freudenberger rp1.odd = 0UL; 3924516f355SHarald Freudenberger rp2.even = (unsigned long)msg; 3934516f355SHarald Freudenberger rp2.odd = (unsigned long)length; 394f1b0a434SHarald Freudenberger 395f1b0a434SHarald Freudenberger asm volatile( 3964516f355SHarald Freudenberger " lgr 0,%[reg0]\n" /* qid param into gr0 */ 3974516f355SHarald Freudenberger " lghi 2,0\n" /* 0 into gr2 (res length) */ 3984516f355SHarald Freudenberger "0: ltgr %N[rp2],%N[rp2]\n" /* check buf len */ 3994516f355SHarald Freudenberger " jz 2f\n" /* go out if buf len is 0 */ 4004516f355SHarald Freudenberger "1: .insn rre,0xb2ae0000,%[rp1],%[rp2]\n" 4014516f355SHarald Freudenberger " brc 6,0b\n" /* handle partial complete */ 4024516f355SHarald Freudenberger "2: lgr %[reg0],0\n" /* gr0 (qid + info) into reg0 */ 4034516f355SHarald Freudenberger " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 4044516f355SHarald Freudenberger " lgr %[reg2],2\n" /* gr2 (res length) into reg2 */ 4054516f355SHarald Freudenberger : [reg0] "+&d" (reg0), [reg1] "=&d" (reg1), [reg2] "=&d" (reg2), 4064516f355SHarald Freudenberger [rp1] "+&d" (rp1.pair), [rp2] "+&d" (rp2.pair) 4074516f355SHarald Freudenberger : 4084516f355SHarald Freudenberger : "cc", "memory", "0", "1", "2"); 4091f0d22deSHarald Freudenberger 4101f0d22deSHarald Freudenberger if (reslength) 4111f0d22deSHarald Freudenberger *reslength = reg2; 4124516f355SHarald Freudenberger if (reg2 != 0 && rp2.odd == 0) { 4131f0d22deSHarald Freudenberger /* 4141f0d22deSHarald Freudenberger * Partially complete, status in gr1 is not set. 4151f0d22deSHarald Freudenberger * Signal the caller that this dqap is only partially received 4161f0d22deSHarald Freudenberger * with a special status response code 0xFF and *resgr0 updated 4171f0d22deSHarald Freudenberger */ 4181f0d22deSHarald Freudenberger reg1.response_code = 0xFF; 4191f0d22deSHarald Freudenberger if (resgr0) 4201f0d22deSHarald Freudenberger *resgr0 = reg0; 4211f0d22deSHarald Freudenberger } else { 4224516f355SHarald Freudenberger *psmid = (((unsigned long long)rp1.even) << 32) + rp1.odd; 4231f0d22deSHarald Freudenberger if (resgr0) 4241f0d22deSHarald Freudenberger *resgr0 = 0; 4251f0d22deSHarald Freudenberger } 4261f0d22deSHarald Freudenberger 427f1b0a434SHarald Freudenberger return reg1; 428f1b0a434SHarald Freudenberger } 42946fde9a9SHarald Freudenberger 4300d9c038fSTony Krowiak /* 4310d9c038fSTony Krowiak * Interface to tell the AP bus code that a configuration 4320d9c038fSTony Krowiak * change has happened. The bus code should at least do 4330d9c038fSTony Krowiak * an ap bus resource rescan. 4340d9c038fSTony Krowiak */ 4350d9c038fSTony Krowiak #if IS_ENABLED(CONFIG_ZCRYPT) 4360d9c038fSTony Krowiak void ap_bus_cfg_chg(void); 4370d9c038fSTony Krowiak #else 438d09cb482SChengyang Fan static inline void ap_bus_cfg_chg(void){} 4390d9c038fSTony Krowiak #endif 4400d9c038fSTony Krowiak 441e7fc5146STony Krowiak #endif /* _ASM_S390_AP_H_ */ 442