summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTzafrir Cohen <tzafrir.cohen@xorcom.com>2011-01-16 14:18:18 +0000
committerTzafrir Cohen <tzafrir.cohen@xorcom.com>2011-01-16 14:18:18 +0000
commit1990c67f642591c62ac648ce313bba653739ece0 (patch)
treeffbd22b7d14f97dcfd81d9fdcdce70b6a00d51e9
parent611b1ab4f98f8befd459335791e06b3460bda9f5 (diff)
Refactor SysFS code to dahdi-sysfs.c
* Refactor SysFS and device-related code to drivers/dahdi/dahdi-sysfs.c . * Move common headers to drivers/dahdi/dahdi.h . This commit merely moves existing code and should have no functional change. Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com> Acked-by: Shaun Ruffell <sruffell@digium.com> Acked-by: Oron Peled <oron.peled@xorcom.com> git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@9628 a0bf4364-ded3-4de4-8d8a-66a801d63aff
-rw-r--r--drivers/dahdi/Kbuild2
-rw-r--r--drivers/dahdi/dahdi-base.c220
-rw-r--r--drivers/dahdi/dahdi-sysfs.c230
-rw-r--r--drivers/dahdi/dahdi.h36
4 files changed, 269 insertions, 219 deletions
diff --git a/drivers/dahdi/Kbuild b/drivers/dahdi/Kbuild
index 3fe2e28..1494713 100644
--- a/drivers/dahdi/Kbuild
+++ b/drivers/dahdi/Kbuild
@@ -76,7 +76,7 @@ CFLAGS_dahdi_dynamic_ethmf.o := -DNEW_SKB_LINEARIZE
endif
endif
-dahdi-objs := dahdi-base.o
+dahdi-objs := dahdi-base.o dahdi-sysfs.o
###############################################################################
# Find appropriate ARCH value for VPMADT032 and HPEC binary modules
diff --git a/drivers/dahdi/dahdi-base.c b/drivers/dahdi/dahdi-base.c
index 30b04e6..df0032a 100644
--- a/drivers/dahdi/dahdi-base.c
+++ b/drivers/dahdi/dahdi-base.c
@@ -65,6 +65,7 @@
#define FAST_HDLC_NEED_TABLES
#include <dahdi/kernel.h>
#include "ecdis.h"
+#include "dahdi.h"
#ifdef CONFIG_DAHDI_PPP
#include <linux/netdevice.h>
@@ -132,8 +133,6 @@ EXPORT_SYMBOL(dahdi_hdlc_finish);
EXPORT_SYMBOL(dahdi_hdlc_getbuf);
EXPORT_SYMBOL(dahdi_hdlc_putbuf);
EXPORT_SYMBOL(dahdi_alarm_channel);
-EXPORT_SYMBOL(dahdi_register_chardev);
-EXPORT_SYMBOL(dahdi_unregister_chardev);
EXPORT_SYMBOL(dahdi_register_echocan_factory);
EXPORT_SYMBOL(dahdi_unregister_echocan_factory);
@@ -144,48 +143,9 @@ EXPORT_SYMBOL(dahdi_set_hpec_ioctl);
static struct proc_dir_entry *root_proc_entry;
#endif
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
-#define CLASS_DEV_CREATE(class, devt, device, name) \
- device_create(class, device, devt, NULL, "%s", name)
-#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
-#define CLASS_DEV_CREATE(class, devt, device, name) \
- device_create(class, device, devt, name)
-#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
-#define CLASS_DEV_CREATE(class, devt, device, name) \
- class_device_create(class, NULL, devt, device, name)
-#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
-#define CLASS_DEV_CREATE(class, devt, device, name) \
- class_device_create(class, devt, device, name)
-#else
-#define CLASS_DEV_CREATE(class, devt, device, name) \
- class_simple_device_add(class, devt, device, name)
-#endif
-
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
-#define CLASS_DEV_DESTROY(class, devt) \
- device_destroy(class, devt)
-#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
-#define CLASS_DEV_DESTROY(class, devt) \
- class_device_destroy(class, devt)
-#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9)
-#define CLASS_DEV_DESTROY(class, devt) \
- class_simple_device_remove(devt)
-#else
-#define CLASS_DEV_DESTROY(class, devt) \
- class_simple_device_remove(class, devt)
-#endif
-
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
-static struct class *dahdi_class = NULL;
-#else
-static struct class_simple *dahdi_class = NULL;
-#define class_create class_simple_create
-#define class_destroy class_simple_destroy
-#endif
-
static int deftaps = 64;
-static int debug;
+int debug;
#define DEBUG_MAIN (1 << 0)
#define DEBUG_RBS (1 << 5)
@@ -6445,56 +6405,6 @@ static long dahdi_ioctl_compat(struct file *file, unsigned int cmd,
}
#endif
-static void span_sysfs_remove(struct dahdi_span *span)
-{
- int x;
- for (x = 0; x < span->channels; x++) {
- struct dahdi_chan *chan = span->chans[x];
- if (!test_bit(DAHDI_FLAGBIT_DEVFILE, &chan->flags))
- continue;
-
- CLASS_DEV_DESTROY(dahdi_class,
- MKDEV(DAHDI_MAJOR, chan->channo));
- clear_bit(DAHDI_FLAGBIT_DEVFILE, &chan->flags);
- }
-}
-
-static int span_sysfs_create(struct dahdi_span *span)
-{
- int res = 0;
- int x;
-
- for (x = 0; x < span->channels; x++) {
- struct dahdi_chan *chan = span->chans[x];
- char chan_name[32];
- void *dummy;
-
- if (chan->channo >= 250)
- continue;
- if (test_bit(DAHDI_FLAGBIT_DEVFILE, &chan->flags))
- continue;
-
- snprintf(chan_name, sizeof(chan_name), "dahdi!%d",
- chan->channo);
- dummy = (void *)CLASS_DEV_CREATE(dahdi_class,
- MKDEV(DAHDI_MAJOR, chan->channo),
- NULL, chan_name);
- if (IS_ERR(dummy)) {
- res = PTR_ERR(dummy);
- chan_err(chan, "Failed creating sysfs device: %d\n",
- res);
- goto cleanup;
- }
-
- set_bit(DAHDI_FLAGBIT_DEVFILE, &chan->flags);
- }
- return 0;
-
-cleanup:
- span_sysfs_remove(span);
- return res;
-}
-
/**
* _get_next_channo - Return the next taken channel number from the span list.
* @span: The span with which to start the search.
@@ -9339,30 +9249,6 @@ static void __exit watchdog_cleanup(void)
#endif
-int dahdi_register_chardev(struct dahdi_chardev *dev)
-{
- static const char *DAHDI_STRING = "dahdi!";
- char *udevname;
-
- udevname = kzalloc(strlen(dev->name) + sizeof(DAHDI_STRING) + 1,
- GFP_KERNEL);
- if (!udevname)
- return -ENOMEM;
-
- strcpy(udevname, DAHDI_STRING);
- strcat(udevname, dev->name);
- CLASS_DEV_CREATE(dahdi_class, MKDEV(DAHDI_MAJOR, dev->minor), NULL, udevname);
- kfree(udevname);
- return 0;
-}
-
-int dahdi_unregister_chardev(struct dahdi_chardev *dev)
-{
- CLASS_DEV_DESTROY(dahdi_class, MKDEV(DAHDI_MAJOR, dev->minor));
-
- return 0;
-}
-
static const char *hwec_def_name = "HWEC";
static const char *hwec_get_name(const struct dahdi_chan *chan)
{
@@ -9388,108 +9274,6 @@ static const struct dahdi_echocan_factory hwec_factory = {
.echocan_create = hwec_echocan_create,
};
-#define MAKE_DAHDI_DEV(num, name) \
- CLASS_DEV_CREATE(dahdi_class, MKDEV(DAHDI_MAJOR, num), NULL, name)
-#define DEL_DAHDI_DEV(num) \
- CLASS_DEV_DESTROY(dahdi_class, MKDEV(DAHDI_MAJOR, num))
-
-/* Only used to flag that the device exists: */
-static struct {
- unsigned int ctl:1;
- unsigned int timer:1;
- unsigned int channel:1;
- unsigned int pseudo:1;
-} dummy_dev;
-
-static void dahdi_sysfs_exit(void)
-{
- if (dummy_dev.pseudo) {
- dahdi_dbg(DEVICES, "Removing /dev/dahdi/pseudo:\n");
- DEL_DAHDI_DEV(DAHDI_PSEUDO);
- dummy_dev.pseudo = 0;
- }
- if (dummy_dev.channel) {
- dahdi_dbg(DEVICES, "Removing /dev/dahdi/channel:\n");
- DEL_DAHDI_DEV(DAHDI_CHANNEL);
- dummy_dev.channel = 0;
- }
- if (dummy_dev.timer) {
- dahdi_dbg(DEVICES, "Removing /dev/dahdi/timer:\n");
- DEL_DAHDI_DEV(DAHDI_TIMER);
- dummy_dev.timer = 0;
- }
- if (dummy_dev.ctl) {
- dahdi_dbg(DEVICES, "Removing /dev/dahdi/ctl:\n");
- DEL_DAHDI_DEV(DAHDI_CTL);
- dummy_dev.ctl = 0;
- }
- if (dahdi_class) {
- dahdi_dbg(DEVICES, "Destroying DAHDI class:\n");
- class_destroy(dahdi_class);
- dahdi_class = NULL;
- }
- unregister_chrdev(DAHDI_MAJOR, "dahdi");
-}
-
-static int __init dahdi_sysfs_init(const struct file_operations *dahdi_fops)
-{
- int res = 0;
- void *dev;
-
- res = register_chrdev(DAHDI_MAJOR, "dahdi", dahdi_fops);
- if (res) {
- module_printk(KERN_ERR, "Unable to register DAHDI character device handler on %d\n", DAHDI_MAJOR);
- return res;
- }
- module_printk(KERN_INFO, "Telephony Interface Registered on major %d\n",
- DAHDI_MAJOR);
- module_printk(KERN_INFO, "Version: %s\n", DAHDI_VERSION);
-
- dahdi_class = class_create(THIS_MODULE, "dahdi");
- if (!dahdi_class) {
- res = -EEXIST;
- goto cleanup;
- }
-
- dahdi_dbg(DEVICES, "Creating /dev/dahdi/timer:\n");
- dev = MAKE_DAHDI_DEV(DAHDI_TIMER, "dahdi!timer");
- if (IS_ERR(dev)) {
- res = PTR_ERR(dev);
- goto cleanup;
- }
- dummy_dev.timer = 1;
-
- dahdi_dbg(DEVICES, "Creating /dev/dahdi/channel:\n");
- dev = MAKE_DAHDI_DEV(DAHDI_CHANNEL, "dahdi!channel");
- if (IS_ERR(dev)) {
- res = PTR_ERR(dev);
- goto cleanup;
- }
- dummy_dev.channel = 1;
-
- dahdi_dbg(DEVICES, "Creating /dev/dahdi/pseudo:\n");
- dev = MAKE_DAHDI_DEV(DAHDI_PSEUDO, "dahdi!pseudo");
- if (IS_ERR(dev)) {
- res = PTR_ERR(dev);
- goto cleanup;
- }
- dummy_dev.pseudo = 1;
-
- dahdi_dbg(DEVICES, "Creating /dev/dahdi/ctl:\n");
- dev = MAKE_DAHDI_DEV(DAHDI_CTL, "dahdi!ctl");
- if (IS_ERR(dev)) {
- res = PTR_ERR(dev);
- goto cleanup;
- }
- dummy_dev.ctl = 1;
-
- return 0;
-
-cleanup:
- dahdi_sysfs_exit();
- return res;
-}
-
static int __init dahdi_init(void)
{
int res = 0;
diff --git a/drivers/dahdi/dahdi-sysfs.c b/drivers/dahdi/dahdi-sysfs.c
new file mode 100644
index 0000000..be1ad19
--- /dev/null
+++ b/drivers/dahdi/dahdi-sysfs.c
@@ -0,0 +1,230 @@
+#include <linux/kernel.h>
+#include <linux/version.h>
+#define DAHDI_PRINK_MACROS_USE_debug
+#include <dahdi/kernel.h>
+#include <linux/device.h>
+#include <dahdi/version.h>
+
+#include "dahdi.h"
+
+/* FIXME: Move to kernel.h */
+#define module_printk(level, fmt, args...) printk(level "%s: " fmt, THIS_MODULE->name, ## args)
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
+#define CLASS_DEV_CREATE(class, devt, device, name) \
+ device_create(class, device, devt, NULL, "%s", name)
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
+#define CLASS_DEV_CREATE(class, devt, device, name) \
+ device_create(class, device, devt, name)
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)
+#define CLASS_DEV_CREATE(class, devt, device, name) \
+ class_device_create(class, NULL, devt, device, name)
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
+#define CLASS_DEV_CREATE(class, devt, device, name) \
+ class_device_create(class, devt, device, name)
+#else
+#define CLASS_DEV_CREATE(class, devt, device, name) \
+ class_simple_device_add(class, devt, device, name)
+#endif
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
+#define CLASS_DEV_DESTROY(class, devt) \
+ device_destroy(class, devt)
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
+#define CLASS_DEV_DESTROY(class, devt) \
+ class_device_destroy(class, devt)
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9)
+#define CLASS_DEV_DESTROY(class, devt) \
+ class_simple_device_remove(devt)
+#else
+#define CLASS_DEV_DESTROY(class, devt) \
+ class_simple_device_remove(class, devt)
+#endif
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
+static struct class *dahdi_class = NULL;
+#else
+static struct class_simple *dahdi_class = NULL;
+#define class_create class_simple_create
+#define class_destroy class_simple_destroy
+#endif
+
+
+int dahdi_register_chardev(struct dahdi_chardev *dev)
+{
+ static const char *DAHDI_STRING = "dahdi!";
+ char *udevname;
+
+ udevname = kzalloc(strlen(dev->name) + sizeof(DAHDI_STRING) + 1,
+ GFP_KERNEL);
+ if (!udevname)
+ return -ENOMEM;
+
+ strcpy(udevname, DAHDI_STRING);
+ strcat(udevname, dev->name);
+ CLASS_DEV_CREATE(dahdi_class, MKDEV(DAHDI_MAJOR, dev->minor), NULL, udevname);
+ kfree(udevname);
+ return 0;
+}
+EXPORT_SYMBOL(dahdi_register_chardev);
+
+int dahdi_unregister_chardev(struct dahdi_chardev *dev)
+{
+ CLASS_DEV_DESTROY(dahdi_class, MKDEV(DAHDI_MAJOR, dev->minor));
+
+ return 0;
+}
+EXPORT_SYMBOL(dahdi_unregister_chardev);
+
+void span_sysfs_remove(struct dahdi_span *span)
+{
+ int x;
+ for (x = 0; x < span->channels; x++) {
+ struct dahdi_chan *chan = span->chans[x];
+ if (!test_bit(DAHDI_FLAGBIT_DEVFILE, &chan->flags))
+ continue;
+
+ CLASS_DEV_DESTROY(dahdi_class,
+ MKDEV(DAHDI_MAJOR, chan->channo));
+ clear_bit(DAHDI_FLAGBIT_DEVFILE, &chan->flags);
+ }
+}
+
+int span_sysfs_create(struct dahdi_span *span)
+{
+ int res = 0;
+ int x;
+
+ for (x = 0; x < span->channels; x++) {
+ struct dahdi_chan *chan = span->chans[x];
+ char chan_name[32];
+ void *dummy;
+
+ if (chan->channo >= 250)
+ continue;
+ if (test_bit(DAHDI_FLAGBIT_DEVFILE, &chan->flags))
+ continue;
+
+ snprintf(chan_name, sizeof(chan_name), "dahdi!%d",
+ chan->channo);
+ dummy = (void *)CLASS_DEV_CREATE(dahdi_class,
+ MKDEV(DAHDI_MAJOR, chan->channo),
+ NULL, chan_name);
+ if (IS_ERR(dummy)) {
+ res = PTR_ERR(dummy);
+ chan_err(chan, "Failed creating sysfs device: %d\n",
+ res);
+ goto cleanup;
+ }
+
+ set_bit(DAHDI_FLAGBIT_DEVFILE, &chan->flags);
+ }
+ return 0;
+
+cleanup:
+ span_sysfs_remove(span);
+ return res;
+}
+
+#define MAKE_DAHDI_DEV(num, name) \
+ CLASS_DEV_CREATE(dahdi_class, MKDEV(DAHDI_MAJOR, num), NULL, name)
+#define DEL_DAHDI_DEV(num) \
+ CLASS_DEV_DESTROY(dahdi_class, MKDEV(DAHDI_MAJOR, num))
+
+/* Only used to flag that the device exists: */
+static struct {
+ unsigned int ctl:1;
+ unsigned int timer:1;
+ unsigned int channel:1;
+ unsigned int pseudo:1;
+} dummy_dev;
+
+void dahdi_sysfs_exit(void)
+{
+ if (dummy_dev.pseudo) {
+ dahdi_dbg(DEVICES, "Removing /dev/dahdi/pseudo:\n");
+ DEL_DAHDI_DEV(DAHDI_PSEUDO);
+ dummy_dev.pseudo = 0;
+ }
+ if (dummy_dev.channel) {
+ dahdi_dbg(DEVICES, "Removing /dev/dahdi/channel:\n");
+ DEL_DAHDI_DEV(DAHDI_CHANNEL);
+ dummy_dev.channel = 0;
+ }
+ if (dummy_dev.timer) {
+ dahdi_dbg(DEVICES, "Removing /dev/dahdi/timer:\n");
+ DEL_DAHDI_DEV(DAHDI_TIMER);
+ dummy_dev.timer = 0;
+ }
+ if (dummy_dev.ctl) {
+ dahdi_dbg(DEVICES, "Removing /dev/dahdi/ctl:\n");
+ DEL_DAHDI_DEV(DAHDI_CTL);
+ dummy_dev.ctl = 0;
+ }
+ if (dahdi_class) {
+ dahdi_dbg(DEVICES, "Destroying DAHDI class:\n");
+ class_destroy(dahdi_class);
+ dahdi_class = NULL;
+ }
+ unregister_chrdev(DAHDI_MAJOR, "dahdi");
+}
+
+int __init dahdi_sysfs_init(const struct file_operations *dahdi_fops)
+{
+ int res = 0;
+ void *dev;
+
+ res = register_chrdev(DAHDI_MAJOR, "dahdi", dahdi_fops);
+ if (res) {
+ module_printk(KERN_ERR, "Unable to register DAHDI character device handler on %d\n", DAHDI_MAJOR);
+ return res;
+ }
+ module_printk(KERN_INFO, "Telephony Interface Registered on major %d\n",
+ DAHDI_MAJOR);
+ module_printk(KERN_INFO, "Version: %s\n", DAHDI_VERSION);
+
+ dahdi_class = class_create(THIS_MODULE, "dahdi");
+ if (!dahdi_class) {
+ res = -EEXIST;
+ goto cleanup;
+ }
+
+ dahdi_dbg(DEVICES, "Creating /dev/dahdi/timer:\n");
+ dev = MAKE_DAHDI_DEV(DAHDI_TIMER, "dahdi!timer");
+ if (IS_ERR(dev)) {
+ res = PTR_ERR(dev);
+ goto cleanup;
+ }
+ dummy_dev.timer = 1;
+
+ dahdi_dbg(DEVICES, "Creating /dev/dahdi/channel:\n");
+ dev = MAKE_DAHDI_DEV(DAHDI_CHANNEL, "dahdi!channel");
+ if (IS_ERR(dev)) {
+ res = PTR_ERR(dev);
+ goto cleanup;
+ }
+ dummy_dev.channel = 1;
+
+ dahdi_dbg(DEVICES, "Creating /dev/dahdi/pseudo:\n");
+ dev = MAKE_DAHDI_DEV(DAHDI_PSEUDO, "dahdi!pseudo");
+ if (IS_ERR(dev)) {
+ res = PTR_ERR(dev);
+ goto cleanup;
+ }
+ dummy_dev.pseudo = 1;
+
+ dahdi_dbg(DEVICES, "Creating /dev/dahdi/ctl:\n");
+ dev = MAKE_DAHDI_DEV(DAHDI_CTL, "dahdi!ctl");
+ if (IS_ERR(dev)) {
+ res = PTR_ERR(dev);
+ goto cleanup;
+ }
+ dummy_dev.ctl = 1;
+
+ return 0;
+
+cleanup:
+ dahdi_sysfs_exit();
+ return res;
+}
+
diff --git a/drivers/dahdi/dahdi.h b/drivers/dahdi/dahdi.h
new file mode 100644
index 0000000..54960dd
--- /dev/null
+++ b/drivers/dahdi/dahdi.h
@@ -0,0 +1,36 @@
+#ifndef _DAHDI_H
+#define _DAHDI_H
+
+/* dahdi.h: headers intended only for the dahdi.ko module.
+ * Not to be included elsewhere
+ *
+ * Written by Tzafrir Cohen <tzafrir.cohen@xorcom.com>
+ * Copyright (C) 2011, Xorcom
+ *
+ * All rights reserved.
+ *
+ */
+
+/*
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2 as published by the
+ * Free Software Foundation. See the LICENSE file included with
+ * this program for more details.
+ */
+
+extern int debug;
+
+int dahdi_register_chardev(struct dahdi_chardev *dev);
+int dahdi_unregister_chardev(struct dahdi_chardev *dev);
+int span_sysfs_create(struct dahdi_span *span);
+void span_sysfs_remove(struct dahdi_span *span);
+int __init dahdi_sysfs_init(const struct file_operations *dahdi_fops);
+void dahdi_sysfs_exit(void);
+
+#endif /* _DAHDI_H */