blob: ff8558c4fe256c27fd28c3505b28d574c9adad66 [file] [log] [blame]
Sebastian Ottf30664e2012-08-28 16:50:38 +02001/*
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
8#define KMSG_COMPONENT "scm_block"
9#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
10
11#include <linux/module.h>
Sebastian Ottf30664e2012-08-28 16:50:38 +020012#include <linux/slab.h>
13#include <asm/eadm.h>
14#include "scm_blk.h"
15
Sebastian Ott93481c92013-02-28 12:07:38 +010016static void scm_notify(struct scm_device *scmdev, enum scm_event event)
Sebastian Ottf30664e2012-08-28 16:50:38 +020017{
Sebastian Ott93481c92013-02-28 12:07:38 +010018 switch (event) {
19 case SCM_CHANGE:
20 pr_info("%lu: The capabilities of the SCM increment changed\n",
21 (unsigned long) scmdev->address);
22 SCM_LOG(2, "State changed");
23 SCM_LOG_STATE(2, scmdev);
24 break;
25 }
Sebastian Ottf30664e2012-08-28 16:50:38 +020026}
27
28static int scm_probe(struct scm_device *scmdev)
29{
30 struct scm_blk_dev *bdev;
31 int ret;
32
33 SCM_LOG(2, "probe");
34 SCM_LOG_STATE(2, scmdev);
35
36 if (scmdev->attrs.oper_state != OP_STATE_GOOD)
37 return -EINVAL;
38
39 bdev = kzalloc(sizeof(*bdev), GFP_KERNEL);
40 if (!bdev)
41 return -ENOMEM;
42
Sebastian Ottf30664e2012-08-28 16:50:38 +020043 dev_set_drvdata(&scmdev->dev, bdev);
Sebastian Ottf30664e2012-08-28 16:50:38 +020044 ret = scm_blk_dev_setup(bdev, scmdev);
45 if (ret) {
Sebastian Ottf30664e2012-08-28 16:50:38 +020046 dev_set_drvdata(&scmdev->dev, NULL);
Sebastian Ottf30664e2012-08-28 16:50:38 +020047 kfree(bdev);
48 goto out;
49 }
50
51out:
52 return ret;
53}
54
55static int scm_remove(struct scm_device *scmdev)
56{
Sebastian Ottc3e6d402012-09-04 19:36:41 +020057 struct scm_blk_dev *bdev = dev_get_drvdata(&scmdev->dev);
Sebastian Ottf30664e2012-08-28 16:50:38 +020058
Sebastian Ottf30664e2012-08-28 16:50:38 +020059 scm_blk_dev_cleanup(bdev);
Sebastian Ott24996ed2012-09-04 19:37:51 +020060 dev_set_drvdata(&scmdev->dev, NULL);
Sebastian Ottf30664e2012-08-28 16:50:38 +020061 kfree(bdev);
62
63 return 0;
64}
65
66static struct scm_driver scm_drv = {
67 .drv = {
68 .name = "scm_block",
69 .owner = THIS_MODULE,
70 },
Sebastian Ott93481c92013-02-28 12:07:38 +010071 .notify = scm_notify,
Sebastian Ottf30664e2012-08-28 16:50:38 +020072 .probe = scm_probe,
73 .remove = scm_remove,
74 .handler = scm_blk_irq,
75};
76
77int __init scm_drv_init(void)
78{
79 return scm_driver_register(&scm_drv);
80}
81
82void scm_drv_cleanup(void)
83{
84 scm_driver_unregister(&scm_drv);
85}