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 52*ebf95e88SHarald Freudenberger /* 53*ebf95e88SHarald Freudenberger * AP queue status reg union to access the reg1 54*ebf95e88SHarald Freudenberger * register with the lower 32 bits comprising the 55*ebf95e88SHarald Freudenberger * ap queue status. 56*ebf95e88SHarald Freudenberger */ 57*ebf95e88SHarald Freudenberger union ap_queue_status_reg { 58*ebf95e88SHarald Freudenberger unsigned long value; 59*ebf95e88SHarald Freudenberger struct { 60*ebf95e88SHarald Freudenberger u32 _pad; 61*ebf95e88SHarald Freudenberger struct ap_queue_status status; 62*ebf95e88SHarald Freudenberger }; 63*ebf95e88SHarald Freudenberger }; 64*ebf95e88SHarald Freudenberger 65e7fc5146STony Krowiak /** 66f1b0a434SHarald Freudenberger * ap_intructions_available() - Test if AP instructions are available. 67f1b0a434SHarald Freudenberger * 689b97e9f5SHarald Freudenberger * Returns true if the AP instructions are installed, otherwise false. 69f1b0a434SHarald Freudenberger */ 709b97e9f5SHarald Freudenberger static inline bool ap_instructions_available(void) 71f1b0a434SHarald Freudenberger { 72b9639b31SHeiko Carstens unsigned long reg0 = AP_MKQID(0, 0); 73b9639b31SHeiko Carstens unsigned long reg1 = 0; 74f1b0a434SHarald Freudenberger 75f1b0a434SHarald Freudenberger asm volatile( 76b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* qid into gr0 */ 77b9639b31SHeiko Carstens " lghi 1,0\n" /* 0 into gr1 */ 78b9639b31SHeiko Carstens " lghi 2,0\n" /* 0 into gr2 */ 792d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(TAPQ) */ 80b9639b31SHeiko Carstens "0: la %[reg1],1\n" /* 1 into reg1 */ 81f1b0a434SHarald Freudenberger "1:\n" 82f1b0a434SHarald Freudenberger EX_TABLE(0b, 1b) 83b9639b31SHeiko Carstens : [reg1] "+&d" (reg1) 84b9639b31SHeiko Carstens : [reg0] "d" (reg0) 85b9639b31SHeiko Carstens : "cc", "0", "1", "2"); 869b97e9f5SHarald Freudenberger return reg1 != 0; 87f1b0a434SHarald Freudenberger } 88f1b0a434SHarald Freudenberger 89f1b0a434SHarald Freudenberger /** 90f1b0a434SHarald Freudenberger * ap_tapq(): Test adjunct processor queue. 91f1b0a434SHarald Freudenberger * @qid: The AP queue number 92f1b0a434SHarald Freudenberger * @info: Pointer to queue descriptor 93f1b0a434SHarald Freudenberger * 94f1b0a434SHarald Freudenberger * Returns AP queue status structure. 95f1b0a434SHarald Freudenberger */ 96f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_tapq(ap_qid_t qid, unsigned long *info) 97f1b0a434SHarald Freudenberger { 98*ebf95e88SHarald Freudenberger union ap_queue_status_reg reg1; 99b9639b31SHeiko Carstens unsigned long reg2; 100f1b0a434SHarald Freudenberger 101b9639b31SHeiko Carstens asm volatile( 102b9639b31SHeiko Carstens " lgr 0,%[qid]\n" /* qid into gr0 */ 103b9639b31SHeiko Carstens " lghi 2,0\n" /* 0 into gr2 */ 1042d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(TAPQ) */ 105b9639b31SHeiko Carstens " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 106b9639b31SHeiko Carstens " lgr %[reg2],2\n" /* gr2 into reg2 */ 107*ebf95e88SHarald Freudenberger : [reg1] "=&d" (reg1.value), [reg2] "=&d" (reg2) 108b9639b31SHeiko Carstens : [qid] "d" (qid) 109b9639b31SHeiko Carstens : "cc", "0", "1", "2"); 110f1b0a434SHarald Freudenberger if (info) 111f1b0a434SHarald Freudenberger *info = reg2; 112*ebf95e88SHarald Freudenberger return reg1.status; 113f1b0a434SHarald Freudenberger } 114f1b0a434SHarald Freudenberger 115f1b0a434SHarald Freudenberger /** 116e7fc5146STony Krowiak * ap_test_queue(): Test adjunct processor queue. 117e7fc5146STony Krowiak * @qid: The AP queue number 118e7fc5146STony Krowiak * @tbit: Test facilities bit 119e7fc5146STony Krowiak * @info: Pointer to queue descriptor 120e7fc5146STony Krowiak * 121e7fc5146STony Krowiak * Returns AP queue status structure. 122e7fc5146STony Krowiak */ 123f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_test_queue(ap_qid_t qid, 124e7fc5146STony Krowiak int tbit, 125f1b0a434SHarald Freudenberger unsigned long *info) 126f1b0a434SHarald Freudenberger { 127f1b0a434SHarald Freudenberger if (tbit) 128f1b0a434SHarald Freudenberger qid |= 1UL << 23; /* set T bit*/ 129f1b0a434SHarald Freudenberger return ap_tapq(qid, info); 130f1b0a434SHarald Freudenberger } 131e7fc5146STony Krowiak 132f1b0a434SHarald Freudenberger /** 133f1b0a434SHarald Freudenberger * ap_pqap_rapq(): Reset adjunct processor queue. 134f1b0a434SHarald Freudenberger * @qid: The AP queue number 135f1b0a434SHarald Freudenberger * 136f1b0a434SHarald Freudenberger * Returns AP queue status structure. 137f1b0a434SHarald Freudenberger */ 138f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_rapq(ap_qid_t qid) 139f1b0a434SHarald Freudenberger { 140b9639b31SHeiko Carstens unsigned long reg0 = qid | (1UL << 24); /* fc 1UL is RAPQ */ 141*ebf95e88SHarald Freudenberger union ap_queue_status_reg reg1; 142f1b0a434SHarald Freudenberger 143f1b0a434SHarald Freudenberger asm volatile( 144b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* qid arg into gr0 */ 1452d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(RAPQ) */ 146b9639b31SHeiko Carstens " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 147*ebf95e88SHarald Freudenberger : [reg1] "=&d" (reg1.value) 148b9639b31SHeiko Carstens : [reg0] "d" (reg0) 149b9639b31SHeiko Carstens : "cc", "0", "1"); 150*ebf95e88SHarald Freudenberger return reg1.status; 151f1b0a434SHarald Freudenberger } 152f1b0a434SHarald Freudenberger 153f1b0a434SHarald Freudenberger /** 154f1b0a434SHarald Freudenberger * ap_pqap_zapq(): Reset and zeroize adjunct processor queue. 155f1b0a434SHarald Freudenberger * @qid: The AP queue number 156f1b0a434SHarald Freudenberger * 157f1b0a434SHarald Freudenberger * Returns AP queue status structure. 158f1b0a434SHarald Freudenberger */ 159f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_zapq(ap_qid_t qid) 160f1b0a434SHarald Freudenberger { 161b9639b31SHeiko Carstens unsigned long reg0 = qid | (2UL << 24); /* fc 2UL is ZAPQ */ 162*ebf95e88SHarald Freudenberger union ap_queue_status_reg reg1; 163f1b0a434SHarald Freudenberger 164f1b0a434SHarald Freudenberger asm volatile( 165b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* qid arg into gr0 */ 1662d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(ZAPQ) */ 167b9639b31SHeiko Carstens " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 168*ebf95e88SHarald Freudenberger : [reg1] "=&d" (reg1.value) 169b9639b31SHeiko Carstens : [reg0] "d" (reg0) 170b9639b31SHeiko Carstens : "cc", "0", "1"); 171*ebf95e88SHarald Freudenberger return reg1.status; 172f1b0a434SHarald Freudenberger } 173f1b0a434SHarald Freudenberger 174f1b0a434SHarald Freudenberger /** 175f1b0a434SHarald Freudenberger * struct ap_config_info - convenience struct for AP crypto 176f1b0a434SHarald Freudenberger * config info as returned by the ap_qci() function. 177f1b0a434SHarald Freudenberger */ 178050349b5SHarald Freudenberger struct ap_config_info { 179050349b5SHarald Freudenberger unsigned int apsc : 1; /* S bit */ 180050349b5SHarald Freudenberger unsigned int apxa : 1; /* N bit */ 181050349b5SHarald Freudenberger unsigned int qact : 1; /* C bit */ 182050349b5SHarald Freudenberger unsigned int rc8a : 1; /* R bit */ 183050349b5SHarald Freudenberger unsigned char _reserved1 : 4; 184050349b5SHarald Freudenberger unsigned char _reserved2[3]; 185050349b5SHarald Freudenberger unsigned char Na; /* max # of APs - 1 */ 186050349b5SHarald Freudenberger unsigned char Nd; /* max # of Domains - 1 */ 187050349b5SHarald Freudenberger unsigned char _reserved3[10]; 188050349b5SHarald Freudenberger unsigned int apm[8]; /* AP ID mask */ 1897379e652SHarald Freudenberger unsigned int aqm[8]; /* AP (usage) queue mask */ 1907379e652SHarald Freudenberger unsigned int adm[8]; /* AP (control) domain mask */ 191050349b5SHarald Freudenberger unsigned char _reserved4[16]; 192050349b5SHarald Freudenberger } __aligned(8); 193050349b5SHarald Freudenberger 194f1b0a434SHarald Freudenberger /** 195f1b0a434SHarald Freudenberger * ap_qci(): Get AP configuration data 196050349b5SHarald Freudenberger * 197f1b0a434SHarald Freudenberger * Returns 0 on success, or -EOPNOTSUPP. 198050349b5SHarald Freudenberger */ 199f1b0a434SHarald Freudenberger static inline int ap_qci(struct ap_config_info *config) 200f1b0a434SHarald Freudenberger { 201b9639b31SHeiko Carstens unsigned long reg0 = 4UL << 24; /* fc 4UL is QCI */ 202b9639b31SHeiko Carstens unsigned long reg1 = -EOPNOTSUPP; 203b9639b31SHeiko Carstens struct ap_config_info *reg2 = config; 204f1b0a434SHarald Freudenberger 205f1b0a434SHarald Freudenberger asm volatile( 206b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* QCI fc into gr0 */ 207b9639b31SHeiko Carstens " lgr 2,%[reg2]\n" /* ptr to config into gr2 */ 2082d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(QCI) */ 209b9639b31SHeiko Carstens "0: la %[reg1],0\n" /* good case, QCI fc available */ 210f1b0a434SHarald Freudenberger "1:\n" 211f1b0a434SHarald Freudenberger EX_TABLE(0b, 1b) 212b9639b31SHeiko Carstens : [reg1] "+&d" (reg1) 213b9639b31SHeiko Carstens : [reg0] "d" (reg0), [reg2] "d" (reg2) 214b9639b31SHeiko Carstens : "cc", "memory", "0", "2"); 215f1b0a434SHarald Freudenberger 216f1b0a434SHarald Freudenberger return reg1; 217f1b0a434SHarald Freudenberger } 218050349b5SHarald Freudenberger 21946fde9a9SHarald Freudenberger /* 22046fde9a9SHarald Freudenberger * struct ap_qirq_ctrl - convenient struct for easy invocation 221f1b0a434SHarald Freudenberger * of the ap_aqic() function. This struct is passed as GR1 222f1b0a434SHarald Freudenberger * parameter to the PQAP(AQIC) instruction. For details please 223f1b0a434SHarald Freudenberger * see the AR documentation. 22446fde9a9SHarald Freudenberger */ 225*ebf95e88SHarald Freudenberger union ap_qirq_ctrl { 226*ebf95e88SHarald Freudenberger unsigned long value; 227*ebf95e88SHarald Freudenberger struct { 228*ebf95e88SHarald Freudenberger unsigned int : 8; 22946fde9a9SHarald Freudenberger unsigned int zone : 8; /* zone info */ 23046fde9a9SHarald Freudenberger unsigned int ir : 1; /* ir flag: enable (1) or disable (0) irq */ 231*ebf95e88SHarald Freudenberger unsigned int : 4; 23246fde9a9SHarald Freudenberger unsigned int gisc : 3; /* guest isc field */ 233*ebf95e88SHarald Freudenberger unsigned int : 6; 23446fde9a9SHarald Freudenberger unsigned int gf : 2; /* gisa format */ 235*ebf95e88SHarald Freudenberger unsigned int : 1; 23646fde9a9SHarald Freudenberger unsigned int gisa : 27; /* gisa origin */ 237*ebf95e88SHarald Freudenberger unsigned int : 1; 23846fde9a9SHarald Freudenberger unsigned int isc : 3; /* irq sub class */ 23946fde9a9SHarald Freudenberger }; 240*ebf95e88SHarald Freudenberger }; 24146fde9a9SHarald Freudenberger 24246fde9a9SHarald Freudenberger /** 243f1b0a434SHarald Freudenberger * ap_aqic(): Control interruption for a specific AP. 24446fde9a9SHarald Freudenberger * @qid: The AP queue number 245f1b0a434SHarald Freudenberger * @qirqctrl: struct ap_qirq_ctrl (64 bit value) 24610e19d49SNicolin Chen * @pa_ind: Physical address of the notification indicator byte 24746fde9a9SHarald Freudenberger * 24846fde9a9SHarald Freudenberger * Returns AP queue status. 24946fde9a9SHarald Freudenberger */ 250f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_aqic(ap_qid_t qid, 251*ebf95e88SHarald Freudenberger union ap_qirq_ctrl qirqctrl, 25210e19d49SNicolin Chen phys_addr_t pa_ind) 253f1b0a434SHarald Freudenberger { 254b9639b31SHeiko Carstens unsigned long reg0 = qid | (3UL << 24); /* fc 3UL is AQIC */ 255*ebf95e88SHarald Freudenberger union ap_queue_status_reg reg1; 25610e19d49SNicolin Chen unsigned long reg2 = pa_ind; 257f1b0a434SHarald Freudenberger 258*ebf95e88SHarald Freudenberger reg1.value = qirqctrl.value; 259159491f3SHarald Freudenberger 260f1b0a434SHarald Freudenberger asm volatile( 261b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* qid param into gr0 */ 262b9639b31SHeiko Carstens " lgr 1,%[reg1]\n" /* irq ctrl into gr1 */ 263b9639b31SHeiko Carstens " lgr 2,%[reg2]\n" /* ni addr into gr2 */ 2642d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(AQIC) */ 265b9639b31SHeiko Carstens " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 266*ebf95e88SHarald Freudenberger : [reg1] "+&d" (reg1.value) 267b9639b31SHeiko Carstens : [reg0] "d" (reg0), [reg2] "d" (reg2) 268394740d7SHalil Pasic : "cc", "memory", "0", "1", "2"); 269159491f3SHarald Freudenberger 270159491f3SHarald Freudenberger return reg1.status; 271f1b0a434SHarald Freudenberger } 272f1b0a434SHarald Freudenberger 273f1b0a434SHarald Freudenberger /* 274f1b0a434SHarald Freudenberger * union ap_qact_ap_info - used together with the 275f1b0a434SHarald Freudenberger * ap_aqic() function to provide a convenient way 276f1b0a434SHarald Freudenberger * to handle the ap info needed by the qact function. 277f1b0a434SHarald Freudenberger */ 278f1b0a434SHarald Freudenberger union ap_qact_ap_info { 279f1b0a434SHarald Freudenberger unsigned long val; 280f1b0a434SHarald Freudenberger struct { 281f1b0a434SHarald Freudenberger unsigned int : 3; 282f1b0a434SHarald Freudenberger unsigned int mode : 3; 283f1b0a434SHarald Freudenberger unsigned int : 26; 284f1b0a434SHarald Freudenberger unsigned int cat : 8; 285f1b0a434SHarald Freudenberger unsigned int : 8; 286f1b0a434SHarald Freudenberger unsigned char ver[2]; 287f1b0a434SHarald Freudenberger }; 288f1b0a434SHarald Freudenberger }; 289f1b0a434SHarald Freudenberger 290f1b0a434SHarald Freudenberger /** 291f1b0a434SHarald Freudenberger * ap_qact(): Query AP combatibility type. 292f1b0a434SHarald Freudenberger * @qid: The AP queue number 293f1b0a434SHarald Freudenberger * @apinfo: On input the info about the AP queue. On output the 294f1b0a434SHarald Freudenberger * alternate AP queue info provided by the qact function 295f1b0a434SHarald Freudenberger * in GR2 is stored in. 296f1b0a434SHarald Freudenberger * 297f1b0a434SHarald Freudenberger * Returns AP queue status. Check response_code field for failures. 298f1b0a434SHarald Freudenberger */ 299f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_qact(ap_qid_t qid, int ifbit, 300f1b0a434SHarald Freudenberger union ap_qact_ap_info *apinfo) 301f1b0a434SHarald Freudenberger { 302b9639b31SHeiko Carstens unsigned long reg0 = qid | (5UL << 24) | ((ifbit & 0x01) << 22); 303*ebf95e88SHarald Freudenberger union ap_queue_status_reg reg1; 304b9639b31SHeiko Carstens unsigned long reg2; 305f1b0a434SHarald Freudenberger 306159491f3SHarald Freudenberger reg1.value = apinfo->val; 307159491f3SHarald Freudenberger 308f1b0a434SHarald Freudenberger asm volatile( 309b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* qid param into gr0 */ 310b9639b31SHeiko Carstens " lgr 1,%[reg1]\n" /* qact in info into gr1 */ 3112d6c0008SHeiko Carstens " .insn rre,0xb2af0000,0,0\n" /* PQAP(QACT) */ 312b9639b31SHeiko Carstens " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 313b9639b31SHeiko Carstens " lgr %[reg2],2\n" /* qact out info into reg2 */ 314*ebf95e88SHarald Freudenberger : [reg1] "+&d" (reg1.value), [reg2] "=&d" (reg2) 315b9639b31SHeiko Carstens : [reg0] "d" (reg0) 316b9639b31SHeiko Carstens : "cc", "0", "1", "2"); 317f1b0a434SHarald Freudenberger apinfo->val = reg2; 318159491f3SHarald Freudenberger return reg1.status; 319f1b0a434SHarald Freudenberger } 320f1b0a434SHarald Freudenberger 321f1b0a434SHarald Freudenberger /** 322f1b0a434SHarald Freudenberger * ap_nqap(): Send message to adjunct processor queue. 323f1b0a434SHarald Freudenberger * @qid: The AP queue number 324f1b0a434SHarald Freudenberger * @psmid: The program supplied message identifier 325f1b0a434SHarald Freudenberger * @msg: The message text 326f1b0a434SHarald Freudenberger * @length: The message length 327f1b0a434SHarald Freudenberger * 328f1b0a434SHarald Freudenberger * Returns AP queue status structure. 329f1b0a434SHarald Freudenberger * Condition code 1 on NQAP can't happen because the L bit is 1. 330f1b0a434SHarald Freudenberger * Condition code 2 on NQAP also means the send is incomplete, 331f1b0a434SHarald Freudenberger * because a segment boundary was reached. The NQAP is repeated. 332f1b0a434SHarald Freudenberger */ 333f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_nqap(ap_qid_t qid, 334f1b0a434SHarald Freudenberger unsigned long long psmid, 335f1b0a434SHarald Freudenberger void *msg, size_t length) 336f1b0a434SHarald Freudenberger { 337b9639b31SHeiko Carstens unsigned long reg0 = qid | 0x40000000UL; /* 0x4... is last msg part */ 338b9639b31SHeiko Carstens union register_pair nqap_r1, nqap_r2; 339*ebf95e88SHarald Freudenberger union ap_queue_status_reg reg1; 340b9639b31SHeiko Carstens 341b9639b31SHeiko Carstens nqap_r1.even = (unsigned int)(psmid >> 32); 342b9639b31SHeiko Carstens nqap_r1.odd = psmid & 0xffffffff; 343b9639b31SHeiko Carstens nqap_r2.even = (unsigned long)msg; 344b9639b31SHeiko Carstens nqap_r2.odd = (unsigned long)length; 345f1b0a434SHarald Freudenberger 346f1b0a434SHarald Freudenberger asm volatile ( 347b9639b31SHeiko Carstens " lgr 0,%[reg0]\n" /* qid param in gr0 */ 348b9639b31SHeiko Carstens "0: .insn rre,0xb2ad0000,%[nqap_r1],%[nqap_r2]\n" 349b9639b31SHeiko Carstens " brc 2,0b\n" /* handle partial completion */ 350b9639b31SHeiko Carstens " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 351*ebf95e88SHarald Freudenberger : [reg0] "+&d" (reg0), [reg1] "=&d" (reg1.value), 352b9639b31SHeiko Carstens [nqap_r2] "+&d" (nqap_r2.pair) 353b9639b31SHeiko Carstens : [nqap_r1] "d" (nqap_r1.pair) 354b9639b31SHeiko Carstens : "cc", "memory", "0", "1"); 355*ebf95e88SHarald Freudenberger return reg1.status; 356f1b0a434SHarald Freudenberger } 357f1b0a434SHarald Freudenberger 358f1b0a434SHarald Freudenberger /** 359f1b0a434SHarald Freudenberger * ap_dqap(): Receive message from adjunct processor queue. 360f1b0a434SHarald Freudenberger * @qid: The AP queue number 361f1b0a434SHarald Freudenberger * @psmid: Pointer to program supplied message identifier 362f1b0a434SHarald Freudenberger * @msg: The message text 363f1b0a434SHarald Freudenberger * @length: The message length 3641f0d22deSHarald Freudenberger * @reslength: Resitual length on return 3651f0d22deSHarald Freudenberger * @resgr0: input: gr0 value (only used if != 0), output: resitual gr0 content 366f1b0a434SHarald Freudenberger * 367f1b0a434SHarald Freudenberger * Returns AP queue status structure. 368f1b0a434SHarald Freudenberger * Condition code 1 on DQAP means the receive has taken place 369f1b0a434SHarald Freudenberger * but only partially. The response is incomplete, hence the 370f1b0a434SHarald Freudenberger * DQAP is repeated. 371f1b0a434SHarald Freudenberger * Condition code 2 on DQAP also means the receive is incomplete, 372f1b0a434SHarald Freudenberger * this time because a segment boundary was reached. Again, the 373f1b0a434SHarald Freudenberger * DQAP is repeated. 374f1b0a434SHarald Freudenberger * Note that gpr2 is used by the DQAP instruction to keep track of 375f1b0a434SHarald Freudenberger * any 'residual' length, in case the instruction gets interrupted. 376f1b0a434SHarald Freudenberger * Hence it gets zeroed before the instruction. 3771f0d22deSHarald Freudenberger * If the message does not fit into the buffer, this function will 3781f0d22deSHarald Freudenberger * return with a truncated message and the reply in the firmware queue 3791f0d22deSHarald Freudenberger * is not removed. This is indicated to the caller with an 3801f0d22deSHarald Freudenberger * ap_queue_status response_code value of all bits on (0xFF) and (if 3811f0d22deSHarald Freudenberger * the reslength ptr is given) the remaining length is stored in 3821f0d22deSHarald Freudenberger * *reslength and (if the resgr0 ptr is given) the updated gr0 value 3831f0d22deSHarald Freudenberger * for further processing of this msg entry is stored in *resgr0. The 3841f0d22deSHarald Freudenberger * caller needs to detect this situation and should invoke ap_dqap 3851f0d22deSHarald Freudenberger * with a valid resgr0 ptr and a value in there != 0 to indicate that 3861f0d22deSHarald Freudenberger * *resgr0 is to be used instead of qid to further process this entry. 387f1b0a434SHarald Freudenberger */ 388f1b0a434SHarald Freudenberger static inline struct ap_queue_status ap_dqap(ap_qid_t qid, 389f1b0a434SHarald Freudenberger unsigned long long *psmid, 3901f0d22deSHarald Freudenberger void *msg, size_t length, 3911f0d22deSHarald Freudenberger size_t *reslength, 3921f0d22deSHarald Freudenberger unsigned long *resgr0) 393f1b0a434SHarald Freudenberger { 3944516f355SHarald Freudenberger unsigned long reg0 = resgr0 && *resgr0 ? *resgr0 : qid | 0x80000000UL; 395*ebf95e88SHarald Freudenberger union ap_queue_status_reg reg1; 3964516f355SHarald Freudenberger unsigned long reg2; 3974516f355SHarald Freudenberger union register_pair rp1, rp2; 3984516f355SHarald Freudenberger 3994516f355SHarald Freudenberger rp1.even = 0UL; 4004516f355SHarald Freudenberger rp1.odd = 0UL; 4014516f355SHarald Freudenberger rp2.even = (unsigned long)msg; 4024516f355SHarald Freudenberger rp2.odd = (unsigned long)length; 403f1b0a434SHarald Freudenberger 404f1b0a434SHarald Freudenberger asm volatile( 4054516f355SHarald Freudenberger " lgr 0,%[reg0]\n" /* qid param into gr0 */ 4064516f355SHarald Freudenberger " lghi 2,0\n" /* 0 into gr2 (res length) */ 4074516f355SHarald Freudenberger "0: ltgr %N[rp2],%N[rp2]\n" /* check buf len */ 4084516f355SHarald Freudenberger " jz 2f\n" /* go out if buf len is 0 */ 4094516f355SHarald Freudenberger "1: .insn rre,0xb2ae0000,%[rp1],%[rp2]\n" 4104516f355SHarald Freudenberger " brc 6,0b\n" /* handle partial complete */ 4114516f355SHarald Freudenberger "2: lgr %[reg0],0\n" /* gr0 (qid + info) into reg0 */ 4124516f355SHarald Freudenberger " lgr %[reg1],1\n" /* gr1 (status) into reg1 */ 4134516f355SHarald Freudenberger " lgr %[reg2],2\n" /* gr2 (res length) into reg2 */ 414*ebf95e88SHarald Freudenberger : [reg0] "+&d" (reg0), [reg1] "=&d" (reg1.value), 415*ebf95e88SHarald Freudenberger [reg2] "=&d" (reg2), [rp1] "+&d" (rp1.pair), 416*ebf95e88SHarald Freudenberger [rp2] "+&d" (rp2.pair) 4174516f355SHarald Freudenberger : 4184516f355SHarald Freudenberger : "cc", "memory", "0", "1", "2"); 4191f0d22deSHarald Freudenberger 4201f0d22deSHarald Freudenberger if (reslength) 4211f0d22deSHarald Freudenberger *reslength = reg2; 4224516f355SHarald Freudenberger if (reg2 != 0 && rp2.odd == 0) { 4231f0d22deSHarald Freudenberger /* 4241f0d22deSHarald Freudenberger * Partially complete, status in gr1 is not set. 4251f0d22deSHarald Freudenberger * Signal the caller that this dqap is only partially received 4261f0d22deSHarald Freudenberger * with a special status response code 0xFF and *resgr0 updated 4271f0d22deSHarald Freudenberger */ 428*ebf95e88SHarald Freudenberger reg1.status.response_code = 0xFF; 4291f0d22deSHarald Freudenberger if (resgr0) 4301f0d22deSHarald Freudenberger *resgr0 = reg0; 4311f0d22deSHarald Freudenberger } else { 4324516f355SHarald Freudenberger *psmid = (((unsigned long long)rp1.even) << 32) + rp1.odd; 4331f0d22deSHarald Freudenberger if (resgr0) 4341f0d22deSHarald Freudenberger *resgr0 = 0; 4351f0d22deSHarald Freudenberger } 4361f0d22deSHarald Freudenberger 437*ebf95e88SHarald Freudenberger return reg1.status; 438f1b0a434SHarald Freudenberger } 43946fde9a9SHarald Freudenberger 4400d9c038fSTony Krowiak /* 4410d9c038fSTony Krowiak * Interface to tell the AP bus code that a configuration 4420d9c038fSTony Krowiak * change has happened. The bus code should at least do 4430d9c038fSTony Krowiak * an ap bus resource rescan. 4440d9c038fSTony Krowiak */ 4450d9c038fSTony Krowiak #if IS_ENABLED(CONFIG_ZCRYPT) 4460d9c038fSTony Krowiak void ap_bus_cfg_chg(void); 4470d9c038fSTony Krowiak #else 448d09cb482SChengyang Fan static inline void ap_bus_cfg_chg(void){} 4490d9c038fSTony Krowiak #endif 4500d9c038fSTony Krowiak 451e7fc5146STony Krowiak #endif /* _ASM_S390_AP_H_ */ 452