xref: /openbmc/linux/drivers/isdn/mISDN/core.c (revision 9467af61)
11802d0beSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
21b2b03f8SKarsten Keil /*
31b2b03f8SKarsten Keil  * Copyright 2008  by Karsten Keil <kkeil@novell.com>
41b2b03f8SKarsten Keil  */
51b2b03f8SKarsten Keil 
65a0e3ad6STejun Heo #include <linux/slab.h>
71b2b03f8SKarsten Keil #include <linux/types.h>
81b2b03f8SKarsten Keil #include <linux/stddef.h>
91b2b03f8SKarsten Keil #include <linux/module.h>
101b2b03f8SKarsten Keil #include <linux/spinlock.h>
111b2b03f8SKarsten Keil #include <linux/mISDNif.h>
121b2b03f8SKarsten Keil #include "core.h"
131b2b03f8SKarsten Keil 
141b2b03f8SKarsten Keil static u_int debug;
151b2b03f8SKarsten Keil 
161b2b03f8SKarsten Keil MODULE_AUTHOR("Karsten Keil");
171b2b03f8SKarsten Keil MODULE_LICENSE("GPL");
181b2b03f8SKarsten Keil module_param(debug, uint, S_IRUGO | S_IWUSR);
191b2b03f8SKarsten Keil 
201b2b03f8SKarsten Keil static u64		device_ids;
211b2b03f8SKarsten Keil #define MAX_DEVICE_ID	63
221b2b03f8SKarsten Keil 
231b2b03f8SKarsten Keil static LIST_HEAD(Bprotocols);
245b834354SHannes Eder static DEFINE_RWLOCK(bp_lock);
251b2b03f8SKarsten Keil 
mISDN_dev_release(struct device * dev)26b36b654aSMatthias Urlichs static void mISDN_dev_release(struct device *dev)
27b36b654aSMatthias Urlichs {
28b36b654aSMatthias Urlichs 	/* nothing to do: the device is part of its parent's data structure */
29b36b654aSMatthias Urlichs }
30b36b654aSMatthias Urlichs 
id_show(struct device * dev,struct device_attribute * attr,char * buf)31d98259cbSGreg Kroah-Hartman static ssize_t id_show(struct device *dev,
32b36b654aSMatthias Urlichs 		       struct device_attribute *attr, char *buf)
33b36b654aSMatthias Urlichs {
34b36b654aSMatthias Urlichs 	struct mISDNdevice *mdev = dev_to_mISDN(dev);
35b36b654aSMatthias Urlichs 
36b36b654aSMatthias Urlichs 	if (!mdev)
37b36b654aSMatthias Urlichs 		return -ENODEV;
38b36b654aSMatthias Urlichs 	return sprintf(buf, "%d\n", mdev->id);
39b36b654aSMatthias Urlichs }
40d98259cbSGreg Kroah-Hartman static DEVICE_ATTR_RO(id);
41b36b654aSMatthias Urlichs 
nrbchan_show(struct device * dev,struct device_attribute * attr,char * buf)42d98259cbSGreg Kroah-Hartman static ssize_t nrbchan_show(struct device *dev,
43b36b654aSMatthias Urlichs 			    struct device_attribute *attr, char *buf)
44b36b654aSMatthias Urlichs {
45b36b654aSMatthias Urlichs 	struct mISDNdevice *mdev = dev_to_mISDN(dev);
46b36b654aSMatthias Urlichs 
47b36b654aSMatthias Urlichs 	if (!mdev)
48b36b654aSMatthias Urlichs 		return -ENODEV;
49b36b654aSMatthias Urlichs 	return sprintf(buf, "%d\n", mdev->nrbchan);
50b36b654aSMatthias Urlichs }
51d98259cbSGreg Kroah-Hartman static DEVICE_ATTR_RO(nrbchan);
52b36b654aSMatthias Urlichs 
d_protocols_show(struct device * dev,struct device_attribute * attr,char * buf)53d98259cbSGreg Kroah-Hartman static ssize_t d_protocols_show(struct device *dev,
54b36b654aSMatthias Urlichs 				struct device_attribute *attr, char *buf)
55b36b654aSMatthias Urlichs {
56b36b654aSMatthias Urlichs 	struct mISDNdevice *mdev = dev_to_mISDN(dev);
57b36b654aSMatthias Urlichs 
58b36b654aSMatthias Urlichs 	if (!mdev)
59b36b654aSMatthias Urlichs 		return -ENODEV;
60b36b654aSMatthias Urlichs 	return sprintf(buf, "%d\n", mdev->Dprotocols);
61b36b654aSMatthias Urlichs }
62d98259cbSGreg Kroah-Hartman static DEVICE_ATTR_RO(d_protocols);
63b36b654aSMatthias Urlichs 
b_protocols_show(struct device * dev,struct device_attribute * attr,char * buf)64d98259cbSGreg Kroah-Hartman static ssize_t b_protocols_show(struct device *dev,
65b36b654aSMatthias Urlichs 				struct device_attribute *attr, char *buf)
66b36b654aSMatthias Urlichs {
67b36b654aSMatthias Urlichs 	struct mISDNdevice *mdev = dev_to_mISDN(dev);
68b36b654aSMatthias Urlichs 
69b36b654aSMatthias Urlichs 	if (!mdev)
70b36b654aSMatthias Urlichs 		return -ENODEV;
71b36b654aSMatthias Urlichs 	return sprintf(buf, "%d\n", mdev->Bprotocols | get_all_Bprotocols());
72b36b654aSMatthias Urlichs }
73d98259cbSGreg Kroah-Hartman static DEVICE_ATTR_RO(b_protocols);
74b36b654aSMatthias Urlichs 
protocol_show(struct device * dev,struct device_attribute * attr,char * buf)75d98259cbSGreg Kroah-Hartman static ssize_t protocol_show(struct device *dev,
76b36b654aSMatthias Urlichs 			     struct device_attribute *attr, char *buf)
77b36b654aSMatthias Urlichs {
78b36b654aSMatthias Urlichs 	struct mISDNdevice *mdev = dev_to_mISDN(dev);
79b36b654aSMatthias Urlichs 
80b36b654aSMatthias Urlichs 	if (!mdev)
81b36b654aSMatthias Urlichs 		return -ENODEV;
82b36b654aSMatthias Urlichs 	return sprintf(buf, "%d\n", mdev->D.protocol);
83b36b654aSMatthias Urlichs }
84d98259cbSGreg Kroah-Hartman static DEVICE_ATTR_RO(protocol);
85b36b654aSMatthias Urlichs 
name_show(struct device * dev,struct device_attribute * attr,char * buf)86d98259cbSGreg Kroah-Hartman static ssize_t name_show(struct device *dev,
87b36b654aSMatthias Urlichs 			 struct device_attribute *attr, char *buf)
88b36b654aSMatthias Urlichs {
89b36b654aSMatthias Urlichs 	strcpy(buf, dev_name(dev));
90b36b654aSMatthias Urlichs 	return strlen(buf);
91b36b654aSMatthias Urlichs }
92d98259cbSGreg Kroah-Hartman static DEVICE_ATTR_RO(name);
93b36b654aSMatthias Urlichs 
94b36b654aSMatthias Urlichs #if 0 /* hangs */
95d98259cbSGreg Kroah-Hartman static ssize_t name_set(struct device *dev, struct device_attribute *attr,
96b36b654aSMatthias Urlichs 			const char *buf, size_t count)
97b36b654aSMatthias Urlichs {
98b36b654aSMatthias Urlichs 	int err = 0;
99b36b654aSMatthias Urlichs 	char *out = kmalloc(count + 1, GFP_KERNEL);
100b36b654aSMatthias Urlichs 
101b36b654aSMatthias Urlichs 	if (!out)
102b36b654aSMatthias Urlichs 		return -ENOMEM;
103b36b654aSMatthias Urlichs 
104b36b654aSMatthias Urlichs 	memcpy(out, buf, count);
105b36b654aSMatthias Urlichs 	if (count && out[count - 1] == '\n')
106b36b654aSMatthias Urlichs 		out[--count] = 0;
107b36b654aSMatthias Urlichs 	if (count)
108b36b654aSMatthias Urlichs 		err = device_rename(dev, out);
109b36b654aSMatthias Urlichs 	kfree(out);
110b36b654aSMatthias Urlichs 
111b36b654aSMatthias Urlichs 	return (err < 0) ? err : count;
112b36b654aSMatthias Urlichs }
113d98259cbSGreg Kroah-Hartman static DEVICE_ATTR_RW(name);
114b36b654aSMatthias Urlichs #endif
115b36b654aSMatthias Urlichs 
channelmap_show(struct device * dev,struct device_attribute * attr,char * buf)116d98259cbSGreg Kroah-Hartman static ssize_t channelmap_show(struct device *dev,
117b36b654aSMatthias Urlichs 			       struct device_attribute *attr, char *buf)
118b36b654aSMatthias Urlichs {
119b36b654aSMatthias Urlichs 	struct mISDNdevice *mdev = dev_to_mISDN(dev);
120b36b654aSMatthias Urlichs 	char *bp = buf;
121b36b654aSMatthias Urlichs 	int i;
122b36b654aSMatthias Urlichs 
123b36b654aSMatthias Urlichs 	for (i = 0; i <= mdev->nrbchan; i++)
124b36b654aSMatthias Urlichs 		*bp++ = test_channelmap(i, mdev->channelmap) ? '1' : '0';
125b36b654aSMatthias Urlichs 
126b36b654aSMatthias Urlichs 	return bp - buf;
127b36b654aSMatthias Urlichs }
128d98259cbSGreg Kroah-Hartman static DEVICE_ATTR_RO(channelmap);
129b36b654aSMatthias Urlichs 
130d98259cbSGreg Kroah-Hartman static struct attribute *mISDN_attrs[] = {
131d98259cbSGreg Kroah-Hartman 	&dev_attr_id.attr,
132d98259cbSGreg Kroah-Hartman 	&dev_attr_d_protocols.attr,
133d98259cbSGreg Kroah-Hartman 	&dev_attr_b_protocols.attr,
134d98259cbSGreg Kroah-Hartman 	&dev_attr_protocol.attr,
135d98259cbSGreg Kroah-Hartman 	&dev_attr_channelmap.attr,
136d98259cbSGreg Kroah-Hartman 	&dev_attr_nrbchan.attr,
137d98259cbSGreg Kroah-Hartman 	&dev_attr_name.attr,
138d98259cbSGreg Kroah-Hartman 	NULL,
139b36b654aSMatthias Urlichs };
140d98259cbSGreg Kroah-Hartman ATTRIBUTE_GROUPS(mISDN);
141b36b654aSMatthias Urlichs 
mISDN_uevent(const struct device * dev,struct kobj_uevent_env * env)142*23680f0bSGreg Kroah-Hartman static int mISDN_uevent(const struct device *dev, struct kobj_uevent_env *env)
143b36b654aSMatthias Urlichs {
144*23680f0bSGreg Kroah-Hartman 	const struct mISDNdevice *mdev = dev_to_mISDN(dev);
145b36b654aSMatthias Urlichs 
146b36b654aSMatthias Urlichs 	if (!mdev)
147b36b654aSMatthias Urlichs 		return 0;
148b36b654aSMatthias Urlichs 
149b36b654aSMatthias Urlichs 	if (add_uevent_var(env, "nchans=%d", mdev->nrbchan))
150b36b654aSMatthias Urlichs 		return -ENOMEM;
151b36b654aSMatthias Urlichs 
152b36b654aSMatthias Urlichs 	return 0;
153b36b654aSMatthias Urlichs }
154b36b654aSMatthias Urlichs 
155b36b654aSMatthias Urlichs static struct class mISDN_class = {
156b36b654aSMatthias Urlichs 	.name = "mISDN",
157b36b654aSMatthias Urlichs 	.dev_uevent = mISDN_uevent,
158d98259cbSGreg Kroah-Hartman 	.dev_groups = mISDN_groups,
159b36b654aSMatthias Urlichs 	.dev_release = mISDN_dev_release,
160b36b654aSMatthias Urlichs };
161b36b654aSMatthias Urlichs 
162b36b654aSMatthias Urlichs static int
_get_mdevice(struct device * dev,const void * id)1639f3b795aSMichał Mirosław _get_mdevice(struct device *dev, const void *id)
164b36b654aSMatthias Urlichs {
165b36b654aSMatthias Urlichs 	struct mISDNdevice *mdev = dev_to_mISDN(dev);
166b36b654aSMatthias Urlichs 
167b36b654aSMatthias Urlichs 	if (!mdev)
168b36b654aSMatthias Urlichs 		return 0;
1699f3b795aSMichał Mirosław 	if (mdev->id != *(const u_int *)id)
170b36b654aSMatthias Urlichs 		return 0;
171b36b654aSMatthias Urlichs 	return 1;
172b36b654aSMatthias Urlichs }
173b36b654aSMatthias Urlichs 
1741b2b03f8SKarsten Keil struct mISDNdevice
get_mdevice(u_int id)1751b2b03f8SKarsten Keil *get_mdevice(u_int id)
1761b2b03f8SKarsten Keil {
177b36b654aSMatthias Urlichs 	return dev_to_mISDN(class_find_device(&mISDN_class, NULL, &id,
178b36b654aSMatthias Urlichs 					      _get_mdevice));
1791b2b03f8SKarsten Keil }
180b36b654aSMatthias Urlichs 
181b36b654aSMatthias Urlichs static int
_get_mdevice_count(struct device * dev,void * cnt)182b36b654aSMatthias Urlichs _get_mdevice_count(struct device *dev, void *cnt)
183b36b654aSMatthias Urlichs {
184b36b654aSMatthias Urlichs 	*(int *)cnt += 1;
185b36b654aSMatthias Urlichs 	return 0;
1861b2b03f8SKarsten Keil }
1871b2b03f8SKarsten Keil 
1881b2b03f8SKarsten Keil int
get_mdevice_count(void)1891b2b03f8SKarsten Keil get_mdevice_count(void)
1901b2b03f8SKarsten Keil {
1911b2b03f8SKarsten Keil 	int cnt = 0;
1921b2b03f8SKarsten Keil 
193b36b654aSMatthias Urlichs 	class_for_each_device(&mISDN_class, NULL, &cnt, _get_mdevice_count);
1941b2b03f8SKarsten Keil 	return cnt;
1951b2b03f8SKarsten Keil }
1961b2b03f8SKarsten Keil 
1971b2b03f8SKarsten Keil static int
get_free_devid(void)1981b2b03f8SKarsten Keil get_free_devid(void)
1991b2b03f8SKarsten Keil {
2001b2b03f8SKarsten Keil 	u_int	i;
2011b2b03f8SKarsten Keil 
2021b2b03f8SKarsten Keil 	for (i = 0; i <= MAX_DEVICE_ID; i++)
2031b2b03f8SKarsten Keil 		if (!test_and_set_bit(i, (u_long *)&device_ids))
204b36b654aSMatthias Urlichs 			break;
205b36b654aSMatthias Urlichs 	if (i > MAX_DEVICE_ID)
206ddacd14eSRoel Kluin 		return -EBUSY;
207b36b654aSMatthias Urlichs 	return i;
2081b2b03f8SKarsten Keil }
2091b2b03f8SKarsten Keil 
2101b2b03f8SKarsten Keil int
mISDN_register_device(struct mISDNdevice * dev,struct device * parent,char * name)211b36b654aSMatthias Urlichs mISDN_register_device(struct mISDNdevice *dev,
212b36b654aSMatthias Urlichs 		      struct device *parent, char *name)
2131b2b03f8SKarsten Keil {
2141b2b03f8SKarsten Keil 	int	err;
2151b2b03f8SKarsten Keil 
216ddacd14eSRoel Kluin 	err = get_free_devid();
217ddacd14eSRoel Kluin 	if (err < 0)
2182d25107eSWang ShaoBo 		return err;
219ddacd14eSRoel Kluin 	dev->id = err;
220b36b654aSMatthias Urlichs 
221b36b654aSMatthias Urlichs 	device_initialize(&dev->dev);
2221b2b03f8SKarsten Keil 	if (name && name[0])
223837468d1SMatthias Urlichs 		dev_set_name(&dev->dev, "%s", name);
2241b2b03f8SKarsten Keil 	else
225837468d1SMatthias Urlichs 		dev_set_name(&dev->dev, "mISDN%d", dev->id);
2261b2b03f8SKarsten Keil 	if (debug & DEBUG_CORE)
2271b2b03f8SKarsten Keil 		printk(KERN_DEBUG "mISDN_register %s %d\n",
228837468d1SMatthias Urlichs 		       dev_name(&dev->dev), dev->id);
229e7d1d4d9SYang Yingliang 	dev->dev.class = &mISDN_class;
230e7d1d4d9SYang Yingliang 
2311b2b03f8SKarsten Keil 	err = create_stack(dev);
2321b2b03f8SKarsten Keil 	if (err)
233b36b654aSMatthias Urlichs 		goto error1;
234b36b654aSMatthias Urlichs 
235b36b654aSMatthias Urlichs 	dev->dev.platform_data = dev;
236b36b654aSMatthias Urlichs 	dev->dev.parent = parent;
237b36b654aSMatthias Urlichs 	dev_set_drvdata(&dev->dev, dev);
238b36b654aSMatthias Urlichs 
239b36b654aSMatthias Urlichs 	err = device_add(&dev->dev);
240b36b654aSMatthias Urlichs 	if (err)
241b36b654aSMatthias Urlichs 		goto error3;
2421b2b03f8SKarsten Keil 	return 0;
243b36b654aSMatthias Urlichs 
244b36b654aSMatthias Urlichs error3:
245b36b654aSMatthias Urlichs 	delete_stack(dev);
246b36b654aSMatthias Urlichs error1:
247e7d1d4d9SYang Yingliang 	put_device(&dev->dev);
248b36b654aSMatthias Urlichs 	return err;
249b36b654aSMatthias Urlichs 
2501b2b03f8SKarsten Keil }
2511b2b03f8SKarsten Keil EXPORT_SYMBOL(mISDN_register_device);
2521b2b03f8SKarsten Keil 
2531b2b03f8SKarsten Keil void
mISDN_unregister_device(struct mISDNdevice * dev)2541b2b03f8SKarsten Keil mISDN_unregister_device(struct mISDNdevice *dev) {
2551b2b03f8SKarsten Keil 	if (debug & DEBUG_CORE)
2561b2b03f8SKarsten Keil 		printk(KERN_DEBUG "mISDN_unregister %s %d\n",
257837468d1SMatthias Urlichs 		       dev_name(&dev->dev), dev->id);
258b36b654aSMatthias Urlichs 	/* sysfs_remove_link(&dev->dev.kobj, "device"); */
259b36b654aSMatthias Urlichs 	device_del(&dev->dev);
260b36b654aSMatthias Urlichs 	dev_set_drvdata(&dev->dev, NULL);
261b36b654aSMatthias Urlichs 
2621b2b03f8SKarsten Keil 	test_and_clear_bit(dev->id, (u_long *)&device_ids);
2631b2b03f8SKarsten Keil 	delete_stack(dev);
264b36b654aSMatthias Urlichs 	put_device(&dev->dev);
2651b2b03f8SKarsten Keil }
2661b2b03f8SKarsten Keil EXPORT_SYMBOL(mISDN_unregister_device);
2671b2b03f8SKarsten Keil 
2681b2b03f8SKarsten Keil u_int
get_all_Bprotocols(void)2691b2b03f8SKarsten Keil get_all_Bprotocols(void)
2701b2b03f8SKarsten Keil {
2711b2b03f8SKarsten Keil 	struct Bprotocol	*bp;
2721b2b03f8SKarsten Keil 	u_int	m = 0;
2731b2b03f8SKarsten Keil 
2741b2b03f8SKarsten Keil 	read_lock(&bp_lock);
2751b2b03f8SKarsten Keil 	list_for_each_entry(bp, &Bprotocols, list)
2761b2b03f8SKarsten Keil 		m |= bp->Bprotocols;
2771b2b03f8SKarsten Keil 	read_unlock(&bp_lock);
2781b2b03f8SKarsten Keil 	return m;
2791b2b03f8SKarsten Keil }
2801b2b03f8SKarsten Keil 
2811b2b03f8SKarsten Keil struct Bprotocol *
get_Bprotocol4mask(u_int m)2821b2b03f8SKarsten Keil get_Bprotocol4mask(u_int m)
2831b2b03f8SKarsten Keil {
2841b2b03f8SKarsten Keil 	struct Bprotocol	*bp;
2851b2b03f8SKarsten Keil 
2861b2b03f8SKarsten Keil 	read_lock(&bp_lock);
2871b2b03f8SKarsten Keil 	list_for_each_entry(bp, &Bprotocols, list)
2881b2b03f8SKarsten Keil 		if (bp->Bprotocols & m) {
2891b2b03f8SKarsten Keil 			read_unlock(&bp_lock);
2901b2b03f8SKarsten Keil 			return bp;
2911b2b03f8SKarsten Keil 		}
2921b2b03f8SKarsten Keil 	read_unlock(&bp_lock);
2931b2b03f8SKarsten Keil 	return NULL;
2941b2b03f8SKarsten Keil }
2951b2b03f8SKarsten Keil 
2961b2b03f8SKarsten Keil struct Bprotocol *
get_Bprotocol4id(u_int id)2971b2b03f8SKarsten Keil get_Bprotocol4id(u_int id)
2981b2b03f8SKarsten Keil {
2991b2b03f8SKarsten Keil 	u_int	m;
3001b2b03f8SKarsten Keil 
3011b2b03f8SKarsten Keil 	if (id < ISDN_P_B_START || id > 63) {
3021b2b03f8SKarsten Keil 		printk(KERN_WARNING "%s id not in range  %d\n",
3031b2b03f8SKarsten Keil 		       __func__, id);
3041b2b03f8SKarsten Keil 		return NULL;
3051b2b03f8SKarsten Keil 	}
3061b2b03f8SKarsten Keil 	m = 1 << (id & ISDN_P_B_MASK);
3071b2b03f8SKarsten Keil 	return get_Bprotocol4mask(m);
3081b2b03f8SKarsten Keil }
3091b2b03f8SKarsten Keil 
3101b2b03f8SKarsten Keil int
mISDN_register_Bprotocol(struct Bprotocol * bp)3111b2b03f8SKarsten Keil mISDN_register_Bprotocol(struct Bprotocol *bp)
3121b2b03f8SKarsten Keil {
3131b2b03f8SKarsten Keil 	u_long			flags;
3141b2b03f8SKarsten Keil 	struct Bprotocol	*old;
3151b2b03f8SKarsten Keil 
3161b2b03f8SKarsten Keil 	if (debug & DEBUG_CORE)
3171b2b03f8SKarsten Keil 		printk(KERN_DEBUG "%s: %s/%x\n", __func__,
3181b2b03f8SKarsten Keil 		       bp->name, bp->Bprotocols);
3191b2b03f8SKarsten Keil 	old = get_Bprotocol4mask(bp->Bprotocols);
3201b2b03f8SKarsten Keil 	if (old) {
3211b2b03f8SKarsten Keil 		printk(KERN_WARNING
3221b2b03f8SKarsten Keil 		       "register duplicate protocol old %s/%x new %s/%x\n",
3231b2b03f8SKarsten Keil 		       old->name, old->Bprotocols, bp->name, bp->Bprotocols);
3241b2b03f8SKarsten Keil 		return -EBUSY;
3251b2b03f8SKarsten Keil 	}
3261b2b03f8SKarsten Keil 	write_lock_irqsave(&bp_lock, flags);
3271b2b03f8SKarsten Keil 	list_add_tail(&bp->list, &Bprotocols);
3281b2b03f8SKarsten Keil 	write_unlock_irqrestore(&bp_lock, flags);
3291b2b03f8SKarsten Keil 	return 0;
3301b2b03f8SKarsten Keil }
3311b2b03f8SKarsten Keil EXPORT_SYMBOL(mISDN_register_Bprotocol);
3321b2b03f8SKarsten Keil 
3331b2b03f8SKarsten Keil void
mISDN_unregister_Bprotocol(struct Bprotocol * bp)3341b2b03f8SKarsten Keil mISDN_unregister_Bprotocol(struct Bprotocol *bp)
3351b2b03f8SKarsten Keil {
3361b2b03f8SKarsten Keil 	u_long	flags;
3371b2b03f8SKarsten Keil 
3381b2b03f8SKarsten Keil 	if (debug & DEBUG_CORE)
3391b2b03f8SKarsten Keil 		printk(KERN_DEBUG "%s: %s/%x\n", __func__, bp->name,
3401b2b03f8SKarsten Keil 		       bp->Bprotocols);
3411b2b03f8SKarsten Keil 	write_lock_irqsave(&bp_lock, flags);
3421b2b03f8SKarsten Keil 	list_del(&bp->list);
3431b2b03f8SKarsten Keil 	write_unlock_irqrestore(&bp_lock, flags);
3441b2b03f8SKarsten Keil }
3451b2b03f8SKarsten Keil EXPORT_SYMBOL(mISDN_unregister_Bprotocol);
3461b2b03f8SKarsten Keil 
347f45ebf3aSKarsten Keil static const char *msg_no_channel = "<no channel>";
348f45ebf3aSKarsten Keil static const char *msg_no_stack = "<no stack>";
349f45ebf3aSKarsten Keil static const char *msg_no_stackdev = "<no stack device>";
350f45ebf3aSKarsten Keil 
mISDNDevName4ch(struct mISDNchannel * ch)351f45ebf3aSKarsten Keil const char *mISDNDevName4ch(struct mISDNchannel *ch)
352f45ebf3aSKarsten Keil {
353f45ebf3aSKarsten Keil 	if (!ch)
354f45ebf3aSKarsten Keil 		return msg_no_channel;
355f45ebf3aSKarsten Keil 	if (!ch->st)
356f45ebf3aSKarsten Keil 		return msg_no_stack;
357f45ebf3aSKarsten Keil 	if (!ch->st->dev)
358f45ebf3aSKarsten Keil 		return msg_no_stackdev;
359f45ebf3aSKarsten Keil 	return dev_name(&ch->st->dev->dev);
360f45ebf3aSKarsten Keil };
361f45ebf3aSKarsten Keil EXPORT_SYMBOL(mISDNDevName4ch);
362f45ebf3aSKarsten Keil 
3635b834354SHannes Eder static int
mISDNInit(void)3641b2b03f8SKarsten Keil mISDNInit(void)
3651b2b03f8SKarsten Keil {
3661b2b03f8SKarsten Keil 	int	err;
3671b2b03f8SKarsten Keil 
3681b2b03f8SKarsten Keil 	printk(KERN_INFO "Modular ISDN core version %d.%d.%d\n",
3691b2b03f8SKarsten Keil 	       MISDN_MAJOR_VERSION, MISDN_MINOR_VERSION, MISDN_RELEASE);
3703bd69ad1SAndreas Eversberg 	mISDN_init_clock(&debug);
3711b2b03f8SKarsten Keil 	mISDN_initstack(&debug);
372b36b654aSMatthias Urlichs 	err = class_register(&mISDN_class);
373b36b654aSMatthias Urlichs 	if (err)
374b36b654aSMatthias Urlichs 		goto error1;
3751b2b03f8SKarsten Keil 	err = mISDN_inittimer(&debug);
3761b2b03f8SKarsten Keil 	if (err)
377b36b654aSMatthias Urlichs 		goto error2;
3788b5fdfc5Swolfgang huang 	err = Isdnl1_Init(&debug);
379b36b654aSMatthias Urlichs 	if (err)
380b36b654aSMatthias Urlichs 		goto error3;
3811b2b03f8SKarsten Keil 	err = Isdnl2_Init(&debug);
382b36b654aSMatthias Urlichs 	if (err)
383b36b654aSMatthias Urlichs 		goto error4;
3841b2b03f8SKarsten Keil 	err = misdn_sock_init(&debug);
385b36b654aSMatthias Urlichs 	if (err)
386b36b654aSMatthias Urlichs 		goto error5;
387b36b654aSMatthias Urlichs 	return 0;
388b36b654aSMatthias Urlichs 
389b36b654aSMatthias Urlichs error5:
3901b2b03f8SKarsten Keil 	Isdnl2_cleanup();
391b36b654aSMatthias Urlichs error4:
3928b5fdfc5Swolfgang huang 	Isdnl1_cleanup();
393b36b654aSMatthias Urlichs error3:
394b36b654aSMatthias Urlichs 	mISDN_timer_cleanup();
395b36b654aSMatthias Urlichs error2:
396b36b654aSMatthias Urlichs 	class_unregister(&mISDN_class);
397b36b654aSMatthias Urlichs error1:
3981b2b03f8SKarsten Keil 	return err;
3991b2b03f8SKarsten Keil }
4001b2b03f8SKarsten Keil 
mISDN_cleanup(void)4015b834354SHannes Eder static void mISDN_cleanup(void)
4021b2b03f8SKarsten Keil {
4031b2b03f8SKarsten Keil 	misdn_sock_cleanup();
4041b2b03f8SKarsten Keil 	Isdnl2_cleanup();
4058b5fdfc5Swolfgang huang 	Isdnl1_cleanup();
406b36b654aSMatthias Urlichs 	mISDN_timer_cleanup();
407b36b654aSMatthias Urlichs 	class_unregister(&mISDN_class);
4081b2b03f8SKarsten Keil 
4091b2b03f8SKarsten Keil 	printk(KERN_DEBUG "mISDNcore unloaded\n");
4101b2b03f8SKarsten Keil }
4111b2b03f8SKarsten Keil 
4121b2b03f8SKarsten Keil module_init(mISDNInit);
4131b2b03f8SKarsten Keil module_exit(mISDN_cleanup);
414