Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / s390 / char / sclp_ap.c
blob0dd1ca7127950b1f9e320e67b28f58192a591945
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * s390 crypto adapter related sclp functions.
5 * Copyright IBM Corp. 2020
6 */
7 #define KMSG_COMPONENT "sclp_cmd"
8 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
10 #include <linux/export.h>
11 #include <linux/slab.h>
12 #include <asm/sclp.h>
13 #include "sclp.h"
15 #define SCLP_CMDW_CONFIGURE_AP 0x001f0001
16 #define SCLP_CMDW_DECONFIGURE_AP 0x001e0001
18 struct ap_cfg_sccb {
19 struct sccb_header header;
20 } __packed;
22 static int do_ap_configure(sclp_cmdw_t cmd, u32 apid)
24 struct ap_cfg_sccb *sccb;
25 int rc;
27 if (!SCLP_HAS_AP_RECONFIG)
28 return -EOPNOTSUPP;
30 sccb = (struct ap_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
31 if (!sccb)
32 return -ENOMEM;
34 sccb->header.length = PAGE_SIZE;
35 cmd |= (apid & 0xFF) << 8;
36 rc = sclp_sync_request(cmd, sccb);
37 if (rc)
38 goto out;
39 switch (sccb->header.response_code) {
40 case 0x0020: case 0x0120: case 0x0440: case 0x0450:
41 break;
42 default:
43 pr_warn("configure AP adapter %u failed: cmd=0x%08x response=0x%04x\n",
44 apid, cmd, sccb->header.response_code);
45 rc = -EIO;
46 break;
48 out:
49 free_page((unsigned long) sccb);
50 return rc;
53 int sclp_ap_configure(u32 apid)
55 return do_ap_configure(SCLP_CMDW_CONFIGURE_AP, apid);
57 EXPORT_SYMBOL(sclp_ap_configure);
59 int sclp_ap_deconfigure(u32 apid)
61 return do_ap_configure(SCLP_CMDW_DECONFIGURE_AP, apid);
63 EXPORT_SYMBOL(sclp_ap_deconfigure);