blob: 3134fd6e058e7fe8801894b61e5ddaf04e822a6c [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Sebastian Ottf30664e2012-08-28 16:50:38 +02002/*
3 * Device driver for s390 storage class memory.
4 *
5 * Copyright IBM Corp. 2012
6 * Author(s): Sebastian Ott <sebott@linux.vnet.ibm.com>
7 */
8
9#define KMSG_COMPONENT "scm_block"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
12#include <linux/module.h>
Sebastian Ottf30664e2012-08-28 16:50:38 +020013#include <linux/slab.h>
14#include <asm/eadm.h>
15#include "scm_blk.h"
16
Sebastian Ott93481c92013-02-28 12:07:38 +010017static void scm_notify(struct scm_device *scmdev, enum scm_event event)
Sebastian Ottf30664e2012-08-28 16:50:38 +020018{
Sebastian Ottaebfa662013-02-28 12:07:55 +010019 struct scm_blk_dev *bdev = dev_get_drvdata(&scmdev->dev);
20
Sebastian Ott93481c92013-02-28 12:07:38 +010021 switch (event) {
22 case SCM_CHANGE:
Sebastian Ott3bff6032013-03-18 16:01:30 +010023 pr_info("%lx: The capabilities of the SCM increment changed\n",
Sebastian Ott93481c92013-02-28 12:07:38 +010024 (unsigned long) scmdev->address);
25 SCM_LOG(2, "State changed");
26 SCM_LOG_STATE(2, scmdev);
27 break;
Sebastian Ottaebfa662013-02-28 12:07:55 +010028 case SCM_AVAIL:
29 SCM_LOG(2, "Increment available");
30 SCM_LOG_STATE(2, scmdev);
31 scm_blk_set_available(bdev);
32 break;
Sebastian Ott93481c92013-02-28 12:07:38 +010033 }
Sebastian Ottf30664e2012-08-28 16:50:38 +020034}
35
36static int scm_probe(struct scm_device *scmdev)
37{
38 struct scm_blk_dev *bdev;
39 int ret;
40
41 SCM_LOG(2, "probe");
42 SCM_LOG_STATE(2, scmdev);
43
44 if (scmdev->attrs.oper_state != OP_STATE_GOOD)
45 return -EINVAL;
46
47 bdev = kzalloc(sizeof(*bdev), GFP_KERNEL);
48 if (!bdev)
49 return -ENOMEM;
50
Sebastian Ottf30664e2012-08-28 16:50:38 +020051 dev_set_drvdata(&scmdev->dev, bdev);
Sebastian Ottf30664e2012-08-28 16:50:38 +020052 ret = scm_blk_dev_setup(bdev, scmdev);
53 if (ret) {
Sebastian Ottf30664e2012-08-28 16:50:38 +020054 dev_set_drvdata(&scmdev->dev, NULL);
Sebastian Ottf30664e2012-08-28 16:50:38 +020055 kfree(bdev);
56 goto out;
57 }
58
59out:
60 return ret;
61}
62
63static int scm_remove(struct scm_device *scmdev)
64{
Sebastian Ottc3e6d402012-09-04 19:36:41 +020065 struct scm_blk_dev *bdev = dev_get_drvdata(&scmdev->dev);
Sebastian Ottf30664e2012-08-28 16:50:38 +020066
Sebastian Ottf30664e2012-08-28 16:50:38 +020067 scm_blk_dev_cleanup(bdev);
Sebastian Ott24996ed2012-09-04 19:37:51 +020068 dev_set_drvdata(&scmdev->dev, NULL);
Sebastian Ottf30664e2012-08-28 16:50:38 +020069 kfree(bdev);
70
71 return 0;
72}
73
74static struct scm_driver scm_drv = {
75 .drv = {
76 .name = "scm_block",
77 .owner = THIS_MODULE,
78 },
Sebastian Ott93481c92013-02-28 12:07:38 +010079 .notify = scm_notify,
Sebastian Ottf30664e2012-08-28 16:50:38 +020080 .probe = scm_probe,
81 .remove = scm_remove,
82 .handler = scm_blk_irq,
83};
84
85int __init scm_drv_init(void)
86{
87 return scm_driver_register(&scm_drv);
88}
89
90void scm_drv_cleanup(void)
91{
92 scm_driver_unregister(&scm_drv);
93}