blob: 2014fb7a4881f131052c79716e37f920dca4e156 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Cornelia Huck4ce3b302006-01-14 13:21:04 -08002 * $Id: cu3088.c,v 1.38 2006/01/12 14:33:09 cohuck Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * CTC / LCS ccw_device driver
5 *
6 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Arnd Bergmann <arndb@de.ibm.com>
Cornelia Huck4ce3b302006-01-14 13:21:04 -08008 * Cornelia Huck <cornelia.huck@de.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25
26#include <linux/init.h>
27#include <linux/module.h>
28#include <linux/err.h>
29
Carsten Ottecfb1b552006-01-06 00:19:14 -080030#include <asm/s390_rdev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <asm/ccwdev.h>
32#include <asm/ccwgroup.h>
33
34#include "cu3088.h"
35
36const char *cu3088_type[] = {
37 "not a channel",
38 "CTC/A",
39 "ESCON channel",
40 "FICON channel",
41 "P390 LCS card",
42 "OSA LCS card",
Frank Pavlic321de3c2005-05-12 20:17:46 +020043 "CLAW channel device",
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 "unknown channel type",
45 "unsupported channel type",
46};
47
48/* static definitions */
49
50static struct ccw_device_id cu3088_ids[] = {
51 { CCW_DEVICE(0x3088, 0x08), .driver_info = channel_type_parallel },
52 { CCW_DEVICE(0x3088, 0x1f), .driver_info = channel_type_escon },
53 { CCW_DEVICE(0x3088, 0x1e), .driver_info = channel_type_ficon },
54 { CCW_DEVICE(0x3088, 0x01), .driver_info = channel_type_p390 },
55 { CCW_DEVICE(0x3088, 0x60), .driver_info = channel_type_osa2 },
Frank Pavlic321de3c2005-05-12 20:17:46 +020056 { CCW_DEVICE(0x3088, 0x61), .driver_info = channel_type_claw },
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 { /* end of list */ }
58};
59
60static struct ccw_driver cu3088_driver;
61
62struct device *cu3088_root_dev;
63
64static ssize_t
65group_write(struct device_driver *drv, const char *buf, size_t count)
66{
67 const char *start, *end;
68 char bus_ids[2][BUS_ID_SIZE], *argv[2];
69 int i;
70 int ret;
71 struct ccwgroup_driver *cdrv;
72
73 cdrv = to_ccwgroupdrv(drv);
74 if (!cdrv)
75 return -EINVAL;
76 start = buf;
77 for (i=0; i<2; i++) {
78 static const char delim[] = {',', '\n'};
79 int len;
80
81 if (!(end = strchr(start, delim[i])))
82 return count;
83 len = min_t(ptrdiff_t, BUS_ID_SIZE, end - start + 1);
84 strlcpy (bus_ids[i], start, len);
85 argv[i] = bus_ids[i];
86 start = end + 1;
87 }
88
89 ret = ccwgroup_create(cu3088_root_dev, cdrv->driver_id,
90 &cu3088_driver, 2, argv);
91
92 return (ret == 0) ? count : ret;
93}
94
95static DRIVER_ATTR(group, 0200, NULL, group_write);
96
97/* Register-unregister for ctc&lcs */
98int
99register_cu3088_discipline(struct ccwgroup_driver *dcp)
100{
101 int rc;
102
103 if (!dcp)
104 return -EINVAL;
105
106 /* Register discipline.*/
107 rc = ccwgroup_driver_register(dcp);
108 if (rc)
109 return rc;
110
111 rc = driver_create_file(&dcp->driver, &driver_attr_group);
112 if (rc)
113 ccwgroup_driver_unregister(dcp);
114
115 return rc;
116
117}
118
119void
120unregister_cu3088_discipline(struct ccwgroup_driver *dcp)
121{
122 if (!dcp)
123 return;
124
125 driver_remove_file(&dcp->driver, &driver_attr_group);
126 ccwgroup_driver_unregister(dcp);
127}
128
129static struct ccw_driver cu3088_driver = {
130 .owner = THIS_MODULE,
131 .ids = cu3088_ids,
132 .name = "cu3088",
133 .probe = ccwgroup_probe_ccwdev,
134 .remove = ccwgroup_remove_ccwdev,
135};
136
137/* module setup */
138static int __init
139cu3088_init (void)
140{
141 int rc;
142
143 cu3088_root_dev = s390_root_dev_register("cu3088");
144 if (IS_ERR(cu3088_root_dev))
145 return PTR_ERR(cu3088_root_dev);
146 rc = ccw_driver_register(&cu3088_driver);
147 if (rc)
148 s390_root_dev_unregister(cu3088_root_dev);
149
150 return rc;
151}
152
153static void __exit
154cu3088_exit (void)
155{
156 ccw_driver_unregister(&cu3088_driver);
157 s390_root_dev_unregister(cu3088_root_dev);
158}
159
160MODULE_DEVICE_TABLE(ccw,cu3088_ids);
161MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
162MODULE_LICENSE("GPL");
163
164module_init(cu3088_init);
165module_exit(cu3088_exit);
166
167EXPORT_SYMBOL_GPL(cu3088_type);
168EXPORT_SYMBOL_GPL(register_cu3088_discipline);
169EXPORT_SYMBOL_GPL(unregister_cu3088_discipline);