scm_drv.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Device driver for s390 storage class memory.
  3. *
  4. * Copyright IBM Corp. 2012
  5. * Author(s): Sebastian Ott <sebott@linux.vnet.ibm.com>
  6. */
  7. #define KMSG_COMPONENT "scm_block"
  8. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  9. #include <linux/module.h>
  10. #include <linux/slab.h>
  11. #include <asm/eadm.h>
  12. #include "scm_blk.h"
  13. static void notify(struct scm_device *scmdev)
  14. {
  15. pr_info("%lu: The capabilities of the SCM increment changed\n",
  16. (unsigned long) scmdev->address);
  17. SCM_LOG(2, "State changed");
  18. SCM_LOG_STATE(2, scmdev);
  19. }
  20. static int scm_probe(struct scm_device *scmdev)
  21. {
  22. struct scm_blk_dev *bdev;
  23. int ret;
  24. SCM_LOG(2, "probe");
  25. SCM_LOG_STATE(2, scmdev);
  26. if (scmdev->attrs.oper_state != OP_STATE_GOOD)
  27. return -EINVAL;
  28. bdev = kzalloc(sizeof(*bdev), GFP_KERNEL);
  29. if (!bdev)
  30. return -ENOMEM;
  31. dev_set_drvdata(&scmdev->dev, bdev);
  32. ret = scm_blk_dev_setup(bdev, scmdev);
  33. if (ret) {
  34. dev_set_drvdata(&scmdev->dev, NULL);
  35. kfree(bdev);
  36. goto out;
  37. }
  38. out:
  39. return ret;
  40. }
  41. static int scm_remove(struct scm_device *scmdev)
  42. {
  43. struct scm_blk_dev *bdev = dev_get_drvdata(&scmdev->dev);
  44. scm_blk_dev_cleanup(bdev);
  45. dev_set_drvdata(&scmdev->dev, NULL);
  46. kfree(bdev);
  47. return 0;
  48. }
  49. static struct scm_driver scm_drv = {
  50. .drv = {
  51. .name = "scm_block",
  52. .owner = THIS_MODULE,
  53. },
  54. .notify = notify,
  55. .probe = scm_probe,
  56. .remove = scm_remove,
  57. .handler = scm_blk_irq,
  58. };
  59. int __init scm_drv_init(void)
  60. {
  61. return scm_driver_register(&scm_drv);
  62. }
  63. void scm_drv_cleanup(void)
  64. {
  65. scm_driver_unregister(&scm_drv);
  66. }