18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * s390 crypto adapter related sclp functions. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright IBM Corp. 2020 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci#define KMSG_COMPONENT "sclp_cmd" 88c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/export.h> 118c2ecf20Sopenharmony_ci#include <linux/slab.h> 128c2ecf20Sopenharmony_ci#include <asm/sclp.h> 138c2ecf20Sopenharmony_ci#include "sclp.h" 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define SCLP_CMDW_CONFIGURE_AP 0x001f0001 168c2ecf20Sopenharmony_ci#define SCLP_CMDW_DECONFIGURE_AP 0x001e0001 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistruct ap_cfg_sccb { 198c2ecf20Sopenharmony_ci struct sccb_header header; 208c2ecf20Sopenharmony_ci} __packed; 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cistatic int do_ap_configure(sclp_cmdw_t cmd, u32 apid) 238c2ecf20Sopenharmony_ci{ 248c2ecf20Sopenharmony_ci struct ap_cfg_sccb *sccb; 258c2ecf20Sopenharmony_ci int rc; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci if (!SCLP_HAS_AP_RECONFIG) 288c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci sccb = (struct ap_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA); 318c2ecf20Sopenharmony_ci if (!sccb) 328c2ecf20Sopenharmony_ci return -ENOMEM; 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci sccb->header.length = PAGE_SIZE; 358c2ecf20Sopenharmony_ci cmd |= (apid & 0xFF) << 8; 368c2ecf20Sopenharmony_ci rc = sclp_sync_request(cmd, sccb); 378c2ecf20Sopenharmony_ci if (rc) 388c2ecf20Sopenharmony_ci goto out; 398c2ecf20Sopenharmony_ci switch (sccb->header.response_code) { 408c2ecf20Sopenharmony_ci case 0x0020: case 0x0120: case 0x0440: case 0x0450: 418c2ecf20Sopenharmony_ci break; 428c2ecf20Sopenharmony_ci default: 438c2ecf20Sopenharmony_ci pr_warn("configure AP adapter %u failed: cmd=0x%08x response=0x%04x\n", 448c2ecf20Sopenharmony_ci apid, cmd, sccb->header.response_code); 458c2ecf20Sopenharmony_ci rc = -EIO; 468c2ecf20Sopenharmony_ci break; 478c2ecf20Sopenharmony_ci } 488c2ecf20Sopenharmony_ciout: 498c2ecf20Sopenharmony_ci free_page((unsigned long) sccb); 508c2ecf20Sopenharmony_ci return rc; 518c2ecf20Sopenharmony_ci} 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ciint sclp_ap_configure(u32 apid) 548c2ecf20Sopenharmony_ci{ 558c2ecf20Sopenharmony_ci return do_ap_configure(SCLP_CMDW_CONFIGURE_AP, apid); 568c2ecf20Sopenharmony_ci} 578c2ecf20Sopenharmony_ciEXPORT_SYMBOL(sclp_ap_configure); 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ciint sclp_ap_deconfigure(u32 apid) 608c2ecf20Sopenharmony_ci{ 618c2ecf20Sopenharmony_ci return do_ap_configure(SCLP_CMDW_DECONFIGURE_AP, apid); 628c2ecf20Sopenharmony_ci} 638c2ecf20Sopenharmony_ciEXPORT_SYMBOL(sclp_ap_deconfigure); 64