2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* Written by Oron Peled <oron@actcom.co.il>
|
|
|
|
* Copyright (C) 2004, Xorcom
|
|
|
|
*
|
|
|
|
* Derived from ztdummy
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002, Hermes Softlab
|
|
|
|
* Copyright (C) 2004, Digium, Inc.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <linux/version.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h> /* for udelay */
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/proc_fs.h>
|
2013-05-22 04:33:18 +08:00
|
|
|
#include <linux/seq_file.h>
|
2010-08-28 05:59:27 +08:00
|
|
|
#include <dahdi/kernel.h>
|
|
|
|
#include "xbus-core.h"
|
|
|
|
#include "xproto.h"
|
|
|
|
#include "xpp_dahdi.h"
|
|
|
|
#include "parport_debug.h"
|
|
|
|
|
|
|
|
static const char rcsid[] = "$Id$";
|
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
struct proc_dir_entry *xpp_proc_toplevel = NULL;
|
|
|
|
#define PROC_DIR "xpp"
|
|
|
|
#define PROC_XPD_SUMMARY "summary"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MAX_QUEUE_LEN 10000
|
|
|
|
#define DELAY_UNTIL_DIALTONE 3000
|
|
|
|
|
|
|
|
DEF_PARM(int, debug, 0, 0644, "Print DBG statements");
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(debug);
|
2012-01-11 23:22:46 +08:00
|
|
|
static DEF_PARM_BOOL(prefmaster, 0, 0644,
|
|
|
|
"Do we want to be dahdi preferred sync master");
|
2010-08-28 05:59:27 +08:00
|
|
|
// DEF_ARRAY(int, pcmtx, 4, 0, "Forced PCM values to transmit");
|
|
|
|
|
|
|
|
#include "dahdi_debug.h"
|
|
|
|
|
2011-01-31 02:13:39 +08:00
|
|
|
static void phonedev_cleanup(xpd_t *xpd);
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
#ifdef DEBUG_SYNC_PARPORT
|
|
|
|
/*
|
|
|
|
* Use parallel port to sample our PCM sync and diagnose quality and
|
|
|
|
* potential problems. A logic analizer or a scope should be connected
|
|
|
|
* to the data bits of the parallel port.
|
|
|
|
*
|
|
|
|
* Array parameter: Choose the two xbuses Id's to sample.
|
|
|
|
* This can be changed on runtime as well. Example:
|
|
|
|
* echo "3,5" > /sys/module/xpp/parameters/parport_xbuses
|
|
|
|
*/
|
|
|
|
static int parport_xbuses[2] = { 0, 1 };
|
2012-01-11 23:22:46 +08:00
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
unsigned int parport_xbuses_num_values;
|
|
|
|
module_param_array(parport_xbuses, int, &parport_xbuses_num_values, 0577);
|
|
|
|
MODULE_PARM_DESC(parport_xbuses, "Id's of xbuses to sample (1-2)");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flip a single bit in the parallel port:
|
|
|
|
* - The bit number is either bitnum0 or bitnum1
|
|
|
|
* - Bit is selected by xbus number from parport_xbuses[]
|
|
|
|
*/
|
|
|
|
void xbus_flip_bit(xbus_t *xbus, unsigned int bitnum0, unsigned int bitnum1)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int num = xbus->num;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (num == parport_xbuses[0])
|
2010-08-28 05:59:27 +08:00
|
|
|
flip_parport_bit(bitnum0);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (num == parport_xbuses[1])
|
2010-08-28 05:59:27 +08:00
|
|
|
flip_parport_bit(bitnum1);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(xbus_flip_bit);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static atomic_t num_registered_spans = ATOMIC_INIT(0);
|
|
|
|
|
|
|
|
int total_registered_spans(void)
|
|
|
|
{
|
|
|
|
return atomic_read(&num_registered_spans);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2013-05-22 04:33:18 +08:00
|
|
|
static const struct file_operations xpd_read_proc_ops;
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*------------------------- XPD Management -------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called by put_xpd() when XPD has no more references.
|
|
|
|
*/
|
|
|
|
static void xpd_destroy(struct kref *kref)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
xpd = kref_to_xpd(kref);
|
|
|
|
XPD_DBG(DEVICES, xpd, "%s\n", __func__);
|
|
|
|
xpd_device_unregister(xpd);
|
|
|
|
}
|
|
|
|
|
|
|
|
int refcount_xpd(xpd_t *xpd)
|
|
|
|
{
|
|
|
|
struct kref *kref = &xpd->kref;
|
|
|
|
|
2017-06-02 01:16:54 +08:00
|
|
|
return refcount_read(&kref->refcount);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
xpd_t *get_xpd(const char *msg, xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_DBG(DEVICES, xpd, "%s: refcount_xpd=%d\n", msg, refcount_xpd(xpd));
|
2010-08-28 05:59:27 +08:00
|
|
|
kref_get(&xpd->kref);
|
|
|
|
return xpd;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(get_xpd);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
void put_xpd(const char *msg, xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_DBG(DEVICES, xpd, "%s: refcount_xpd=%d\n", msg, refcount_xpd(xpd));
|
2010-08-28 05:59:27 +08:00
|
|
|
kref_put(&xpd->kref, xpd_destroy);
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(put_xpd);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
static void xpd_proc_remove(xbus_t *xbus, xpd_t *xpd)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xpd->proc_xpd_dir) {
|
|
|
|
if (xpd->proc_xpd_summary) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_DBG(PROC, xpd, "Removing proc '%s'\n",
|
|
|
|
PROC_XPD_SUMMARY);
|
2010-08-28 05:59:27 +08:00
|
|
|
remove_proc_entry(PROC_XPD_SUMMARY, xpd->proc_xpd_dir);
|
|
|
|
xpd->proc_xpd_summary = NULL;
|
|
|
|
}
|
|
|
|
XPD_DBG(PROC, xpd, "Removing %s/%s proc directory\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus->busname, xpd->xpdname);
|
2010-08-28 05:59:27 +08:00
|
|
|
remove_proc_entry(xpd->xpdname, xbus->proc_xbus_dir);
|
|
|
|
xpd->proc_xpd_dir = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xpd_proc_create(xbus_t *xbus, xpd_t *xpd)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
XPD_DBG(PROC, xpd, "Creating proc directory\n");
|
|
|
|
xpd->proc_xpd_dir = proc_mkdir(xpd->xpdname, xbus->proc_xbus_dir);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd->proc_xpd_dir) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_ERR(xpd, "Failed to create proc directory\n");
|
|
|
|
goto err;
|
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
xpd->proc_xpd_summary = proc_create_data(PROC_XPD_SUMMARY, 0444,
|
|
|
|
xpd->proc_xpd_dir,
|
|
|
|
&xpd_read_proc_ops, xpd);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd->proc_xpd_summary) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_ERR(xpd, "Failed to create proc file '%s'\n",
|
|
|
|
PROC_XPD_SUMMARY);
|
2010-08-28 05:59:27 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
SET_PROC_DIRENTRY_OWNER(xpd->proc_xpd_summary);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
err:
|
|
|
|
xpd_proc_remove(xbus, xpd);
|
|
|
|
return -EFAULT;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void xpd_free(xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_t *xbus = NULL;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd)
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xpd->xproto)
|
2010-08-28 05:59:27 +08:00
|
|
|
xproto_put(xpd->xproto); /* was taken in xpd_alloc() */
|
|
|
|
xpd->xproto = NULL;
|
|
|
|
xbus = xpd->xbus;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xbus)
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
XPD_DBG(DEVICES, xpd, "\n");
|
|
|
|
xpd_proc_remove(xbus, xpd);
|
|
|
|
xbus_xpd_unbind(xbus, xpd);
|
2011-01-31 02:13:39 +08:00
|
|
|
phonedev_cleanup(xpd);
|
2010-08-28 05:59:27 +08:00
|
|
|
KZFREE(xpd);
|
|
|
|
DBG(DEVICES, "refcount_xbus=%d\n", refcount_xbus(xbus));
|
|
|
|
/*
|
|
|
|
* This must be last, so the xbus cannot be released before the xpd
|
|
|
|
*/
|
2012-01-11 23:22:46 +08:00
|
|
|
put_xbus(__func__, xbus); /* was taken in xpd_alloc() */
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xpd_free);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Synchronous part of XPD detection.
|
|
|
|
* Called from new_card()
|
|
|
|
*/
|
2015-11-17 04:42:21 +08:00
|
|
|
int create_xpd(xbus_t *xbus, const xproto_table_t *proto_table,
|
|
|
|
const struct unit_descriptor *unit_descriptor,
|
|
|
|
int unit,
|
|
|
|
int subunit, __u8 type)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd = NULL;
|
|
|
|
bool to_phone;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(type == XPD_TYPE_NOMODULE);
|
2015-11-17 04:42:21 +08:00
|
|
|
to_phone = BIT(subunit) & unit_descriptor->port_dir;
|
2010-08-28 05:59:27 +08:00
|
|
|
BUG_ON(!xbus);
|
|
|
|
xpd = xpd_byaddr(xbus, unit, subunit);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xpd) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_NOTICE(xpd, "XPD at %d%d already exists\n", unit, subunit);
|
2010-08-28 05:59:27 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2015-11-17 04:42:21 +08:00
|
|
|
INFO("%s: [%d.%d] type=%d subtype=%d numchips=%d ports_per_chip=%d ports_dir=%d\n",
|
|
|
|
__func__,
|
|
|
|
unit_descriptor->addr.unit,
|
|
|
|
unit_descriptor->addr.subunit,
|
|
|
|
unit_descriptor->type,
|
|
|
|
unit_descriptor->subtype,
|
|
|
|
unit_descriptor->numchips,
|
|
|
|
unit_descriptor->ports_per_chip,
|
|
|
|
unit_descriptor->port_dir);
|
|
|
|
if (unit_descriptor->ports_per_chip <= 0 || unit_descriptor->ports_per_chip > CHANNELS_PERXPD) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_NOTICE(xbus, "Illegal number of ports %d for XPD %d%d\n",
|
2015-11-17 04:42:21 +08:00
|
|
|
unit_descriptor->ports_per_chip, unit, subunit);
|
2010-08-28 05:59:27 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd =
|
|
|
|
proto_table->xops->card_new(xbus, unit, subunit, proto_table,
|
2015-11-17 04:42:21 +08:00
|
|
|
unit_descriptor,
|
2012-01-11 23:22:46 +08:00
|
|
|
to_phone);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd) {
|
2015-11-17 04:42:21 +08:00
|
|
|
XBUS_NOTICE(xbus, "card_new(%d,%d,%d,%d) failed. Ignored.\n",
|
|
|
|
unit, subunit, proto_table->type,
|
2012-01-11 23:22:46 +08:00
|
|
|
to_phone);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(create_xpd);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prints a general procfs entry for the bus, under xpp/BUSNAME/summary
|
|
|
|
*/
|
2013-05-22 04:33:18 +08:00
|
|
|
static int xpd_read_proc_show(struct seq_file *sfile, void *data)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int len = 0;
|
2013-05-22 04:33:18 +08:00
|
|
|
xpd_t *xpd = sfile->private;
|
2012-01-11 23:22:46 +08:00
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd)
|
2013-05-22 04:33:18 +08:00
|
|
|
return -EINVAL;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile,
|
2012-01-11 23:22:46 +08:00
|
|
|
"%s (%s, card %s, span %d)\n" "timing_priority: %d\n"
|
|
|
|
"timer_count: %d span->mainttimer=%d\n", xpd->xpdname,
|
|
|
|
xpd->type_name, (xpd->card_present) ? "present" : "missing",
|
|
|
|
(SPAN_REGISTERED(xpd)) ? PHONEDEV(xpd).span.spanno : 0,
|
|
|
|
PHONEDEV(xpd).timing_priority, xpd->timer_count,
|
|
|
|
PHONEDEV(xpd).span.mainttimer);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "xpd_state: %s (%d)\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_statename(xpd->xpd_state), xpd->xpd_state);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "open_counter=%d refcount=%d\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
atomic_read(&PHONEDEV(xpd).open_counter),
|
|
|
|
refcount_xpd(xpd));
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "Address: U=%d S=%d\n", xpd->addr.unit,
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd->addr.subunit);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "Subunits: %d\n", xpd->subunits);
|
2015-11-17 04:42:21 +08:00
|
|
|
seq_printf(sfile, "Type: %d.%d\n", xpd->xpd_type, XPD_HW(xpd).subtype);
|
|
|
|
seq_printf(sfile, "Hardware type: %d.%d\nn", XPD_HW(xpd).type, XPD_HW(xpd).subtype);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "pcm_len=%d\n\n", PHONEDEV(xpd).pcm_len);
|
|
|
|
seq_printf(sfile, "wanted_pcm_mask=0x%04X\n\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
PHONEDEV(xpd).wanted_pcm_mask);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "mute_dtmf=0x%04X\n\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
PHONEDEV(xpd).mute_dtmf);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "STATES:");
|
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "output_relays");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%d ",
|
2012-01-11 23:22:46 +08:00
|
|
|
IS_SET(PHONEDEV(xpd).digital_outputs, i));
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "input_relays");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%d ",
|
2012-01-11 23:22:46 +08:00
|
|
|
IS_SET(PHONEDEV(xpd).digital_inputs, i));
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "offhook");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%d ", IS_OFFHOOK(xpd, i));
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "oht_pcm_pass");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%d ",
|
2012-01-11 23:22:46 +08:00
|
|
|
IS_SET(PHONEDEV(xpd).oht_pcm_pass, i));
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "msg_waiting");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%d ", PHONEDEV(xpd).msg_waiting[i]);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "ringing");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%d ", PHONEDEV(xpd).ringing[i]);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "no_pcm");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%d ", IS_SET(PHONEDEV(xpd).no_pcm, i));
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
#if 1
|
2012-01-11 23:20:05 +08:00
|
|
|
if (SPAN_REGISTERED(xpd)) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile,
|
2012-01-12 03:56:35 +08:00
|
|
|
"\nPCM:\n |"
|
|
|
|
" [readchunk] |"
|
|
|
|
" [writechunk] | W D");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2012-01-11 23:22:46 +08:00
|
|
|
struct dahdi_chan *chan = XPD_CHAN(xpd, i);
|
|
|
|
__u8 rchunk[DAHDI_CHUNKSIZE];
|
|
|
|
__u8 wchunk[DAHDI_CHUNKSIZE];
|
|
|
|
__u8 *rp;
|
|
|
|
__u8 *wp;
|
2010-08-28 05:59:27 +08:00
|
|
|
int j;
|
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (IS_SET(PHONEDEV(xpd).digital_outputs, i))
|
2010-08-28 05:59:27 +08:00
|
|
|
continue;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (IS_SET(PHONEDEV(xpd).digital_inputs, i))
|
2010-08-28 05:59:27 +08:00
|
|
|
continue;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (IS_SET(PHONEDEV(xpd).digital_signalling, i))
|
2010-08-28 05:59:27 +08:00
|
|
|
continue;
|
|
|
|
rp = chan->readchunk;
|
|
|
|
wp = chan->writechunk;
|
|
|
|
memcpy(rchunk, rp, DAHDI_CHUNKSIZE);
|
|
|
|
memcpy(wchunk, wp, DAHDI_CHUNKSIZE);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\n port %2d> | ", i);
|
2012-01-13 01:14:15 +08:00
|
|
|
for (j = 0; j < DAHDI_CHUNKSIZE; j++)
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%02X ", rchunk[j]);
|
|
|
|
seq_printf(sfile, " | ");
|
2012-01-13 01:14:15 +08:00
|
|
|
for (j = 0; j < DAHDI_CHUNKSIZE; j++)
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%02X ", wchunk[j]);
|
|
|
|
seq_printf(sfile, " | %c",
|
2012-01-13 01:14:15 +08:00
|
|
|
(IS_SET(PHONEDEV(xpd).wanted_pcm_mask, i))
|
|
|
|
? '+' : ' ');
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, " %c",
|
2012-01-13 01:14:15 +08:00
|
|
|
(IS_SET(PHONEDEV(xpd).mute_dtmf, i))
|
|
|
|
? '-' : ' ');
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if 0
|
2012-01-11 23:20:05 +08:00
|
|
|
if (SPAN_REGISTERED(xpd)) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\nSignalling:\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
|
|
|
struct dahdi_chan *chan = XPD_CHAN(xpd, i);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile,
|
2012-01-11 23:22:46 +08:00
|
|
|
"\t%2d> sigcap=0x%04X sig=0x%04X\n", i,
|
|
|
|
chan->sigcap, chan->sig);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\nCOUNTERS:\n");
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < XPD_COUNTER_MAX; i++) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\t\t%-20s = %d\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_counters[i].name, xpd->counters[i]);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "<-- len=%d\n", len);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2013-05-22 04:33:18 +08:00
|
|
|
static int xpd_read_proc_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return single_open(file, xpd_read_proc_show, PDE_DATA(inode));
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
2013-05-22 04:33:18 +08:00
|
|
|
static const struct file_operations xpd_read_proc_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = xpd_read_proc_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
};
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
const char *xpd_statename(enum xpd_state st)
|
|
|
|
{
|
2012-01-11 23:20:05 +08:00
|
|
|
switch (st) {
|
2012-01-11 23:22:46 +08:00
|
|
|
case XPD_STATE_START:
|
|
|
|
return "START";
|
|
|
|
case XPD_STATE_INIT_REGS:
|
|
|
|
return "INIT_REGS";
|
|
|
|
case XPD_STATE_READY:
|
|
|
|
return "READY";
|
|
|
|
case XPD_STATE_NOHW:
|
|
|
|
return "NOHW";
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool xpd_setstate(xpd_t *xpd, enum xpd_state newstate)
|
|
|
|
{
|
|
|
|
BUG_ON(!xpd);
|
2012-01-11 23:17:09 +08:00
|
|
|
XPD_DBG(DEVICES, xpd, "%s: %s (%d) -> %s (%d)\n", __func__,
|
2010-08-28 05:59:27 +08:00
|
|
|
xpd_statename(xpd->xpd_state), xpd->xpd_state,
|
|
|
|
xpd_statename(newstate), newstate);
|
2012-01-11 23:20:05 +08:00
|
|
|
switch (newstate) {
|
2010-08-28 05:59:27 +08:00
|
|
|
case XPD_STATE_START:
|
|
|
|
goto badstate;
|
|
|
|
case XPD_STATE_INIT_REGS:
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xpd->xpd_state != XPD_STATE_START)
|
2010-08-28 05:59:27 +08:00
|
|
|
goto badstate;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xpd->addr.subunit != 0) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_NOTICE(xpd,
|
2012-01-12 03:56:35 +08:00
|
|
|
"%s: Moving to %s allowed only for subunit 0\n",
|
|
|
|
__func__, xpd_statename(newstate));
|
2010-08-28 05:59:27 +08:00
|
|
|
goto badstate;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XPD_STATE_READY:
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xpd->addr.subunit == 0) {
|
2010-08-28 05:59:27 +08:00
|
|
|
/* Unit 0 script initialize registers of all subunits */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xpd->xpd_state != XPD_STATE_INIT_REGS)
|
2010-08-28 05:59:27 +08:00
|
|
|
goto badstate;
|
|
|
|
} else {
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xpd->xpd_state != XPD_STATE_START)
|
2010-08-28 05:59:27 +08:00
|
|
|
goto badstate;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XPD_STATE_NOHW:
|
|
|
|
break;
|
|
|
|
default:
|
2012-01-11 23:17:09 +08:00
|
|
|
XPD_ERR(xpd, "%s: Unknown newstate=%d\n", __func__, newstate);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
xpd->xpd_state = newstate;
|
|
|
|
return 1;
|
|
|
|
badstate:
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_NOTICE(xpd, "%s: cannot transition: %s (%d) -> %s (%d)\n", __func__,
|
|
|
|
xpd_statename(xpd->xpd_state), xpd->xpd_state,
|
|
|
|
xpd_statename(newstate), newstate);
|
2010-08-28 05:59:27 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-30 22:11:49 +08:00
|
|
|
/*
|
|
|
|
* Cleanup/initialize phonedev
|
|
|
|
*/
|
|
|
|
static void phonedev_cleanup(xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct phonedev *phonedev = &PHONEDEV(xpd);
|
|
|
|
unsigned int x;
|
2011-01-30 22:11:49 +08:00
|
|
|
|
|
|
|
for (x = 0; x < phonedev->channels; x++) {
|
2013-12-30 02:43:14 +08:00
|
|
|
if (phonedev->chans[x]) {
|
2011-01-31 02:14:49 +08:00
|
|
|
KZFREE(phonedev->chans[x]);
|
2013-12-30 02:43:14 +08:00
|
|
|
phonedev->chans[x] = NULL;
|
|
|
|
}
|
|
|
|
if (phonedev->ec[x]) {
|
2011-06-29 02:23:00 +08:00
|
|
|
KZFREE(phonedev->ec[x]);
|
2013-12-30 02:43:14 +08:00
|
|
|
phonedev->ec[x] = NULL;
|
|
|
|
}
|
2011-01-30 22:11:49 +08:00
|
|
|
}
|
2013-12-30 02:43:14 +08:00
|
|
|
phonedev->channels = 0;
|
2011-01-30 22:11:49 +08:00
|
|
|
}
|
|
|
|
|
2013-12-30 02:43:14 +08:00
|
|
|
int phonedev_alloc_channels(xpd_t *xpd, int channels)
|
2011-01-30 22:11:49 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct phonedev *phonedev = &PHONEDEV(xpd);
|
2013-12-30 02:43:14 +08:00
|
|
|
int old_channels = phonedev->channels;
|
2012-01-11 23:22:46 +08:00
|
|
|
unsigned int x;
|
2011-01-30 22:11:49 +08:00
|
|
|
|
2014-05-12 23:36:16 +08:00
|
|
|
XPD_DBG(DEVICES, xpd, "Reallocating channels: %d -> %d\n",
|
2013-12-30 02:43:14 +08:00
|
|
|
old_channels, channels);
|
|
|
|
phonedev_cleanup(xpd);
|
2011-01-30 22:11:49 +08:00
|
|
|
phonedev->channels = channels;
|
|
|
|
for (x = 0; x < phonedev->channels; x++) {
|
2012-01-11 23:22:46 +08:00
|
|
|
if (!
|
|
|
|
(phonedev->chans[x] =
|
|
|
|
KZALLOC(sizeof(*(phonedev->chans[x])), GFP_KERNEL))) {
|
2012-01-11 23:17:09 +08:00
|
|
|
ERR("%s: Unable to allocate channel %d\n", __func__, x);
|
2011-01-30 22:11:49 +08:00
|
|
|
goto err;
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
phonedev->ec[x] =
|
|
|
|
KZALLOC(sizeof(*(phonedev->ec[x])), GFP_KERNEL);
|
2011-06-29 02:23:00 +08:00
|
|
|
if (!phonedev->ec[x]) {
|
|
|
|
ERR("%s: Unable to allocate ec state %d\n", __func__,
|
2012-01-11 23:22:46 +08:00
|
|
|
x);
|
2011-06-29 02:23:00 +08:00
|
|
|
goto err;
|
|
|
|
}
|
2011-01-30 22:11:49 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
phonedev_cleanup(xpd);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2013-12-30 02:43:14 +08:00
|
|
|
EXPORT_SYMBOL(phonedev_alloc_channels);
|
|
|
|
|
|
|
|
__must_check static int phonedev_init(xpd_t *xpd,
|
|
|
|
const xproto_table_t *proto_table,
|
|
|
|
int channels, xpp_line_t no_pcm)
|
|
|
|
{
|
|
|
|
struct phonedev *phonedev = &PHONEDEV(xpd);
|
|
|
|
|
|
|
|
spin_lock_init(&phonedev->lock_recompute_pcm);
|
|
|
|
phonedev->no_pcm = no_pcm;
|
|
|
|
phonedev->offhook_state = 0x0; /* ONHOOK */
|
|
|
|
phonedev->phoneops = proto_table->phoneops;
|
|
|
|
phonedev->digital_outputs = 0;
|
|
|
|
phonedev->digital_inputs = 0;
|
|
|
|
atomic_set(&phonedev->dahdi_registered, 0);
|
|
|
|
atomic_set(&phonedev->open_counter, 0);
|
|
|
|
if (phonedev_alloc_channels(xpd, channels) < 0)
|
|
|
|
goto err;
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2011-01-30 22:11:49 +08:00
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* xpd_alloc - Allocator for new XPD's
|
|
|
|
*
|
|
|
|
*/
|
2012-01-12 03:56:35 +08:00
|
|
|
__must_check xpd_t *xpd_alloc(xbus_t *xbus, int unit, int subunit,
|
2015-11-17 04:42:21 +08:00
|
|
|
size_t privsize,
|
|
|
|
const xproto_table_t *proto_table,
|
|
|
|
const struct unit_descriptor *unit_descriptor,
|
|
|
|
int channels)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd = NULL;
|
|
|
|
size_t alloc_size = sizeof(xpd_t) + privsize;
|
|
|
|
int type = proto_table->type;
|
|
|
|
xpp_line_t no_pcm = 0;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!proto_table);
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_DBG(DEVICES, xbus, "type=%d channels=%d (alloc_size=%zd)\n", type,
|
|
|
|
channels, alloc_size);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (channels > CHANNELS_PERXPD) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_ERR(xbus, "%s: type=%d: too many channels %d\n", __func__,
|
|
|
|
type, channels);
|
2010-08-28 05:59:27 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((xpd = KZALLOC(alloc_size, GFP_KERNEL)) == NULL) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_ERR(xbus, "%s: type=%d: Unable to allocate memory\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
__func__, type);
|
2010-08-28 05:59:27 +08:00
|
|
|
goto err;
|
|
|
|
}
|
2012-01-11 23:21:54 +08:00
|
|
|
xpd->priv = (__u8 *)xpd + sizeof(xpd_t);
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_lock_init(&xpd->lock);
|
|
|
|
xpd->card_present = 0;
|
2015-11-17 04:42:21 +08:00
|
|
|
xpd->xpd_type = proto_table->type;
|
2010-08-28 05:59:27 +08:00
|
|
|
xpd->xproto = proto_table;
|
2015-11-17 04:42:21 +08:00
|
|
|
xpd->unit_descriptor = *unit_descriptor;
|
2011-01-30 22:11:49 +08:00
|
|
|
xpd->xops = proto_table->xops;
|
2010-08-28 05:59:27 +08:00
|
|
|
xpd->xpd_state = XPD_STATE_START;
|
2017-04-02 23:03:03 +08:00
|
|
|
xpd->subunits = subunits_of_xpd(unit_descriptor, proto_table);
|
2010-08-28 05:59:27 +08:00
|
|
|
kref_init(&xpd->kref);
|
|
|
|
|
|
|
|
/* For USB-1 disable some channels */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (MAX_SEND_SIZE(xbus) < RPACKET_SIZE(GLOBAL, PCM_WRITE)) {
|
2012-01-11 23:22:46 +08:00
|
|
|
no_pcm =
|
|
|
|
0x7F | PHONEDEV(xpd).digital_outputs | PHONEDEV(xpd).
|
|
|
|
digital_inputs;
|
|
|
|
XBUS_NOTICE(xbus,
|
2012-01-12 03:56:35 +08:00
|
|
|
"max xframe size = %d, disabling some PCM channels. "
|
|
|
|
"no_pcm=0x%04X\n",
|
|
|
|
MAX_SEND_SIZE(xbus), PHONEDEV(xpd).no_pcm);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2011-01-30 22:11:49 +08:00
|
|
|
if (phonedev_init(xpd, proto_table, channels, no_pcm) < 0)
|
|
|
|
goto err;
|
2010-08-28 05:59:27 +08:00
|
|
|
xbus_xpd_bind(xbus, xpd, unit, subunit);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xpd_proc_create(xbus, xpd) < 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
goto err;
|
|
|
|
/*
|
|
|
|
* This makes sure the xbus cannot be removed before this xpd
|
|
|
|
* is removed in xpd_free()
|
|
|
|
*/
|
|
|
|
xbus = get_xbus(__func__, xbus->num); /* returned in xpd_free() */
|
2012-01-11 23:22:46 +08:00
|
|
|
xproto_get(type); /* will be returned in xpd_free() */
|
2010-08-28 05:59:27 +08:00
|
|
|
return xpd;
|
|
|
|
err:
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xpd) {
|
2010-08-28 05:59:27 +08:00
|
|
|
xpd_proc_remove(xbus, xpd);
|
2011-01-30 22:11:49 +08:00
|
|
|
phonedev_cleanup(xpd);
|
2010-08-28 05:59:27 +08:00
|
|
|
KZFREE(xpd);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xpd_alloc);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The xpd isn't open by anyone, we can unregister it and free it
|
|
|
|
*/
|
|
|
|
void xpd_remove(xpd_t *xpd)
|
|
|
|
{
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
XPD_INFO(xpd, "Remove\n");
|
2011-01-30 22:14:14 +08:00
|
|
|
CALL_XMETHOD(card_remove, xpd);
|
2010-08-28 05:59:27 +08:00
|
|
|
xpd_free(xpd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_xpd_status(xpd_t *xpd, int alarm_flag)
|
|
|
|
{
|
2011-01-30 22:11:49 +08:00
|
|
|
struct dahdi_span *span = &PHONEDEV(xpd).span;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!SPAN_REGISTERED(xpd)) {
|
2012-01-12 03:56:35 +08:00
|
|
|
#if 0
|
|
|
|
XPD_NOTICE(xpd,
|
|
|
|
"%s: XPD is not registered. Skipping.\n",
|
|
|
|
__func__);
|
|
|
|
#endif
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (alarm_flag) {
|
2012-01-11 23:22:46 +08:00
|
|
|
case DAHDI_ALARM_NONE:
|
|
|
|
xpd->last_response = jiffies;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Nothing
|
|
|
|
break;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (span->alarms == alarm_flag)
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_DBG(GENERAL, xpd, "Update XPD alarms: %s -> %02X\n",
|
|
|
|
PHONEDEV(xpd).span.name, alarm_flag);
|
2010-08-28 05:59:27 +08:00
|
|
|
span->alarms = alarm_flag;
|
|
|
|
dahdi_alarm_notify(span);
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(update_xpd_status);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Used to block/pass PCM during onhook-transfers. E.g:
|
|
|
|
* - Playing FSK after FXS ONHOOK for MWI (non-neon style)
|
|
|
|
* - Playing DTFM/FSK for FXO Caller-ID detection.
|
|
|
|
*/
|
|
|
|
void oht_pcm(xpd_t *xpd, int pos, bool pass)
|
|
|
|
{
|
2012-01-11 23:20:05 +08:00
|
|
|
if (pass) {
|
2010-08-28 05:59:27 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "OHT PCM: pass\n");
|
2011-01-30 22:11:49 +08:00
|
|
|
BIT_SET(PHONEDEV(xpd).oht_pcm_pass, pos);
|
2010-08-28 05:59:27 +08:00
|
|
|
} else {
|
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "OHT PCM: block\n");
|
2011-01-30 22:11:49 +08:00
|
|
|
BIT_CLR(PHONEDEV(xpd).oht_pcm_pass, pos);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2011-01-30 22:14:14 +08:00
|
|
|
CALL_PHONE_METHOD(card_pcm_recompute, xpd, 0);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(oht_pcm);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Update our hookstate -- for PCM block/pass
|
|
|
|
*/
|
|
|
|
void mark_offhook(xpd_t *xpd, int pos, bool to_offhook)
|
|
|
|
{
|
2012-01-11 23:20:05 +08:00
|
|
|
if (to_offhook) {
|
2010-08-28 05:59:27 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "OFFHOOK\n");
|
2011-01-30 22:11:49 +08:00
|
|
|
BIT_SET(PHONEDEV(xpd).offhook_state, pos);
|
2010-08-28 05:59:27 +08:00
|
|
|
} else {
|
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "ONHOOK\n");
|
2011-01-30 22:11:49 +08:00
|
|
|
BIT_CLR(PHONEDEV(xpd).offhook_state, pos);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2011-01-30 22:14:14 +08:00
|
|
|
CALL_PHONE_METHOD(card_pcm_recompute, xpd, 0);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(mark_offhook);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a signalling notification to Asterisk
|
|
|
|
*/
|
|
|
|
void notify_rxsig(xpd_t *xpd, int pos, enum dahdi_rxsig rxsig)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We should not spinlock before calling dahdi_hooksig() as
|
|
|
|
* it may call back into our xpp_hooksig() and cause
|
|
|
|
* a nested spinlock scenario
|
|
|
|
*/
|
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "rxsig=%s\n", rxsig2str(rxsig));
|
2012-01-11 23:20:05 +08:00
|
|
|
if (SPAN_REGISTERED(xpd))
|
2010-08-28 05:59:27 +08:00
|
|
|
dahdi_hooksig(XPD_CHAN(xpd, pos), rxsig);
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(notify_rxsig);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when hardware state changed:
|
|
|
|
* - FXS -- the phone was picked up or hanged-up.
|
|
|
|
* - FXO -- we answered the phone or handed-up.
|
|
|
|
*/
|
|
|
|
void hookstate_changed(xpd_t *xpd, int pos, bool to_offhook)
|
|
|
|
{
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
mark_offhook(xpd, pos, to_offhook);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!to_offhook) {
|
2010-08-28 05:59:27 +08:00
|
|
|
oht_pcm(xpd, pos, 0);
|
|
|
|
/*
|
|
|
|
* To prevent latest PCM to stay in buffers
|
|
|
|
* indefinitely, mark this channel for a
|
|
|
|
* single silence transmittion.
|
|
|
|
*
|
|
|
|
* This bit will be cleared on the next tick.
|
|
|
|
*/
|
2011-01-30 22:11:49 +08:00
|
|
|
BIT_SET(PHONEDEV(xpd).silence_pcm, pos);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
notify_rxsig(xpd, pos,
|
|
|
|
(to_offhook) ? DAHDI_RXSIG_OFFHOOK : DAHDI_RXSIG_ONHOOK);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(hookstate_changed);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
#define XPP_MAX_LEN 512
|
|
|
|
|
|
|
|
/*------------------------- Dahdi Interfaces -----------------------*/
|
|
|
|
|
|
|
|
/*
|
2014-06-17 15:11:40 +08:00
|
|
|
* Called with spinlock held on chan. Must not call back
|
2010-08-28 05:59:27 +08:00
|
|
|
* dahdi functions.
|
|
|
|
*/
|
2014-06-17 15:11:40 +08:00
|
|
|
static int _xpp_open(struct dahdi_chan *chan)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd;
|
|
|
|
xbus_t *xbus;
|
|
|
|
int pos;
|
2014-05-12 22:04:28 +08:00
|
|
|
int open_counter;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
if (!chan) {
|
|
|
|
NOTICE("open called on a null chan\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
xpd = chan->pvt;
|
|
|
|
if (!xpd) {
|
|
|
|
NOTICE("open called on a chan with no pvt (xpd)\n");
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
xbus = xpd->xbus;
|
|
|
|
if (!xbus) {
|
|
|
|
NOTICE("open called on a chan with no xbus\n");
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
pos = chan->chanpos - 1;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd->card_present) {
|
2010-08-28 05:59:27 +08:00
|
|
|
LINE_NOTICE(xpd, pos, "Cannot open -- device not ready\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2014-05-12 22:04:28 +08:00
|
|
|
open_counter = atomic_inc_return(&PHONEDEV(xpd).open_counter);
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_DBG(DEVICES, xpd, pos, "%s[%d]: open_counter=%d\n", current->comm,
|
2014-05-12 22:04:28 +08:00
|
|
|
current->pid, open_counter);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (PHONE_METHOD(card_open, xpd))
|
2011-01-30 22:14:14 +08:00
|
|
|
CALL_PHONE_METHOD(card_open, xpd, pos);
|
2010-08-28 05:59:27 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2014-06-17 15:11:40 +08:00
|
|
|
|
|
|
|
int xpp_open(struct dahdi_chan *chan)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int res;
|
|
|
|
spin_lock_irqsave(&chan->lock, flags);
|
|
|
|
res = _xpp_open(chan);
|
|
|
|
spin_unlock_irqrestore(&chan->lock, flags);
|
|
|
|
return res;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xpp_open);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
int xpp_close(struct dahdi_chan *chan)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd = chan->pvt;
|
|
|
|
int pos = chan->chanpos - 1;
|
2014-05-12 22:04:28 +08:00
|
|
|
int open_counter;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (PHONE_METHOD(card_close, xpd))
|
2011-01-30 22:14:14 +08:00
|
|
|
CALL_PHONE_METHOD(card_close, xpd, pos);
|
2014-05-12 22:04:28 +08:00
|
|
|
/* from xpp_open(): */
|
|
|
|
open_counter = atomic_dec_return(&PHONEDEV(xpd).open_counter);
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_DBG(DEVICES, xpd, pos, "%s[%d]: open_counter=%d\n", current->comm,
|
2014-05-12 22:04:28 +08:00
|
|
|
current->pid, open_counter);
|
2010-08-28 05:59:27 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xpp_close);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
void report_bad_ioctl(const char *msg, xpd_t *xpd, int pos, unsigned int cmd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
char *extra_msg = "";
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (_IOC_TYPE(cmd) == 'J')
|
2010-08-28 05:59:27 +08:00
|
|
|
extra_msg = " (for old ZAPTEL)";
|
|
|
|
XPD_NOTICE(xpd, "%s: Bad ioctl%s\n", msg, extra_msg);
|
|
|
|
XPD_NOTICE(xpd, "ENOTTY: chan=%d cmd=0x%x\n", pos, cmd);
|
|
|
|
XPD_NOTICE(xpd, " IOC_TYPE=0x%02X\n", _IOC_TYPE(cmd));
|
|
|
|
XPD_NOTICE(xpd, " IOC_DIR=0x%02X\n", _IOC_DIR(cmd));
|
|
|
|
XPD_NOTICE(xpd, " IOC_NR=%d\n", _IOC_NR(cmd));
|
|
|
|
XPD_NOTICE(xpd, " IOC_SIZE=0x%02X\n", _IOC_SIZE(cmd));
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(report_bad_ioctl);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
int xpp_ioctl(struct dahdi_chan *chan, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd = chan->pvt;
|
|
|
|
int pos = chan->chanpos - 1;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd) {
|
2010-08-28 05:59:27 +08:00
|
|
|
ERR("%s: channel in pos %d, was already closed. Ignore.\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
__func__, pos);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
switch (cmd) {
|
2012-01-11 23:22:46 +08:00
|
|
|
default:
|
|
|
|
/* Some span-specific commands before we give up: */
|
|
|
|
if (PHONE_METHOD(card_ioctl, xpd)) {
|
|
|
|
return CALL_PHONE_METHOD(card_ioctl, xpd, pos, cmd,
|
|
|
|
arg);
|
|
|
|
}
|
|
|
|
report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd);
|
|
|
|
return -ENOTTY;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xpp_ioctl);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
int xpp_hooksig(struct dahdi_chan *chan, enum dahdi_txsig txsig)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd = chan->pvt;
|
|
|
|
xbus_t *xbus;
|
2010-08-28 05:59:27 +08:00
|
|
|
int pos = chan->chanpos - 1;
|
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd) {
|
2010-08-28 05:59:27 +08:00
|
|
|
ERR("%s: channel in pos %d, was already closed. Ignore.\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
__func__, pos);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!PHONE_METHOD(card_hooksig, xpd)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
LINE_ERR(xpd, pos,
|
2012-01-11 23:22:46 +08:00
|
|
|
"%s: No hooksig method for this channel. Ignore.\n",
|
|
|
|
__func__);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
xbus = xpd->xbus;
|
|
|
|
BUG_ON(!xbus);
|
2012-01-11 23:22:46 +08:00
|
|
|
DBG(SIGNAL, "Setting %s to %s (%d)\n", chan->name, txsig2str(txsig),
|
|
|
|
txsig);
|
2011-01-30 22:14:14 +08:00
|
|
|
return CALL_PHONE_METHOD(card_hooksig, xpd, pos, txsig);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(xpp_hooksig);
|
|
|
|
|
|
|
|
/* Req: Set the requested chunk size. This is the unit in which you must
|
|
|
|
report results for conferencing, etc */
|
|
|
|
int xpp_setchunksize(struct dahdi_span *span, int chunksize);
|
|
|
|
|
|
|
|
/* Enable maintenance modes */
|
|
|
|
int xpp_maint(struct dahdi_span *span, int cmd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct phonedev *phonedev = container_of(span, struct phonedev, span);
|
|
|
|
xpd_t *xpd = container_of(phonedev, struct xpd, phonedev);
|
|
|
|
int ret = 0;
|
2010-08-28 05:59:27 +08:00
|
|
|
#if 0
|
2012-01-11 23:22:46 +08:00
|
|
|
char loopback_data[] = "THE-QUICK-BROWN-FOX-JUMPED-OVER-THE-LAZY-DOG";
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
DBG(GENERAL, "span->mainttimer=%d\n", span->mainttimer);
|
2012-01-11 23:20:05 +08:00
|
|
|
switch (cmd) {
|
2012-01-11 23:22:46 +08:00
|
|
|
case DAHDI_MAINT_NONE:
|
|
|
|
INFO("XXX Turn off local and remote loops XXX\n");
|
|
|
|
break;
|
|
|
|
case DAHDI_MAINT_LOCALLOOP:
|
|
|
|
INFO("XXX Turn on local loopback XXX\n");
|
|
|
|
break;
|
|
|
|
case DAHDI_MAINT_REMOTELOOP:
|
|
|
|
INFO("XXX Turn on remote loopback XXX\n");
|
|
|
|
break;
|
|
|
|
case DAHDI_MAINT_LOOPUP:
|
|
|
|
INFO("XXX Send loopup code XXX\n");
|
|
|
|
break;
|
|
|
|
case DAHDI_MAINT_LOOPDOWN:
|
|
|
|
INFO("XXX Send loopdown code XXX\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("XPP: Unknown maint command: %d\n", cmd);
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-11 23:16:34 +08:00
|
|
|
if (span->mainttimer || span->maintstat)
|
2010-08-28 05:59:27 +08:00
|
|
|
update_xpd_status(xpd, DAHDI_ALARM_LOOPBACK);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xpp_maint);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_DAHDI_WATCHDOG
|
|
|
|
/*
|
|
|
|
* If the watchdog detects no received data, it will call the
|
|
|
|
* watchdog routine
|
|
|
|
*/
|
2012-04-12 04:09:44 +08:00
|
|
|
int xpp_watchdog(struct dahdi_span *span, int cause)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
static int rate_limit;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((rate_limit++ % 1000) == 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
DBG(GENERAL, "\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2012-04-12 04:09:44 +08:00
|
|
|
EXPORT_SYMBOL(xpp_watchdog);
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
|
2011-06-29 02:23:00 +08:00
|
|
|
/*
|
|
|
|
* Hardware Echo Canceller management
|
|
|
|
*/
|
|
|
|
static void echocan_free(struct dahdi_chan *chan,
|
2012-01-11 23:22:46 +08:00
|
|
|
struct dahdi_echocan_state *ec)
|
2011-06-29 02:23:00 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd;
|
|
|
|
xbus_t *xbus;
|
|
|
|
int pos = chan->chanpos - 1;
|
|
|
|
const struct echoops *echoops;
|
2011-06-29 02:23:00 +08:00
|
|
|
|
|
|
|
xpd = chan->pvt;
|
|
|
|
xbus = xpd->xbus;
|
|
|
|
echoops = ECHOOPS(xbus);
|
|
|
|
if (!echoops)
|
|
|
|
return;
|
2011-07-13 02:08:42 +08:00
|
|
|
LINE_DBG(GENERAL, xpd, pos, "mode=0x%X\n", ec->status.mode);
|
2011-06-29 02:23:00 +08:00
|
|
|
CALL_EC_METHOD(ec_set, xbus, xpd, pos, 0);
|
|
|
|
CALL_EC_METHOD(ec_update, xbus, xbus);
|
2012-01-11 23:17:09 +08:00
|
|
|
put_xpd(__func__, xpd); /* aquired in xpp_echocan_create() */
|
2011-06-29 02:23:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct dahdi_echocan_features xpp_ec_features = {
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct dahdi_echocan_ops xpp_ec_ops = {
|
|
|
|
.echocan_free = echocan_free,
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *xpp_echocan_name(const struct dahdi_chan *chan)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd;
|
|
|
|
xbus_t *xbus;
|
|
|
|
int pos;
|
2011-06-29 02:23:00 +08:00
|
|
|
|
|
|
|
if (!chan) {
|
|
|
|
NOTICE("%s(NULL)\n", __func__);
|
|
|
|
return "XPP";
|
|
|
|
}
|
|
|
|
xpd = chan->pvt;
|
|
|
|
xbus = xpd->xbus;
|
|
|
|
pos = chan->chanpos - 1;
|
2011-11-02 22:19:14 +08:00
|
|
|
LINE_DBG(GENERAL, xpd, pos, "\n");
|
2011-06-29 02:23:00 +08:00
|
|
|
if (!ECHOOPS(xbus))
|
|
|
|
return NULL;
|
2011-07-04 22:04:33 +08:00
|
|
|
/*
|
|
|
|
* quirks and limitations
|
|
|
|
*/
|
|
|
|
if (xbus->quirks.has_fxo) {
|
2015-11-17 04:42:21 +08:00
|
|
|
if (xbus->quirks.has_digital_span && xpd->xpd_type == XPD_TYPE_FXO) {
|
2011-07-04 22:04:33 +08:00
|
|
|
LINE_NOTICE(xpd, pos,
|
2012-01-11 23:22:46 +08:00
|
|
|
"quirk: give up HWEC on FXO: "
|
|
|
|
"AB has digital span\n");
|
2011-07-04 22:04:33 +08:00
|
|
|
return NULL;
|
2012-01-11 23:22:46 +08:00
|
|
|
} else if (xbus->sync_mode != SYNC_MODE_AB
|
2015-11-17 04:42:21 +08:00
|
|
|
&& xpd->xpd_type == XPD_TYPE_FXS) {
|
2011-07-04 22:04:33 +08:00
|
|
|
LINE_NOTICE(xpd, pos,
|
2012-01-11 23:22:46 +08:00
|
|
|
"quirk: give up HWEC on FXS: "
|
|
|
|
"AB has FXO and is sync slave\n");
|
2011-07-04 22:04:33 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2011-06-29 02:23:00 +08:00
|
|
|
return "XPP";
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(xpp_echocan_name);
|
|
|
|
|
2012-01-12 03:56:35 +08:00
|
|
|
int xpp_echocan_create(struct dahdi_chan *chan,
|
|
|
|
struct dahdi_echocanparams *ecp,
|
|
|
|
struct dahdi_echocanparam *p,
|
|
|
|
struct dahdi_echocan_state **ec)
|
2011-06-29 02:23:00 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd;
|
|
|
|
xbus_t *xbus;
|
|
|
|
int pos;
|
|
|
|
struct phonedev *phonedev;
|
|
|
|
const struct echoops *echoops;
|
|
|
|
int ret;
|
2011-06-29 02:23:00 +08:00
|
|
|
|
|
|
|
xpd = chan->pvt;
|
|
|
|
xbus = xpd->xbus;
|
|
|
|
pos = chan->chanpos - 1;
|
|
|
|
echoops = ECHOOPS(xbus);
|
|
|
|
if (!echoops)
|
|
|
|
return -ENODEV;
|
|
|
|
phonedev = &PHONEDEV(xpd);
|
|
|
|
*ec = phonedev->ec[pos];
|
|
|
|
(*ec)->ops = &xpp_ec_ops;
|
|
|
|
(*ec)->features = xpp_ec_features;
|
2012-01-11 23:17:09 +08:00
|
|
|
xpd = get_xpd(__func__, xpd); /* Returned in echocan_free() */
|
2011-07-13 02:08:42 +08:00
|
|
|
LINE_DBG(GENERAL, xpd, pos, "(tap=%d, param_count=%d)\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
ecp->tap_length, ecp->param_count);
|
2011-06-29 02:23:00 +08:00
|
|
|
ret = CALL_EC_METHOD(ec_set, xbus, xpd, pos, 1);
|
|
|
|
CALL_EC_METHOD(ec_update, xbus, xbus);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(xpp_echocan_create);
|
|
|
|
|
2011-11-03 01:05:38 +08:00
|
|
|
void xpp_span_assigned(struct dahdi_span *span)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct phonedev *phonedev = container_of(span, struct phonedev, span);
|
|
|
|
xpd_t *xpd = container_of(phonedev, struct xpd, phonedev);
|
2011-11-03 01:05:38 +08:00
|
|
|
|
|
|
|
XPD_INFO(xpd, "Span assigned: %d\n", span->spanno);
|
|
|
|
if (xpd->card_present) {
|
|
|
|
span->alarms &= ~DAHDI_ALARM_NOTOPEN;
|
|
|
|
dahdi_alarm_notify(&phonedev->span);
|
|
|
|
}
|
2017-06-20 19:39:34 +08:00
|
|
|
if (PHONE_METHOD(span_assigned, xpd))
|
|
|
|
CALL_PHONE_METHOD(span_assigned, xpd);
|
2011-11-03 01:05:38 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(xpp_span_assigned);
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
static const struct dahdi_span_ops xpp_span_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = xpp_open,
|
|
|
|
.close = xpp_close,
|
|
|
|
.ioctl = xpp_ioctl,
|
|
|
|
.maint = xpp_maint,
|
2011-06-29 02:23:00 +08:00
|
|
|
.echocan_create = xpp_echocan_create,
|
|
|
|
.echocan_name = xpp_echocan_name,
|
2011-11-03 01:05:38 +08:00
|
|
|
.assigned = xpp_span_assigned,
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct dahdi_span_ops xpp_rbs_span_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.hooksig = xpp_hooksig,
|
|
|
|
.open = xpp_open,
|
|
|
|
.close = xpp_close,
|
|
|
|
.ioctl = xpp_ioctl,
|
|
|
|
.maint = xpp_maint,
|
2011-06-29 02:23:00 +08:00
|
|
|
.echocan_create = xpp_echocan_create,
|
|
|
|
.echocan_name = xpp_echocan_name,
|
2011-11-03 01:05:38 +08:00
|
|
|
.assigned = xpp_span_assigned,
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
2011-10-27 03:05:49 +08:00
|
|
|
void xpd_set_spanname(xpd_t *xpd)
|
|
|
|
{
|
|
|
|
struct dahdi_span *span = &PHONEDEV(xpd).span;
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
snprintf(span->name, MAX_SPANNAME, "%s/%s", xpd->xbus->busname,
|
|
|
|
xpd->xpdname);
|
2011-10-27 03:06:57 +08:00
|
|
|
/*
|
|
|
|
* The "Xorcom XPD" is a prefix in one of the regexes we
|
|
|
|
* use in our dahdi_genconf to match for PRI cards.
|
|
|
|
* FIXME: After moving completely to sysfs, we can remove
|
|
|
|
* this horseshit.
|
|
|
|
*/
|
|
|
|
snprintf(span->desc, MAX_SPANDESC, "Xorcom XPD [%s].%d: %s",
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd->xbus->label, span->offset + 1, xpd->type_name);
|
2011-10-27 03:05:49 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(xpd_set_spanname);
|
|
|
|
|
2011-10-27 02:58:14 +08:00
|
|
|
static void xpd_init_span(xpd_t *xpd, unsigned offset, int cn)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct dahdi_span *span;
|
2011-10-27 02:58:14 +08:00
|
|
|
|
|
|
|
memset(&PHONEDEV(xpd).span, 0, sizeof(struct dahdi_span));
|
2013-12-30 02:43:14 +08:00
|
|
|
phonedev_alloc_channels(xpd, cn);
|
2011-10-27 02:58:14 +08:00
|
|
|
span = &PHONEDEV(xpd).span;
|
2012-01-12 03:56:35 +08:00
|
|
|
span->deflaw = DAHDI_LAW_MULAW; /* card_* drivers may override */
|
2011-10-27 02:58:14 +08:00
|
|
|
span->channels = cn;
|
|
|
|
span->chans = PHONEDEV(xpd).chans;
|
|
|
|
|
|
|
|
span->flags = DAHDI_FLAG_RBS;
|
|
|
|
span->offset = offset;
|
|
|
|
if (PHONEDEV(xpd).phoneops->card_hooksig)
|
|
|
|
span->ops = &xpp_rbs_span_ops; /* Only with RBS bits */
|
|
|
|
else
|
|
|
|
span->ops = &xpp_span_ops;
|
2011-10-27 03:05:49 +08:00
|
|
|
xpd_set_spanname(xpd);
|
2011-10-27 02:58:14 +08:00
|
|
|
list_add_tail(&span->device_node, &xpd->xbus->ddev->spans);
|
|
|
|
}
|
|
|
|
|
|
|
|
int xpd_dahdi_preregister(xpd_t *xpd, unsigned offset)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_t *xbus;
|
|
|
|
int cn;
|
|
|
|
struct phonedev *phonedev;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
|
|
|
|
xbus = xpd->xbus;
|
|
|
|
|
2011-01-30 22:13:22 +08:00
|
|
|
if (!IS_PHONEDEV(xpd)) {
|
|
|
|
XPD_ERR(xpd, "Not a telephony device\n");
|
|
|
|
return -EBADF;
|
|
|
|
}
|
2011-10-27 02:58:14 +08:00
|
|
|
|
|
|
|
phonedev = &PHONEDEV(xpd);
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
if (SPAN_REGISTERED(xpd)) {
|
|
|
|
XPD_ERR(xpd, "Already registered\n");
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
|
2011-10-27 02:58:14 +08:00
|
|
|
cn = PHONEDEV(xpd).channels;
|
|
|
|
xpd_init_span(xpd, offset, cn);
|
2011-10-27 03:09:09 +08:00
|
|
|
XPD_DBG(DEVICES, xpd, "Preregister local span %d: %d channels.\n",
|
|
|
|
offset + 1, cn);
|
2011-01-30 22:14:14 +08:00
|
|
|
CALL_PHONE_METHOD(card_dahdi_preregistration, xpd, 1);
|
2011-10-27 02:58:14 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xpd_dahdi_postregister(xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int cn;
|
2011-10-27 02:58:14 +08:00
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
atomic_inc(&num_registered_spans);
|
2011-01-30 22:11:49 +08:00
|
|
|
atomic_inc(&PHONEDEV(xpd).dahdi_registered);
|
2011-01-30 22:14:14 +08:00
|
|
|
CALL_PHONE_METHOD(card_dahdi_postregistration, xpd, 1);
|
2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* Update dahdi about our state:
|
|
|
|
* - Since asterisk didn't open the channel yet,
|
|
|
|
* the report is discarded anyway.
|
|
|
|
* - Our FXS driver have another notification mechanism that
|
|
|
|
* is triggered (indirectly) by the open() of the channe.
|
|
|
|
* - The real fix should be in Asterisk (to get the correct state
|
|
|
|
* after open).
|
|
|
|
*/
|
|
|
|
for_each_line(xpd, cn) {
|
2012-01-11 23:20:05 +08:00
|
|
|
if (IS_OFFHOOK(xpd, cn))
|
2010-08-28 05:59:27 +08:00
|
|
|
notify_rxsig(xpd, cn, DAHDI_RXSIG_OFFHOOK);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-27 02:58:14 +08:00
|
|
|
/*
|
|
|
|
* Try our best to make asterisk close all channels related to
|
|
|
|
* this Astribank:
|
|
|
|
* - Set span state to DAHDI_ALARM_NOTOPEN in all relevant spans.
|
2012-01-12 03:56:35 +08:00
|
|
|
* - Notify dahdi afterwards about spans
|
|
|
|
* (so it can see all changes at once).
|
2011-10-27 02:58:14 +08:00
|
|
|
* - Also send DAHDI_EVENT_REMOVED on all channels.
|
|
|
|
*/
|
|
|
|
void xpd_dahdi_preunregister(xpd_t *xpd)
|
|
|
|
{
|
2012-11-15 21:40:56 +08:00
|
|
|
if (!xpd || !IS_PHONEDEV(xpd))
|
2011-10-27 02:58:14 +08:00
|
|
|
return;
|
|
|
|
XPD_DBG(DEVICES, xpd, "\n");
|
|
|
|
update_xpd_status(xpd, DAHDI_ALARM_NOTOPEN);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xpd->card_present)
|
2011-10-27 02:58:14 +08:00
|
|
|
CALL_PHONE_METHOD(card_dahdi_preregistration, xpd, 0);
|
|
|
|
/* Now notify dahdi */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (SPAN_REGISTERED(xpd)) {
|
2011-10-27 02:58:14 +08:00
|
|
|
int j;
|
|
|
|
|
|
|
|
dahdi_alarm_notify(&PHONEDEV(xpd).span);
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_DBG(DEVICES, xpd,
|
2012-01-12 03:56:35 +08:00
|
|
|
"Queuing DAHDI_EVENT_REMOVED on all channels "
|
|
|
|
"to ask user to release them\n");
|
2012-01-11 23:22:46 +08:00
|
|
|
for (j = 0; j < PHONEDEV(xpd).span.channels; j++) {
|
|
|
|
dahdi_qevent_lock(XPD_CHAN(xpd, j),
|
|
|
|
DAHDI_EVENT_REMOVED);
|
2011-10-27 02:58:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void xpd_dahdi_postunregister(xpd_t *xpd)
|
|
|
|
{
|
2012-11-15 21:40:56 +08:00
|
|
|
if (!xpd || !IS_PHONEDEV(xpd))
|
2011-10-27 02:58:14 +08:00
|
|
|
return;
|
|
|
|
atomic_dec(&PHONEDEV(xpd).dahdi_registered);
|
|
|
|
atomic_dec(&num_registered_spans);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xpd->card_present)
|
2011-10-27 02:58:14 +08:00
|
|
|
CALL_PHONE_METHOD(card_dahdi_postregistration, xpd, 0);
|
|
|
|
}
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
/*------------------------- Initialization -------------------------*/
|
|
|
|
|
|
|
|
static void do_cleanup(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xpp_proc_toplevel) {
|
2010-08-28 05:59:27 +08:00
|
|
|
DBG(GENERAL, "Removing '%s' from proc\n", PROC_DIR);
|
|
|
|
remove_proc_entry(PROC_DIR, NULL);
|
|
|
|
xpp_proc_toplevel = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init xpp_dahdi_init(void)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int ret = 0;
|
|
|
|
void *top = NULL;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2017-03-27 17:42:56 +08:00
|
|
|
INFO("MAX_XPDS=%d (%d*%d)\n", MAX_XPDS, MAX_UNIT, MAX_SUBUNIT);
|
2010-08-28 05:59:27 +08:00
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
xpp_proc_toplevel = proc_mkdir(PROC_DIR, NULL);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpp_proc_toplevel) {
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = -EIO;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
top = xpp_proc_toplevel;
|
|
|
|
#endif
|
|
|
|
ret = xbus_core_init();
|
2012-01-11 23:20:05 +08:00
|
|
|
if (ret) {
|
2010-08-28 05:59:27 +08:00
|
|
|
ERR("xbus_core_init failed (%d)\n", ret);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
ret = xbus_pcm_init(top);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (ret) {
|
2010-08-28 05:59:27 +08:00
|
|
|
ERR("xbus_pcm_init failed (%d)\n", ret);
|
|
|
|
xbus_core_shutdown();
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
do_cleanup();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit xpp_dahdi_cleanup(void)
|
|
|
|
{
|
|
|
|
xbus_pcm_shutdown();
|
|
|
|
xbus_core_shutdown();
|
|
|
|
do_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("XPP Dahdi Driver");
|
|
|
|
MODULE_AUTHOR("Oron Peled <oron@actcom.co.il>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
module_init(xpp_dahdi_init);
|
|
|
|
module_exit(xpp_dahdi_cleanup);
|