| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* |
| 3 |
* s390 crypto adapter related sclp functions. |
| 4 |
* |
| 5 |
* Copyright IBM Corp. 2020 |
| 6 |
*/ |
| 7 |
#define pr_fmt(fmt) "sclp_cmd: " fmt |
| 8 |
|
| 9 |
#include <linux/export.h> |
| 10 |
#include <linux/slab.h> |
| 11 |
#include <asm/sclp.h> |
| 12 |
#include "sclp.h" |
| 13 |
|
| 14 |
#define SCLP_CMDW_CONFIGURE_AP 0x001f0001 |
| 15 |
#define SCLP_CMDW_DECONFIGURE_AP 0x001e0001 |
| 16 |
|
| 17 |
struct ap_cfg_sccb { |
| 18 |
struct sccb_header header; |
| 19 |
} __packed; |
| 20 |
|
| 21 |
static int do_ap_configure(sclp_cmdw_t cmd, u32 apid) |
| 22 |
{ |
| 23 |
struct ap_cfg_sccb *sccb; |
| 24 |
int rc; |
| 25 |
|
| 26 |
if (!SCLP_HAS_AP_RECONFIG) |
| 27 |
return -EOPNOTSUPP; |
| 28 |
|
| 29 |
sccb = (struct ap_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA); |
| 30 |
if (!sccb) |
| 31 |
return -ENOMEM; |
| 32 |
|
| 33 |
sccb->header.length = PAGE_SIZE; |
| 34 |
cmd |= (apid & 0xFF) << 8; |
| 35 |
rc = sclp_sync_request(cmd, sccb); |
| 36 |
if (rc) |
| 37 |
goto out; |
| 38 |
switch (sccb->header.response_code) { |
| 39 |
case 0x0020: case 0x0120: case 0x0440: case 0x0450: |
| 40 |
break; |
| 41 |
default: |
| 42 |
pr_warn("configure AP adapter %u failed: cmd=0x%08x response=0x%04x\n", |
| 43 |
apid, cmd, sccb->header.response_code); |
| 44 |
rc = -EIO; |
| 45 |
break; |
| 46 |
} |
| 47 |
out: |
| 48 |
free_page((unsigned long) sccb); |
| 49 |
return rc; |
| 50 |
} |
| 51 |
|
| 52 |
int sclp_ap_configure(u32 apid) |
| 53 |
{ |
| 54 |
return do_ap_configure(SCLP_CMDW_CONFIGURE_AP, apid); |
| 55 |
} |
| 56 |
EXPORT_SYMBOL(sclp_ap_configure); |
| 57 |
|
| 58 |
int sclp_ap_deconfigure(u32 apid) |
| 59 |
{ |
| 60 |
return do_ap_configure(SCLP_CMDW_DECONFIGURE_AP, apid); |
| 61 |
} |
| 62 |
EXPORT_SYMBOL(sclp_ap_deconfigure); |