2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* Dynamic Span Interface for DAHDI
|
|
|
|
*
|
|
|
|
* Written by Mark Spencer <markster@digium.com>
|
|
|
|
*
|
2010-09-24 05:38:57 +08:00
|
|
|
* Copyright (C) 2001-2010, Digium, Inc.
|
2010-08-28 05:59:27 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/kmod.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
|
|
|
|
#include <dahdi/kernel.h>
|
|
|
|
|
2011-01-04 02:25:45 +08:00
|
|
|
#ifndef DAHDI_SYNC_TICK
|
|
|
|
#error "Dynamic support depends on DAHDI_SYNC_TICK being enabled."
|
|
|
|
#endif
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* Tasklets provide better system interactive response at the cost of the
|
|
|
|
* possibility of losing a frame of data at very infrequent intervals. If
|
|
|
|
* you are more concerned with the performance of your machine, enable the
|
|
|
|
* tasklets. If you are strict about absolutely no drops, then do not enable
|
|
|
|
* tasklets.
|
|
|
|
*/
|
|
|
|
|
2011-01-04 02:25:51 +08:00
|
|
|
#undef ENABLE_TASKLETS
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Dynamic spans implemented using TDM over X with standard message
|
|
|
|
* types. Message format is as follows:
|
|
|
|
*
|
|
|
|
* Byte #: Meaning
|
|
|
|
* 0 Number of samples per channel
|
|
|
|
* 1 Current flags on span
|
|
|
|
* Bit 0: Yellow Alarm
|
|
|
|
* Bit 1: Sig bits present
|
|
|
|
* Bits 2-7: reserved for future use
|
|
|
|
* 2-3 16-bit counter value for detecting drops, network byte order.
|
|
|
|
* 4-5 Number of channels in the message, network byte order
|
|
|
|
* 6... 16-bit words, containing sig bits for each
|
|
|
|
* four channels, least significant 4 bits being
|
|
|
|
* the least significant channel, network byte order.
|
|
|
|
* the rest data for each channel, all samples per channel
|
|
|
|
before moving to the next.
|
|
|
|
*/
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
#define DAHDI_DYNAMIC_FLAG_YELLOW_ALARM (1 << 0)
|
|
|
|
#define DAHDI_DYNAMIC_FLAG_SIGBITS_PRESENT (1 << 1)
|
|
|
|
#define DAHDI_DYNAMIC_FLAG_LOOPBACK (1 << 2)
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
#define ERR_NSAMP (1 << 16)
|
|
|
|
#define ERR_NCHAN (1 << 17)
|
|
|
|
#define ERR_LEN (1 << 18)
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
static int dahdi_dynamic_init(void);
|
|
|
|
static void dahdi_dynamic_cleanup(void);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
#ifdef ENABLE_TASKLETS
|
|
|
|
static int taskletrun;
|
|
|
|
static int taskletsched;
|
|
|
|
static int taskletpending;
|
|
|
|
static int taskletexec;
|
|
|
|
static int txerrors;
|
2011-01-04 02:25:05 +08:00
|
|
|
static struct tasklet_struct dahdi_dynamic_tlet;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
static void dahdi_dynamic_tasklet(unsigned long data);
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
|
2011-01-04 02:26:04 +08:00
|
|
|
static DEFINE_MUTEX(dspan_mutex);
|
2010-08-28 05:59:27 +08:00
|
|
|
static DEFINE_SPINLOCK(dspan_lock);
|
|
|
|
static DEFINE_SPINLOCK(driver_lock);
|
|
|
|
|
|
|
|
static LIST_HEAD(dspan_list);
|
|
|
|
static LIST_HEAD(driver_list);
|
|
|
|
|
|
|
|
static int debug = 0;
|
|
|
|
|
|
|
|
static int hasmaster = 0;
|
|
|
|
|
|
|
|
static void checkmaster(void)
|
|
|
|
{
|
|
|
|
int newhasmaster=0;
|
|
|
|
int best = 9999999;
|
2011-01-04 02:25:05 +08:00
|
|
|
struct dahdi_dynamic *d, *master = NULL;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
list_for_each_entry_rcu(d, &dspan_list, list) {
|
|
|
|
if (d->timing) {
|
|
|
|
d->master = 0;
|
|
|
|
if (!(d->span.alarms & DAHDI_ALARM_RED) &&
|
2011-01-04 02:25:23 +08:00
|
|
|
(d->timing < best)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
/* If not in alarm and they're
|
|
|
|
a better timing source, use them */
|
2011-01-04 02:25:05 +08:00
|
|
|
master = d;
|
|
|
|
best = d->timing;
|
2010-08-28 05:59:27 +08:00
|
|
|
newhasmaster = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hasmaster = newhasmaster;
|
|
|
|
/* Mark the new master if there is one */
|
|
|
|
if (master)
|
|
|
|
master->master = 1;
|
|
|
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
if (master)
|
|
|
|
printk(KERN_INFO "TDMoX: New master: %s\n", master->span.name);
|
|
|
|
else
|
|
|
|
printk(KERN_INFO "TDMoX: No master.\n");
|
|
|
|
}
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
static void dahdi_dynamic_sendmessage(struct dahdi_dynamic *d)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2011-01-04 02:25:05 +08:00
|
|
|
unsigned char *buf = d->msgbuf;
|
2010-08-28 05:59:27 +08:00
|
|
|
unsigned short bits;
|
|
|
|
int msglen = 0;
|
|
|
|
int x;
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
/* Byte 0: Number of samples per channel */
|
|
|
|
*buf = DAHDI_CHUNKSIZE;
|
|
|
|
buf++; msglen++;
|
|
|
|
|
|
|
|
/* Byte 1: Flags */
|
|
|
|
*buf = 0;
|
2011-01-04 02:25:05 +08:00
|
|
|
if (d->span.alarms & DAHDI_ALARM_RED)
|
|
|
|
*buf |= DAHDI_DYNAMIC_FLAG_YELLOW_ALARM;
|
|
|
|
*buf |= DAHDI_DYNAMIC_FLAG_SIGBITS_PRESENT;
|
2010-08-28 05:59:27 +08:00
|
|
|
buf++; msglen++;
|
|
|
|
|
|
|
|
/* Bytes 2-3: Transmit counter */
|
2011-01-04 02:25:05 +08:00
|
|
|
*((unsigned short *)buf) = htons((unsigned short)d->txcnt);
|
|
|
|
d->txcnt++;
|
2010-08-28 05:59:27 +08:00
|
|
|
buf++; msglen++;
|
|
|
|
buf++; msglen++;
|
|
|
|
|
|
|
|
/* Bytes 4-5: Number of channels */
|
2011-01-04 02:25:05 +08:00
|
|
|
*((unsigned short *)buf) = htons((unsigned short)d->span.channels);
|
2010-08-28 05:59:27 +08:00
|
|
|
buf++; msglen++;
|
|
|
|
buf++; msglen++;
|
|
|
|
bits = 0;
|
|
|
|
offset = 0;
|
2011-01-04 02:25:05 +08:00
|
|
|
for (x = 0; x < d->span.channels; x++) {
|
2010-08-28 05:59:27 +08:00
|
|
|
offset = x % 4;
|
2011-01-04 02:25:05 +08:00
|
|
|
bits |= (d->chans[x]->txsig & 0xf) << (offset << 2);
|
2010-08-28 05:59:27 +08:00
|
|
|
if (offset == 3) {
|
|
|
|
/* Write the bits when we have four channels */
|
|
|
|
*((unsigned short *)buf) = htons(bits);
|
|
|
|
buf++; msglen++;
|
|
|
|
buf++; msglen++;
|
|
|
|
bits = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset != 3) {
|
|
|
|
/* Finish it off if it's not done already */
|
|
|
|
*((unsigned short *)buf) = htons(bits);
|
|
|
|
buf++; msglen++;
|
|
|
|
buf++; msglen++;
|
|
|
|
}
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
for (x = 0; x < d->span.channels; x++) {
|
|
|
|
memcpy(buf, d->chans[x]->writechunk, DAHDI_CHUNKSIZE);
|
2010-08-28 05:59:27 +08:00
|
|
|
buf += DAHDI_CHUNKSIZE;
|
|
|
|
msglen += DAHDI_CHUNKSIZE;
|
|
|
|
}
|
|
|
|
|
2011-01-04 02:25:56 +08:00
|
|
|
d->driver->transmit(d, d->msgbuf, msglen);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
static void __dahdi_dynamic_run(void)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2011-01-04 02:25:05 +08:00
|
|
|
struct dahdi_dynamic *d;
|
2010-08-28 05:59:27 +08:00
|
|
|
struct dahdi_dynamic_driver *drv;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
2011-01-04 02:25:05 +08:00
|
|
|
list_for_each_entry_rcu(d, &dspan_list, list) {
|
2011-01-04 02:25:23 +08:00
|
|
|
dahdi_transmit(&d->span);
|
|
|
|
/* Handle all transmissions now */
|
|
|
|
dahdi_dynamic_sendmessage(d);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry_rcu(drv, &driver_list, list) {
|
|
|
|
/* Flush any traffic still pending in the driver */
|
|
|
|
if (drv->flush) {
|
|
|
|
drv->flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ENABLE_TASKLETS
|
2011-01-04 02:25:05 +08:00
|
|
|
static void dahdi_dynamic_run(void)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
|
|
|
if (likely(!taskletpending)) {
|
|
|
|
taskletpending = 1;
|
|
|
|
taskletsched++;
|
2011-01-04 02:25:05 +08:00
|
|
|
tasklet_hi_schedule(&dahdi_dynamic_tlet);
|
2010-08-28 05:59:27 +08:00
|
|
|
} else {
|
|
|
|
txerrors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2011-01-04 02:25:05 +08:00
|
|
|
#define dahdi_dynamic_run __dahdi_dynamic_run
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline struct dahdi_dynamic *dynamic_from_span(struct dahdi_span *span)
|
|
|
|
{
|
|
|
|
return container_of(span, struct dahdi_dynamic, span);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dahdi_dynamic_receive(struct dahdi_span *span, unsigned char *msg, int msglen)
|
|
|
|
{
|
2011-01-04 02:25:05 +08:00
|
|
|
struct dahdi_dynamic *dtd = dynamic_from_span(span);
|
2010-08-28 05:59:27 +08:00
|
|
|
int newerr=0;
|
|
|
|
int sflags;
|
|
|
|
int xlen;
|
|
|
|
int x, bits, sig;
|
|
|
|
int nchans, master;
|
|
|
|
int newalarm;
|
|
|
|
unsigned short rxpos, rxcnt;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
|
|
|
if (unlikely(msglen < 6)) {
|
|
|
|
rcu_read_unlock();
|
|
|
|
newerr = ERR_LEN;
|
2011-01-04 02:25:05 +08:00
|
|
|
if (newerr != dtd->err)
|
2010-08-28 05:59:27 +08:00
|
|
|
printk(KERN_NOTICE "Span %s: Insufficient samples for header (only %d)\n", span->name, msglen);
|
2011-01-04 02:25:05 +08:00
|
|
|
dtd->err = newerr;
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* First, check the chunksize */
|
|
|
|
if (unlikely(*msg != DAHDI_CHUNKSIZE)) {
|
|
|
|
rcu_read_unlock();
|
|
|
|
newerr = ERR_NSAMP | msg[0];
|
2011-01-04 02:25:05 +08:00
|
|
|
if (newerr != dtd->err)
|
2010-08-28 05:59:27 +08:00
|
|
|
printk(KERN_NOTICE "Span %s: Expected %d samples, but receiving %d\n", span->name, DAHDI_CHUNKSIZE, msg[0]);
|
2011-01-04 02:25:05 +08:00
|
|
|
dtd->err = newerr;
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
msg++;
|
|
|
|
sflags = *msg;
|
|
|
|
msg++;
|
|
|
|
|
|
|
|
rxpos = ntohs(*((unsigned short *)msg));
|
|
|
|
msg++;
|
|
|
|
msg++;
|
|
|
|
|
|
|
|
nchans = ntohs(*((unsigned short *)msg));
|
|
|
|
if (unlikely(nchans != span->channels)) {
|
|
|
|
rcu_read_unlock();
|
|
|
|
newerr = ERR_NCHAN | nchans;
|
2011-01-04 02:25:05 +08:00
|
|
|
if (newerr != dtd->err)
|
2010-08-28 05:59:27 +08:00
|
|
|
printk(KERN_NOTICE "Span %s: Expected %d channels, but receiving %d\n", span->name, span->channels, nchans);
|
2011-01-04 02:25:05 +08:00
|
|
|
dtd->err = newerr;
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
msg++;
|
|
|
|
msg++;
|
|
|
|
|
|
|
|
/* Okay now we've accepted the header, lets check our message
|
|
|
|
length... */
|
|
|
|
|
|
|
|
/* Start with header */
|
|
|
|
xlen = 6;
|
|
|
|
/* Add samples of audio */
|
|
|
|
xlen += nchans * DAHDI_CHUNKSIZE;
|
|
|
|
/* If RBS info is there, add that */
|
2011-01-04 02:25:05 +08:00
|
|
|
if (sflags & DAHDI_DYNAMIC_FLAG_SIGBITS_PRESENT) {
|
2010-08-28 05:59:27 +08:00
|
|
|
/* Account for sigbits -- one short per 4 channels*/
|
|
|
|
xlen += ((nchans + 3) / 4) * 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlikely(xlen != msglen)) {
|
|
|
|
rcu_read_unlock();
|
|
|
|
newerr = ERR_LEN | xlen;
|
2011-01-04 02:25:05 +08:00
|
|
|
if (newerr != dtd->err)
|
2010-08-28 05:59:27 +08:00
|
|
|
printk(KERN_NOTICE "Span %s: Expected message size %d, but was %d instead\n", span->name, xlen, msglen);
|
2011-01-04 02:25:05 +08:00
|
|
|
dtd->err = newerr;
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bits = 0;
|
|
|
|
|
|
|
|
/* Record sigbits if present */
|
2011-01-04 02:25:05 +08:00
|
|
|
if (sflags & DAHDI_DYNAMIC_FLAG_SIGBITS_PRESENT) {
|
2010-08-28 05:59:27 +08:00
|
|
|
for (x=0;x<nchans;x++) {
|
|
|
|
if (!(x%4)) {
|
|
|
|
/* Get new bits */
|
|
|
|
bits = ntohs(*((unsigned short *)msg));
|
|
|
|
msg++;
|
|
|
|
msg++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pick the right bits */
|
|
|
|
sig = (bits >> ((x % 4) << 2)) & 0xff;
|
|
|
|
|
|
|
|
/* Update signalling if appropriate */
|
|
|
|
if (sig != span->chans[x]->rxsig)
|
|
|
|
dahdi_rbsbits(span->chans[x], sig);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Record data for channels */
|
|
|
|
for (x=0;x<nchans;x++) {
|
|
|
|
memcpy(span->chans[x]->readchunk, msg, DAHDI_CHUNKSIZE);
|
|
|
|
msg += DAHDI_CHUNKSIZE;
|
|
|
|
}
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
master = dtd->master;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
rxcnt = dtd->rxcnt;
|
|
|
|
dtd->rxcnt = rxpos+1;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/* Keep track of last received packet */
|
2011-01-04 02:25:05 +08:00
|
|
|
dtd->rxjif = jiffies;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
/* Check for Yellow alarm */
|
|
|
|
newalarm = span->alarms & ~(DAHDI_ALARM_YELLOW | DAHDI_ALARM_RED);
|
2011-01-04 02:25:05 +08:00
|
|
|
if (sflags & DAHDI_DYNAMIC_FLAG_YELLOW_ALARM)
|
2010-08-28 05:59:27 +08:00
|
|
|
newalarm |= DAHDI_ALARM_YELLOW;
|
|
|
|
|
|
|
|
if (newalarm != span->alarms) {
|
|
|
|
span->alarms = newalarm;
|
|
|
|
dahdi_alarm_notify(span);
|
|
|
|
checkmaster();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* note if we had a missing packet */
|
|
|
|
if (unlikely(rxpos != rxcnt))
|
|
|
|
printk(KERN_NOTICE "Span %s: Expected seq no %d, but received %d instead\n", span->name, rxcnt, rxpos);
|
|
|
|
|
2011-08-11 03:22:01 +08:00
|
|
|
dahdi_ec_span(span);
|
|
|
|
dahdi_receive(span);
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
/* If this is our master span, then run everything */
|
|
|
|
if (master)
|
2011-01-04 02:25:05 +08:00
|
|
|
dahdi_dynamic_run();
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2011-01-04 02:25:27 +08:00
|
|
|
EXPORT_SYMBOL(dahdi_dynamic_receive);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2011-01-04 02:25:23 +08:00
|
|
|
/**
|
|
|
|
* dahdi_dynamic_release() - Free the memory associated with the dahdi_dynamic.
|
|
|
|
* @kref: Pointer to kref embedded in dahdi_dynamic structure.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void dahdi_dynamic_release(struct kref *kref)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2011-01-04 02:25:23 +08:00
|
|
|
struct dahdi_dynamic *d = container_of(kref, struct dahdi_dynamic,
|
|
|
|
kref);
|
2010-08-28 05:59:27 +08:00
|
|
|
unsigned int x;
|
|
|
|
|
2011-01-04 02:25:23 +08:00
|
|
|
WARN_ON(test_bit(DAHDI_FLAGBIT_REGISTERED, &d->span.flags));
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2011-01-04 02:25:23 +08:00
|
|
|
if (d->pvt) {
|
2011-01-04 02:25:32 +08:00
|
|
|
if (d->driver && d->driver->destroy) {
|
|
|
|
__module_get(d->driver->owner);
|
2011-01-04 02:25:56 +08:00
|
|
|
d->driver->destroy(d);
|
2011-01-04 02:25:32 +08:00
|
|
|
module_put(d->driver->owner);
|
|
|
|
} else {
|
2011-01-04 02:25:23 +08:00
|
|
|
WARN_ON(1);
|
2011-01-04 02:25:32 +08:00
|
|
|
}
|
2011-01-04 02:25:23 +08:00
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
kfree(d->msgbuf);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
for (x = 0; x < d->span.channels; x++)
|
|
|
|
kfree(d->chans[x]);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
kfree(d);
|
2011-01-04 02:25:23 +08:00
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2011-01-04 02:25:23 +08:00
|
|
|
static inline int dynamic_put(struct dahdi_dynamic *d)
|
|
|
|
{
|
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 12)
|
|
|
|
kref_put(&d->kref, dahdi_dynamic_release);
|
|
|
|
return 1;
|
|
|
|
#else
|
|
|
|
return kref_put(&d->kref, dahdi_dynamic_release);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void dynamic_get(struct dahdi_dynamic *d)
|
|
|
|
{
|
|
|
|
kref_get(&d->kref);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
static struct dahdi_dynamic *find_dynamic(struct dahdi_dynamic_span *dds)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2011-01-04 02:25:05 +08:00
|
|
|
struct dahdi_dynamic *d = NULL, *found = NULL;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
rcu_read_lock();
|
2011-01-04 02:25:05 +08:00
|
|
|
list_for_each_entry_rcu(d, &dspan_list, list) {
|
|
|
|
if (!strcmp(d->dname, dds->driver) &&
|
|
|
|
!strcmp(d->addr, dds->addr)) {
|
2011-01-04 02:25:23 +08:00
|
|
|
dynamic_get(d);
|
2011-01-04 02:25:05 +08:00
|
|
|
found = d;
|
2010-08-28 05:59:27 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2011-01-04 02:25:13 +08:00
|
|
|
static struct dahdi_dynamic_driver *find_driver(const char *name)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2011-01-04 02:25:05 +08:00
|
|
|
struct dahdi_dynamic_driver *dtd, *found = NULL;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
rcu_read_lock();
|
2011-01-04 02:25:05 +08:00
|
|
|
list_for_each_entry_rcu(dtd, &driver_list, list) {
|
2010-08-28 05:59:27 +08:00
|
|
|
/* here's our driver */
|
2011-01-04 02:25:05 +08:00
|
|
|
if (!strcmp(name, dtd->name)) {
|
|
|
|
found = dtd;
|
2010-08-28 05:59:27 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2011-01-04 02:26:04 +08:00
|
|
|
static int _destroy_dynamic(struct dahdi_dynamic_span *dds)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
2011-01-04 02:25:05 +08:00
|
|
|
struct dahdi_dynamic *d;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
d = find_dynamic(dds);
|
|
|
|
if (unlikely(!d))
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2011-01-04 02:25:32 +08:00
|
|
|
/* We shouldn't have more than the two references at this point. If
|
|
|
|
* we do, there are probably channels that are still opened. */
|
|
|
|
if (atomic_read(&d->kref.refcount) > 2) {
|
|
|
|
dynamic_put(d);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EBUSY;
|
2011-01-04 02:25:32 +08:00
|
|
|
}
|
2011-01-04 02:25:23 +08:00
|
|
|
|
|
|
|
dahdi_unregister(&d->span);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&dspan_lock, flags);
|
2011-01-04 02:25:05 +08:00
|
|
|
list_del_rcu(&d->list);
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_unlock_irqrestore(&dspan_lock, flags);
|
|
|
|
synchronize_rcu();
|
|
|
|
|
2011-01-04 02:25:23 +08:00
|
|
|
/* One since we've removed the item from the list... */
|
|
|
|
dynamic_put(d);
|
|
|
|
/* ...and one for find_dynamic. */
|
|
|
|
dynamic_put(d);
|
2010-08-28 05:59:27 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-04 02:26:04 +08:00
|
|
|
static int destroy_dynamic(struct dahdi_dynamic_span *dds)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
mutex_lock(&dspan_mutex);
|
|
|
|
ret = _destroy_dynamic(dds);
|
|
|
|
mutex_unlock(&dspan_mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
static int dahdi_dynamic_rbsbits(struct dahdi_chan *chan, int bits)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
|
|
|
/* Don't have to do anything */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
static int dahdi_dynamic_open(struct dahdi_chan *chan)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2011-01-04 02:25:05 +08:00
|
|
|
struct dahdi_dynamic *d = dynamic_from_span(chan->span);
|
2011-01-04 02:25:32 +08:00
|
|
|
if (!try_module_get(d->driver->owner))
|
|
|
|
return -ENODEV;
|
2011-01-04 02:25:23 +08:00
|
|
|
dynamic_get(d);
|
2010-08-28 05:59:27 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-06-03 04:01:34 +08:00
|
|
|
static int dahdi_dynamic_chanconfig(struct file *file,
|
|
|
|
struct dahdi_chan *chan, int sigtype)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
static int dahdi_dynamic_close(struct dahdi_chan *chan)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2011-01-04 02:25:05 +08:00
|
|
|
struct dahdi_dynamic *d = dynamic_from_span(chan->span);
|
2011-01-04 02:25:32 +08:00
|
|
|
struct module *owner = d->driver->owner;
|
2011-01-04 02:25:23 +08:00
|
|
|
dynamic_put(d);
|
2011-01-04 02:25:32 +08:00
|
|
|
module_put(owner);
|
2010-08-28 05:59:27 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-04 02:26:39 +08:00
|
|
|
static void dahdi_dynamic_sync_tick(struct dahdi_span *span, int is_master)
|
2011-01-04 02:25:45 +08:00
|
|
|
{
|
|
|
|
struct dahdi_dynamic *head;
|
|
|
|
struct dahdi_dynamic *d = dynamic_from_span(span);
|
|
|
|
|
|
|
|
if (hasmaster)
|
2011-01-04 02:26:39 +08:00
|
|
|
return;
|
2011-01-04 02:25:45 +08:00
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
head = list_entry(dspan_list.next, struct dahdi_dynamic, list);
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
if (d == head)
|
|
|
|
dahdi_dynamic_run();
|
2011-01-04 02:26:39 +08:00
|
|
|
return;
|
2011-01-04 02:25:45 +08:00
|
|
|
}
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
static const struct dahdi_span_ops dynamic_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
2011-01-04 02:25:05 +08:00
|
|
|
.rbsbits = dahdi_dynamic_rbsbits,
|
|
|
|
.open = dahdi_dynamic_open,
|
|
|
|
.close = dahdi_dynamic_close,
|
|
|
|
.chanconfig = dahdi_dynamic_chanconfig,
|
2011-01-04 02:25:45 +08:00
|
|
|
.sync_tick = dahdi_dynamic_sync_tick,
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
2011-01-04 02:26:04 +08:00
|
|
|
static int _create_dynamic(struct dahdi_dynamic_span *dds)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2011-01-04 02:25:56 +08:00
|
|
|
int res = 0;
|
2011-01-04 02:25:05 +08:00
|
|
|
struct dahdi_dynamic *d;
|
|
|
|
struct dahdi_dynamic_driver *dtd;
|
2010-08-28 05:59:27 +08:00
|
|
|
unsigned long flags;
|
|
|
|
int x;
|
|
|
|
int bufsize;
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
if (dds->numchans < 1) {
|
|
|
|
printk(KERN_NOTICE "Can't be less than 1 channel (%d)!\n",
|
|
|
|
dds->numchans);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2011-01-04 02:25:56 +08:00
|
|
|
if (dds->numchans >= ARRAY_SIZE(d->chans)) {
|
2011-01-04 02:25:05 +08:00
|
|
|
printk(KERN_NOTICE "Can't create dynamic span with greater "
|
|
|
|
"than %d channels. See dahdi_dynamic.c and increase "
|
|
|
|
"DAHDI_DYNAMIC_MAX_CHANS\n", dds->numchans);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
d = find_dynamic(dds);
|
2011-01-04 02:25:23 +08:00
|
|
|
if (d) {
|
|
|
|
dynamic_put(d);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EEXIST;
|
2011-01-04 02:25:23 +08:00
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2011-01-04 02:25:09 +08:00
|
|
|
d = kzalloc(sizeof(*d), GFP_KERNEL);
|
2011-01-04 02:25:05 +08:00
|
|
|
if (!d)
|
2010-08-28 05:59:27 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2011-01-04 02:25:23 +08:00
|
|
|
kref_init(&d->kref);
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
for (x = 0; x < dds->numchans; x++) {
|
2011-01-04 02:25:09 +08:00
|
|
|
d->chans[x] = kzalloc(sizeof(*d->chans[x]), GFP_KERNEL);
|
2011-01-04 02:25:05 +08:00
|
|
|
if (!d->chans[x]) {
|
2011-01-04 02:25:23 +08:00
|
|
|
dynamic_put(d);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2011-01-04 02:25:23 +08:00
|
|
|
d->span.channels++;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate message buffer with sample space and header space */
|
2011-01-04 02:25:05 +08:00
|
|
|
bufsize = dds->numchans * DAHDI_CHUNKSIZE + dds->numchans / 4 + 48;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2011-01-04 02:25:09 +08:00
|
|
|
d->msgbuf = kzalloc(bufsize, GFP_KERNEL);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
if (!d->msgbuf) {
|
2011-01-04 02:25:23 +08:00
|
|
|
dynamic_put(d);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup parameters properly assuming we're going to be okay. */
|
2011-01-04 02:26:29 +08:00
|
|
|
strlcpy(d->dname, dds->driver, sizeof(d->dname));
|
|
|
|
strlcpy(d->addr, dds->addr, sizeof(d->addr));
|
2011-01-04 02:25:05 +08:00
|
|
|
d->timing = dds->timing;
|
|
|
|
sprintf(d->span.name, "DYN/%s/%s", dds->driver, dds->addr);
|
|
|
|
sprintf(d->span.desc, "Dynamic '%s' span at '%s'",
|
|
|
|
dds->driver, dds->addr);
|
|
|
|
d->span.deflaw = DAHDI_LAW_MULAW;
|
|
|
|
d->span.flags |= DAHDI_FLAG_RBS;
|
|
|
|
d->span.chans = d->chans;
|
|
|
|
d->span.ops = &dynamic_ops;
|
|
|
|
for (x = 0; x < d->span.channels; x++) {
|
|
|
|
sprintf(d->chans[x]->name, "DYN/%s/%s/%d",
|
|
|
|
dds->driver, dds->addr, x+1);
|
|
|
|
d->chans[x]->sigcap = DAHDI_SIG_EM | DAHDI_SIG_CLEAR |
|
|
|
|
DAHDI_SIG_FXSLS | DAHDI_SIG_FXSKS |
|
|
|
|
DAHDI_SIG_FXSGS | DAHDI_SIG_FXOLS |
|
|
|
|
DAHDI_SIG_FXOKS | DAHDI_SIG_FXOGS |
|
|
|
|
DAHDI_SIG_SF | DAHDI_SIG_DACS_RBS |
|
|
|
|
DAHDI_SIG_CAS;
|
|
|
|
d->chans[x]->chanpos = x + 1;
|
|
|
|
d->chans[x]->pvt = d;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
dtd = find_driver(dds->driver);
|
|
|
|
if (!dtd) {
|
|
|
|
request_module("dahdi_dynamic_%s", dds->driver);
|
|
|
|
dtd = find_driver(dds->driver);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
if (!dtd) {
|
|
|
|
printk(KERN_NOTICE "No such driver '%s' for dynamic span\n",
|
|
|
|
dds->driver);
|
2011-01-04 02:25:23 +08:00
|
|
|
dynamic_put(d);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-01-04 02:25:32 +08:00
|
|
|
if (!try_module_get(dtd->owner)) {
|
|
|
|
dynamic_put(d);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remember the driver. We also give our reference to the driver to
|
|
|
|
* the dahdi_dyanmic here. Do not access dtd directly now. */
|
|
|
|
d->driver = dtd;
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
/* Create the stuff */
|
2011-01-04 02:25:56 +08:00
|
|
|
res = dtd->create(d, d->addr);
|
|
|
|
if (res) {
|
2011-01-04 02:25:05 +08:00
|
|
|
printk(KERN_NOTICE "Driver '%s' (%s) rejected address '%s'\n",
|
|
|
|
dtd->name, dtd->desc, d->addr);
|
2011-01-04 02:25:23 +08:00
|
|
|
dynamic_put(d);
|
2011-01-04 02:25:32 +08:00
|
|
|
module_put(dtd->owner);
|
2011-01-04 02:25:56 +08:00
|
|
|
return res;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Whee! We're created. Now register the span */
|
2011-01-04 02:25:05 +08:00
|
|
|
if (dahdi_register(&d->span, 0)) {
|
|
|
|
printk(KERN_NOTICE "Unable to register span '%s'\n",
|
|
|
|
d->span.name);
|
2011-01-04 02:25:23 +08:00
|
|
|
dynamic_put(d);
|
2011-01-04 02:25:32 +08:00
|
|
|
module_put(dtd->owner);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-01-04 02:25:23 +08:00
|
|
|
x = d->span.spanno;
|
|
|
|
|
|
|
|
/* Transfer our reference to the dspan_list. Do not touch d after
|
|
|
|
* this point. It also must remain on the list while registered. */
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_lock_irqsave(&dspan_lock, flags);
|
2011-01-04 02:25:05 +08:00
|
|
|
list_add_rcu(&d->list, &dspan_list);
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_unlock_irqrestore(&dspan_lock, flags);
|
|
|
|
|
|
|
|
checkmaster();
|
|
|
|
|
2011-01-04 02:25:32 +08:00
|
|
|
module_put(dtd->owner);
|
2011-01-04 02:25:23 +08:00
|
|
|
return x;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
2011-01-04 02:26:04 +08:00
|
|
|
static int create_dynamic(struct dahdi_dynamic_span *dds)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
mutex_lock(&dspan_mutex);
|
|
|
|
ret = _create_dynamic(dds);
|
|
|
|
mutex_unlock(&dspan_mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
#ifdef ENABLE_TASKLETS
|
2011-01-04 02:25:05 +08:00
|
|
|
static void dahdi_dynamic_tasklet(unsigned long data)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
|
|
|
taskletrun++;
|
|
|
|
if (taskletpending) {
|
|
|
|
taskletexec++;
|
2011-01-04 02:25:05 +08:00
|
|
|
__dahdi_dynamic_run();
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
taskletpending = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
static int dahdi_dynamic_ioctl(unsigned int cmd, unsigned long data)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2011-01-04 02:25:05 +08:00
|
|
|
struct dahdi_dynamic_span dds;
|
2010-08-28 05:59:27 +08:00
|
|
|
int res;
|
|
|
|
switch(cmd) {
|
|
|
|
case DAHDI_DYNAMIC_CREATE:
|
2011-01-04 02:25:05 +08:00
|
|
|
if (copy_from_user(&dds, (__user const void *)data,
|
|
|
|
sizeof(dds)))
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EFAULT;
|
|
|
|
if (debug)
|
|
|
|
printk(KERN_DEBUG "Dynamic Create\n");
|
2011-01-04 02:25:05 +08:00
|
|
|
res = create_dynamic(&dds);
|
2010-08-28 05:59:27 +08:00
|
|
|
if (res < 0)
|
|
|
|
return res;
|
2011-01-04 02:25:05 +08:00
|
|
|
dds.spanno = res;
|
2010-08-28 05:59:27 +08:00
|
|
|
/* Let them know the new span number */
|
2011-01-04 02:25:05 +08:00
|
|
|
if (copy_to_user((__user void *) data, &dds, sizeof(dds)))
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
case DAHDI_DYNAMIC_DESTROY:
|
2011-01-04 02:25:05 +08:00
|
|
|
if (copy_from_user(&dds, (__user const void *)data,
|
|
|
|
sizeof(dds)))
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EFAULT;
|
|
|
|
if (debug)
|
|
|
|
printk(KERN_DEBUG "Dynamic Destroy\n");
|
2011-01-04 02:25:05 +08:00
|
|
|
return destroy_dynamic(&dds);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
|
2011-01-04 02:25:27 +08:00
|
|
|
int dahdi_dynamic_register_driver(struct dahdi_dynamic_driver *dri)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int res = 0;
|
|
|
|
|
2011-01-04 02:25:32 +08:00
|
|
|
if (!dri->owner)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
if (find_driver(dri->name)) {
|
|
|
|
res = -1;
|
|
|
|
} else {
|
|
|
|
spin_lock_irqsave(&driver_lock, flags);
|
|
|
|
list_add_rcu(&dri->list, &driver_list);
|
|
|
|
spin_unlock_irqrestore(&driver_lock, flags);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2011-01-04 02:25:27 +08:00
|
|
|
EXPORT_SYMBOL(dahdi_dynamic_register_driver);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2011-01-04 02:25:27 +08:00
|
|
|
void dahdi_dynamic_unregister_driver(struct dahdi_dynamic_driver *dri)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2011-01-04 02:25:32 +08:00
|
|
|
struct dahdi_dynamic *d, *n;
|
2010-08-28 05:59:27 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2011-01-04 02:26:04 +08:00
|
|
|
mutex_lock(&dspan_mutex);
|
|
|
|
|
2011-01-04 02:25:32 +08:00
|
|
|
list_for_each_entry_safe(d, n, &dspan_list, list) {
|
2011-01-04 02:25:05 +08:00
|
|
|
if (d->driver == dri) {
|
2011-01-04 02:25:32 +08:00
|
|
|
if (d->pvt) {
|
|
|
|
if (d->driver && d->driver->destroy) {
|
|
|
|
__module_get(d->driver->owner);
|
2011-01-04 02:25:56 +08:00
|
|
|
d->driver->destroy(d);
|
2011-01-04 02:25:32 +08:00
|
|
|
module_put(d->driver->owner);
|
|
|
|
} else {
|
|
|
|
WARN_ON(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dahdi_unregister(&d->span);
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_lock_irqsave(&dspan_lock, flags);
|
2011-01-04 02:25:05 +08:00
|
|
|
list_del_rcu(&d->list);
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_unlock_irqrestore(&dspan_lock, flags);
|
|
|
|
synchronize_rcu();
|
2011-01-04 02:25:23 +08:00
|
|
|
dynamic_put(d);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
}
|
2011-01-04 02:25:32 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&driver_lock, flags);
|
|
|
|
list_del_rcu(&dri->list);
|
|
|
|
spin_unlock_irqrestore(&driver_lock, flags);
|
|
|
|
synchronize_rcu();
|
2011-01-04 02:26:04 +08:00
|
|
|
|
|
|
|
mutex_unlock(&dspan_mutex);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2011-01-04 02:25:27 +08:00
|
|
|
EXPORT_SYMBOL(dahdi_dynamic_unregister_driver);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
static struct timer_list alarmcheck;
|
|
|
|
|
|
|
|
static void check_for_red_alarm(unsigned long ignored)
|
|
|
|
{
|
|
|
|
int newalarm;
|
|
|
|
int alarmchanged = 0;
|
2011-01-04 02:25:05 +08:00
|
|
|
struct dahdi_dynamic *d;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
rcu_read_lock();
|
2011-01-04 02:25:05 +08:00
|
|
|
list_for_each_entry_rcu(d, &dspan_list, list) {
|
|
|
|
newalarm = d->span.alarms & ~DAHDI_ALARM_RED;
|
2010-08-28 05:59:27 +08:00
|
|
|
/* If nothing received for a second, consider that RED ALARM */
|
2011-01-04 02:25:05 +08:00
|
|
|
if ((jiffies - d->rxjif) > 1 * HZ) {
|
2010-08-28 05:59:27 +08:00
|
|
|
newalarm |= DAHDI_ALARM_RED;
|
2011-01-04 02:25:05 +08:00
|
|
|
if (d->span.alarms != newalarm) {
|
|
|
|
d->span.alarms = newalarm;
|
|
|
|
dahdi_alarm_notify(&d->span);
|
2010-08-28 05:59:27 +08:00
|
|
|
alarmchanged++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
if (alarmchanged)
|
|
|
|
checkmaster();
|
|
|
|
|
|
|
|
/* Do the next one */
|
|
|
|
mod_timer(&alarmcheck, jiffies + 1 * HZ);
|
|
|
|
}
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
static int dahdi_dynamic_init(void)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2011-01-04 02:25:05 +08:00
|
|
|
dahdi_set_dynamic_ioctl(dahdi_dynamic_ioctl);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/* Start process to check for RED ALARM */
|
|
|
|
init_timer(&alarmcheck);
|
|
|
|
alarmcheck.expires = 0;
|
|
|
|
alarmcheck.data = 0;
|
|
|
|
alarmcheck.function = check_for_red_alarm;
|
|
|
|
/* Check once per second */
|
|
|
|
mod_timer(&alarmcheck, jiffies + 1 * HZ);
|
|
|
|
#ifdef ENABLE_TASKLETS
|
2011-01-04 02:25:05 +08:00
|
|
|
tasklet_init(&dahdi_dynamic_tlet, dahdi_dynamic_tasklet, 0);
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
printk(KERN_INFO "DAHDI Dynamic Span support LOADED\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
static void dahdi_dynamic_cleanup(void)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
|
|
|
#ifdef ENABLE_TASKLETS
|
|
|
|
if (taskletpending) {
|
2011-01-04 02:25:05 +08:00
|
|
|
tasklet_disable(&dahdi_dynamic_tlet);
|
|
|
|
tasklet_kill(&dahdi_dynamic_tlet);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
dahdi_set_dynamic_ioctl(NULL);
|
|
|
|
del_timer(&alarmcheck);
|
|
|
|
printk(KERN_INFO "DAHDI Dynamic Span support unloaded\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
module_param(debug, int, 0600);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("DAHDI Dynamic Span Support");
|
|
|
|
MODULE_AUTHOR("Mark Spencer <markster@digium.com>");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
|
2011-01-04 02:25:05 +08:00
|
|
|
module_init(dahdi_dynamic_init);
|
|
|
|
module_exit(dahdi_dynamic_cleanup);
|