blob: 4f365bff275c7881472ad1173bf01b1cc2bcd633 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Cornelia Huck4beb3702005-05-01 08:58:59 -07002 * linux/drivers/s390/block/dasd_cmb.c ($Revision: 1.9 $)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Linux on zSeries Channel Measurement Facility support
5 * (dasd device driver interface)
6 *
7 * Copyright 2000,2003 IBM Corporation
8 *
9 * Author: Arnd Bergmann <arndb@de.ibm.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/module.h>
27#include <asm/ccwdev.h>
28#include <asm/cmb.h>
29
30#include "dasd_int.h"
31
32static int
33dasd_ioctl_cmf_enable(struct block_device *bdev, int no, long args)
34{
35 struct dasd_device *device;
36
37 device = bdev->bd_disk->private_data;
38 if (!device)
39 return -EINVAL;
40
41 return enable_cmf(device->cdev);
42}
43
44static int
45dasd_ioctl_cmf_disable(struct block_device *bdev, int no, long args)
46{
47 struct dasd_device *device;
48
49 device = bdev->bd_disk->private_data;
50 if (!device)
51 return -EINVAL;
52
53 return disable_cmf(device->cdev);
54}
55
56static int
57dasd_ioctl_readall_cmb(struct block_device *bdev, int no, long args)
58{
59 struct dasd_device *device;
60 struct cmbdata __user *udata;
61 struct cmbdata data;
62 size_t size;
63 int ret;
64
65 device = bdev->bd_disk->private_data;
66 if (!device)
67 return -EINVAL;
68 udata = (void __user *) args;
69 size = _IOC_SIZE(no);
70
71 if (!access_ok(VERIFY_WRITE, udata, size))
72 return -EFAULT;
73 ret = cmf_readall(device->cdev, &data);
74 if (ret)
75 return ret;
76 if (copy_to_user(udata, &data, min(size, sizeof(*udata))))
77 return -EFAULT;
78 return 0;
79}
80
81/* module initialization below here. dasd already provides a mechanism
82 * to dynamically register ioctl functions, so we simply use this. */
83static inline int
84ioctl_reg(unsigned int no, dasd_ioctl_fn_t handler)
85{
Cornelia Huck4beb3702005-05-01 08:58:59 -070086 return dasd_ioctl_no_register(THIS_MODULE, no, handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087}
88
89static inline void
90ioctl_unreg(unsigned int no, dasd_ioctl_fn_t handler)
91{
92 dasd_ioctl_no_unregister(THIS_MODULE, no, handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093}
94
95static void
96dasd_cmf_exit(void)
97{
98 ioctl_unreg(BIODASDCMFENABLE, dasd_ioctl_cmf_enable);
99 ioctl_unreg(BIODASDCMFDISABLE, dasd_ioctl_cmf_disable);
100 ioctl_unreg(BIODASDREADALLCMB, dasd_ioctl_readall_cmb);
101}
102
103static int __init
104dasd_cmf_init(void)
105{
106 int ret;
107 ret = ioctl_reg (BIODASDCMFENABLE, dasd_ioctl_cmf_enable);
108 if (ret)
109 goto err;
110 ret = ioctl_reg (BIODASDCMFDISABLE, dasd_ioctl_cmf_disable);
111 if (ret)
112 goto err;
113 ret = ioctl_reg (BIODASDREADALLCMB, dasd_ioctl_readall_cmb);
114 if (ret)
115 goto err;
116
117 return 0;
118err:
119 dasd_cmf_exit();
120
121 return ret;
122}
123
124module_init(dasd_cmf_init);
125module_exit(dasd_cmf_exit);
126
127MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
128MODULE_LICENSE("GPL");
129MODULE_DESCRIPTION("channel measurement facility interface for dasd\n"
130 "Copyright 2003 IBM Corporation\n");