Sebastian Ott | f30664e | 2012-08-28 16:50:38 +0200 | [diff] [blame^] | 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 | |
| 8 | #define KMSG_COMPONENT "scm_block" |
| 9 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/spinlock.h> |
| 13 | #include <linux/slab.h> |
| 14 | #include <asm/eadm.h> |
| 15 | #include "scm_blk.h" |
| 16 | |
| 17 | static void notify(struct scm_device *scmdev) |
| 18 | { |
| 19 | pr_info("%lu: The capabilities of the SCM increment changed\n", |
| 20 | (unsigned long) scmdev->address); |
| 21 | SCM_LOG(2, "State changed"); |
| 22 | SCM_LOG_STATE(2, scmdev); |
| 23 | } |
| 24 | |
| 25 | static int scm_probe(struct scm_device *scmdev) |
| 26 | { |
| 27 | struct scm_blk_dev *bdev; |
| 28 | int ret; |
| 29 | |
| 30 | SCM_LOG(2, "probe"); |
| 31 | SCM_LOG_STATE(2, scmdev); |
| 32 | |
| 33 | if (scmdev->attrs.oper_state != OP_STATE_GOOD) |
| 34 | return -EINVAL; |
| 35 | |
| 36 | bdev = kzalloc(sizeof(*bdev), GFP_KERNEL); |
| 37 | if (!bdev) |
| 38 | return -ENOMEM; |
| 39 | |
| 40 | spin_lock_irq(&scmdev->lock); |
| 41 | dev_set_drvdata(&scmdev->dev, bdev); |
| 42 | spin_unlock_irq(&scmdev->lock); |
| 43 | |
| 44 | ret = scm_blk_dev_setup(bdev, scmdev); |
| 45 | if (ret) { |
| 46 | spin_lock_irq(&scmdev->lock); |
| 47 | dev_set_drvdata(&scmdev->dev, NULL); |
| 48 | spin_unlock_irq(&scmdev->lock); |
| 49 | kfree(bdev); |
| 50 | goto out; |
| 51 | } |
| 52 | |
| 53 | out: |
| 54 | return ret; |
| 55 | } |
| 56 | |
| 57 | static int scm_remove(struct scm_device *scmdev) |
| 58 | { |
| 59 | struct scm_blk_dev *bdev; |
| 60 | |
| 61 | spin_lock_irq(&scmdev->lock); |
| 62 | bdev = dev_get_drvdata(&scmdev->dev); |
| 63 | dev_set_drvdata(&scmdev->dev, NULL); |
| 64 | spin_unlock_irq(&scmdev->lock); |
| 65 | scm_blk_dev_cleanup(bdev); |
| 66 | kfree(bdev); |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | static struct scm_driver scm_drv = { |
| 72 | .drv = { |
| 73 | .name = "scm_block", |
| 74 | .owner = THIS_MODULE, |
| 75 | }, |
| 76 | .notify = notify, |
| 77 | .probe = scm_probe, |
| 78 | .remove = scm_remove, |
| 79 | .handler = scm_blk_irq, |
| 80 | }; |
| 81 | |
| 82 | int __init scm_drv_init(void) |
| 83 | { |
| 84 | return scm_driver_register(&scm_drv); |
| 85 | } |
| 86 | |
| 87 | void scm_drv_cleanup(void) |
| 88 | { |
| 89 | scm_driver_unregister(&scm_drv); |
| 90 | } |