xref: /openbmc/linux/drivers/s390/char/sclp_ap.c (revision b4e18b29)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * s390 crypto adapter related sclp functions.
4  *
5  * Copyright IBM Corp. 2020
6  */
7 #define KMSG_COMPONENT "sclp_cmd"
8 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
9 
10 #include <linux/export.h>
11 #include <linux/slab.h>
12 #include <asm/sclp.h>
13 #include "sclp.h"
14 
15 #define SCLP_CMDW_CONFIGURE_AP			0x001f0001
16 #define SCLP_CMDW_DECONFIGURE_AP		0x001e0001
17 
18 struct ap_cfg_sccb {
19 	struct sccb_header header;
20 } __packed;
21 
22 static int do_ap_configure(sclp_cmdw_t cmd, u32 apid)
23 {
24 	struct ap_cfg_sccb *sccb;
25 	int rc;
26 
27 	if (!SCLP_HAS_AP_RECONFIG)
28 		return -EOPNOTSUPP;
29 
30 	sccb = (struct ap_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
31 	if (!sccb)
32 		return -ENOMEM;
33 
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;
47 	}
48 out:
49 	free_page((unsigned long) sccb);
50 	return rc;
51 }
52 
53 int sclp_ap_configure(u32 apid)
54 {
55 	return do_ap_configure(SCLP_CMDW_CONFIGURE_AP, apid);
56 }
57 EXPORT_SYMBOL(sclp_ap_configure);
58 
59 int sclp_ap_deconfigure(u32 apid)
60 {
61 	return do_ap_configure(SCLP_CMDW_DECONFIGURE_AP, apid);
62 }
63 EXPORT_SYMBOL(sclp_ap_deconfigure);
64