sclp_ap.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #include <linux/export.h>
  10. #include <linux/slab.h>
  11. #include <asm/sclp.h>
  12. #include "sclp.h"
  13. #define SCLP_CMDW_CONFIGURE_AP 0x001f0001
  14. #define SCLP_CMDW_DECONFIGURE_AP 0x001e0001
  15. struct ap_cfg_sccb {
  16. struct sccb_header header;
  17. } __packed;
  18. static int do_ap_configure(sclp_cmdw_t cmd, u32 apid)
  19. {
  20. struct ap_cfg_sccb *sccb;
  21. int rc;
  22. if (!SCLP_HAS_AP_RECONFIG)
  23. return -EOPNOTSUPP;
  24. sccb = (struct ap_cfg_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  25. if (!sccb)
  26. return -ENOMEM;
  27. sccb->header.length = PAGE_SIZE;
  28. cmd |= (apid & 0xFF) << 8;
  29. rc = sclp_sync_request(cmd, sccb);
  30. if (rc)
  31. goto out;
  32. switch (sccb->header.response_code) {
  33. case 0x0020: case 0x0120: case 0x0440: case 0x0450:
  34. break;
  35. default:
  36. pr_warn("configure AP adapter %u failed: cmd=0x%08x response=0x%04x\n",
  37. apid, cmd, sccb->header.response_code);
  38. rc = -EIO;
  39. break;
  40. }
  41. out:
  42. free_page((unsigned long) sccb);
  43. return rc;
  44. }
  45. int sclp_ap_configure(u32 apid)
  46. {
  47. return do_ap_configure(SCLP_CMDW_CONFIGURE_AP, apid);
  48. }
  49. EXPORT_SYMBOL(sclp_ap_configure);
  50. int sclp_ap_deconfigure(u32 apid)
  51. {
  52. return do_ap_configure(SCLP_CMDW_DECONFIGURE_AP, apid);
  53. }
  54. EXPORT_SYMBOL(sclp_ap_deconfigure);