2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* Written by Oron Peled <oron@actcom.co.il>
|
|
|
|
* Copyright (C) 2004-2006, Xorcom
|
|
|
|
*
|
|
|
|
* 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/module.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/sched.h>
|
2013-09-29 19:20:38 +08:00
|
|
|
#include <linux/mutex.h>
|
2010-08-28 05:59:27 +08:00
|
|
|
#include <linux/proc_fs.h>
|
2013-05-22 04:33:18 +08:00
|
|
|
#include <linux/seq_file.h>
|
2014-02-28 23:28:46 +08:00
|
|
|
#include <linux/slab.h>
|
2010-08-28 05:59:27 +08:00
|
|
|
#ifdef PROTOCOL_DEBUG
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#endif
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/delay.h> /* for msleep() to debug */
|
|
|
|
#include "xpd.h"
|
|
|
|
#include "xpp_dahdi.h"
|
|
|
|
#include "xbus-core.h"
|
|
|
|
#include "card_global.h"
|
|
|
|
#include "dahdi_debug.h"
|
|
|
|
|
|
|
|
static const char rcsid[] = "$Id$";
|
|
|
|
|
|
|
|
/* Defines */
|
2012-01-11 23:22:46 +08:00
|
|
|
#define INITIALIZATION_TIMEOUT (90*HZ) /* in jiffies */
|
2010-08-28 05:59:27 +08:00
|
|
|
#define PROC_XBUSES "xbuses"
|
|
|
|
#define PROC_XBUS_SUMMARY "summary"
|
|
|
|
|
|
|
|
#ifdef PROTOCOL_DEBUG
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
#define PROC_XBUS_COMMAND "command"
|
2013-05-22 04:33:18 +08:00
|
|
|
static const struct file_operations proc_xbus_command_ops;
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Command line parameters */
|
|
|
|
extern int debug;
|
2012-01-11 23:22:46 +08:00
|
|
|
static DEF_PARM(uint, command_queue_length, 1500, 0444,
|
|
|
|
"Maximal command queue length");
|
|
|
|
static DEF_PARM(uint, poll_timeout, 1000, 0644,
|
|
|
|
"Timeout (in jiffies) waiting for units to reply");
|
2010-08-28 05:59:27 +08:00
|
|
|
static DEF_PARM_BOOL(rx_tasklet, 0, 0644, "Use receive tasklets");
|
2014-01-26 22:11:01 +08:00
|
|
|
static DEF_PARM_BOOL(dahdi_autoreg, 0, 0444,
|
2014-01-26 22:11:00 +08:00
|
|
|
"Register devices automatically (1) or not (0). UNUSED.");
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2013-05-22 04:33:18 +08:00
|
|
|
static const struct file_operations xbus_read_proc_ops;
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
2012-01-11 23:22:46 +08:00
|
|
|
static void transport_init(xbus_t *xbus, struct xbus_ops *ops,
|
|
|
|
ushort max_send_size,
|
|
|
|
struct device *transport_device, void *priv);
|
2010-08-28 05:59:27 +08:00
|
|
|
static void transport_destroy(xbus_t *xbus);
|
|
|
|
|
|
|
|
/* Data structures */
|
2010-09-25 06:44:53 +08:00
|
|
|
static DEFINE_SPINLOCK(xbuses_lock);
|
2010-08-28 05:59:27 +08:00
|
|
|
#ifdef CONFIG_PROC_FS
|
2012-01-11 23:22:46 +08:00
|
|
|
static struct proc_dir_entry *proc_xbuses;
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct xbus_desc {
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_t *xbus;
|
2014-05-12 22:51:59 +08:00
|
|
|
int shutting_down;
|
2010-08-28 05:59:27 +08:00
|
|
|
} xbuses_array[MAX_BUSES];
|
|
|
|
|
2014-05-12 22:51:59 +08:00
|
|
|
static int xbus_is_shutting_down(int num)
|
|
|
|
{
|
|
|
|
return xbuses_array[num].shutting_down;
|
|
|
|
}
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
static xbus_t *xbus_byhwid(const char *hwid)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int i;
|
|
|
|
xbus_t *xbus;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(xbuses_array); i++) {
|
|
|
|
xbus = xbuses_array[i].xbus;
|
|
|
|
if (xbus && strcmp(hwid, xbus->label) == 0)
|
|
|
|
return xbus;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xbus_check_unique(xbus_t *xbus)
|
|
|
|
{
|
|
|
|
if (!xbus)
|
|
|
|
return -ENOENT;
|
2011-05-31 21:11:56 +08:00
|
|
|
if (xbus->label && *(xbus->label)) {
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_t *xbus_old;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
XBUS_DBG(DEVICES, xbus, "Checking LABEL='%s'\n", xbus->label);
|
|
|
|
xbus_old = xbus_byhwid(xbus->label);
|
|
|
|
if (xbus_old && xbus_old != xbus) {
|
|
|
|
XBUS_NOTICE(xbus_old,
|
2012-01-12 03:56:35 +08:00
|
|
|
"Duplicate LABEL='%s'. Leave %s unused. "
|
|
|
|
"refcount_xbus=%d\n",
|
|
|
|
xbus_old->label, xbus->busname,
|
|
|
|
refcount_xbus(xbus_old));
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
} else {
|
2011-05-31 21:11:56 +08:00
|
|
|
XBUS_NOTICE(xbus, "Missing board label (old Astribank?)\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *xbus_statename(enum xbus_state st)
|
|
|
|
{
|
2012-01-11 23:20:05 +08:00
|
|
|
switch (st) {
|
2012-01-11 23:22:46 +08:00
|
|
|
case XBUS_STATE_START:
|
|
|
|
return "START";
|
|
|
|
case XBUS_STATE_IDLE:
|
|
|
|
return "IDLE";
|
|
|
|
case XBUS_STATE_SENT_REQUEST:
|
|
|
|
return "SENT_REQUEST";
|
|
|
|
case XBUS_STATE_RECVD_DESC:
|
|
|
|
return "RECVD_DESC";
|
|
|
|
case XBUS_STATE_READY:
|
|
|
|
return "READY";
|
|
|
|
case XBUS_STATE_DEACTIVATING:
|
|
|
|
return "DEACTIVATING";
|
|
|
|
case XBUS_STATE_DEACTIVATED:
|
|
|
|
return "DEACTIVATED";
|
|
|
|
case XBUS_STATE_FAIL:
|
|
|
|
return "FAIL";
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xbus_statename);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
static void init_xbus(uint num, xbus_t *xbus)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct xbus_desc *desc;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(num >= ARRAY_SIZE(xbuses_array));
|
|
|
|
desc = &xbuses_array[num];
|
|
|
|
desc->xbus = xbus;
|
2014-05-12 22:51:59 +08:00
|
|
|
if (xbus)
|
|
|
|
desc->shutting_down = 0;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
xbus_t *xbus_num(uint num)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct xbus_desc *desc;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (num >= ARRAY_SIZE(xbuses_array))
|
2010-08-28 05:59:27 +08:00
|
|
|
return NULL;
|
|
|
|
desc = &xbuses_array[num];
|
|
|
|
return desc->xbus;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xbus_num);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
static void initialize_xbuses_array(void)
|
|
|
|
{
|
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
|
|
|
for (i = 0; i < ARRAY_SIZE(xbuses_array); i++)
|
2010-08-28 05:59:27 +08:00
|
|
|
init_xbus(i, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void finalize_xbuses_array(void)
|
|
|
|
{
|
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
|
|
|
for (i = 0; i < ARRAY_SIZE(xbuses_array); i++) {
|
|
|
|
if (xbuses_array[i].xbus != NULL) {
|
2012-01-11 23:17:09 +08:00
|
|
|
ERR("%s: xbus #%d is not NULL\n", __func__, i);
|
2010-08-28 05:59:27 +08:00
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called by put_xbus() when XBUS has no more references.
|
|
|
|
*/
|
|
|
|
static void xbus_destroy(struct kref *kref)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_t *xbus;
|
2014-05-12 22:51:59 +08:00
|
|
|
int num;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
xbus = kref_to_xbus(kref);
|
2014-05-12 23:36:16 +08:00
|
|
|
XBUS_DBG(DEVICES, xbus, "%s\n", __func__);
|
2014-05-12 22:51:59 +08:00
|
|
|
num = xbus->num;
|
|
|
|
xbuses_array[num].shutting_down = 1;
|
2010-08-28 05:59:27 +08:00
|
|
|
xbus_sysfs_remove(xbus);
|
|
|
|
}
|
|
|
|
|
|
|
|
xbus_t *get_xbus(const char *msg, uint num)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
unsigned long flags;
|
|
|
|
xbus_t *xbus;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2014-05-12 22:51:59 +08:00
|
|
|
if (xbus_is_shutting_down(num)) {
|
|
|
|
DBG(DEVICES, "%s(%s): XBUS-%d: shutting down\n", __func__,
|
|
|
|
msg, num);
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_lock_irqsave(&xbuses_lock, flags);
|
|
|
|
xbus = xbus_num(num);
|
|
|
|
if (xbus != NULL) {
|
|
|
|
kref_get(&xbus->kref);
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_DBG(DEVICES, xbus, "%s: refcount_xbus=%d\n", msg,
|
|
|
|
refcount_xbus(xbus));
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&xbuses_lock, flags);
|
|
|
|
return xbus;
|
|
|
|
}
|
|
|
|
|
|
|
|
void put_xbus(const char *msg, xbus_t *xbus)
|
|
|
|
{
|
2014-05-12 22:51:59 +08:00
|
|
|
if (xbus_is_shutting_down(xbus->num)) {
|
|
|
|
if (!refcount_xbus(xbus)) {
|
|
|
|
DBG(DEVICES, "%s(%s): XBUS-%d: shutting down\n",
|
|
|
|
__func__, msg, xbus->num);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_DBG(DEVICES, xbus, "%s: refcount_xbus=%d\n", msg,
|
|
|
|
refcount_xbus(xbus));
|
2010-08-28 05:59:27 +08:00
|
|
|
kref_put(&xbus->kref, xbus_destroy);
|
|
|
|
}
|
|
|
|
|
|
|
|
int refcount_xbus(xbus_t *xbus)
|
|
|
|
{
|
|
|
|
struct kref *kref = &xbus->kref;
|
|
|
|
|
|
|
|
return atomic_read(&kref->refcount);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------- Frame Handling ------------------------*/
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
void xframe_init(xbus_t *xbus, xframe_t *xframe, void *buf, size_t maxsize,
|
|
|
|
void *priv)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
|
|
|
memset(xframe, 0, sizeof(*xframe));
|
|
|
|
INIT_LIST_HEAD(&xframe->frame_list);
|
|
|
|
xframe->priv = priv;
|
|
|
|
xframe->xbus = xbus;
|
|
|
|
xframe->packets = xframe->first_free = buf;
|
|
|
|
xframe->frame_maxlen = maxsize;
|
|
|
|
atomic_set(&xframe->frame_len, 0);
|
|
|
|
do_gettimeofday(&xframe->tv_created);
|
|
|
|
xframe->xframe_magic = XFRAME_MAGIC;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xframe_init);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return pointer to next packet slot in the frame
|
|
|
|
* or NULL if the frame is full.
|
|
|
|
*
|
|
|
|
* FIXME: we do not use atomic_add_return() because kernel-2.6.8
|
|
|
|
* does not have it. This make this code a little racy,
|
|
|
|
* but we currently call xframe_next_packet() only in the
|
|
|
|
* PCM loop (xbus_tick() etc.)
|
|
|
|
*/
|
|
|
|
xpacket_t *xframe_next_packet(xframe_t *frm, int len)
|
|
|
|
{
|
|
|
|
int newlen = XFRAME_LEN(frm);
|
|
|
|
|
|
|
|
newlen += len;
|
2012-01-12 03:56:35 +08:00
|
|
|
#if 0
|
2012-01-12 04:33:03 +08:00
|
|
|
DBG(GENERAL, "len=%d, newlen=%d, frm->frame_len=%d\n",
|
|
|
|
len, newlen, XFRAME_LEN(frm));
|
2012-01-12 03:56:35 +08:00
|
|
|
#endif
|
2012-01-13 01:14:15 +08:00
|
|
|
if (newlen > XFRAME_DATASIZE)
|
2010-08-28 05:59:27 +08:00
|
|
|
return NULL;
|
|
|
|
atomic_add(len, &frm->frame_len);
|
|
|
|
return (xpacket_t *)(frm->packets + newlen - len);
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xframe_next_packet);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2010-09-25 06:44:53 +08:00
|
|
|
static DEFINE_SPINLOCK(serialize_dump_xframe);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:21:54 +08:00
|
|
|
static void do_hexdump(const char msg[], __u8 *data, uint16_t len)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int i;
|
|
|
|
int debug = DBG_ANY; /* mask global debug */
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < len; i++)
|
2010-08-28 05:59:27 +08:00
|
|
|
DBG(ANY, "%s: %3d> %02X\n", msg, i, data[i]);
|
|
|
|
}
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
void dump_xframe(const char msg[], const xbus_t *xbus, const xframe_t *xframe,
|
|
|
|
int debug)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
const uint16_t frm_len = XFRAME_LEN(xframe);
|
|
|
|
xpacket_t *pack;
|
|
|
|
uint16_t pos = 0;
|
|
|
|
uint16_t nextpos;
|
|
|
|
int num = 1;
|
|
|
|
bool do_print;
|
|
|
|
unsigned long flags;
|
2012-01-11 23:16:34 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xframe->xframe_magic != XFRAME_MAGIC) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_ERR(xbus, "%s: bad xframe_magic %lX\n", __func__,
|
|
|
|
xframe->xframe_magic);
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
spin_lock_irqsave(&serialize_dump_xframe, flags);
|
|
|
|
do {
|
2012-01-11 23:20:05 +08:00
|
|
|
if (pos >= xbus->transport.max_send_size) {
|
|
|
|
if (printk_ratelimit()) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_NOTICE(xbus,
|
|
|
|
"%s: xframe overflow (%d bytes)\n",
|
|
|
|
msg, frm_len);
|
2010-08-28 05:59:27 +08:00
|
|
|
do_hexdump(msg, xframe->packets, frm_len);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (pos > frm_len) {
|
|
|
|
if (printk_ratelimit()) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_NOTICE(xbus,
|
2012-01-12 03:56:35 +08:00
|
|
|
"%s: packet overflow pos=%d "
|
|
|
|
"frame_len=%d\n",
|
|
|
|
msg, pos, frm_len);
|
2010-08-28 05:59:27 +08:00
|
|
|
do_hexdump(msg, xframe->packets, frm_len);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pack = (xpacket_t *)&xframe->packets[pos];
|
2012-01-11 23:20:05 +08:00
|
|
|
if (XPACKET_LEN(pack) <= 0) {
|
|
|
|
if (printk_ratelimit()) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_NOTICE(xbus,
|
2012-01-12 03:56:35 +08:00
|
|
|
"%s: xframe -- bad packet_len=%d "
|
|
|
|
"pos=%d frame_len=%d\n",
|
|
|
|
msg, XPACKET_LEN(pack), pos, frm_len);
|
2010-08-28 05:59:27 +08:00
|
|
|
do_hexdump(msg, xframe->packets, frm_len);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nextpos = pos + XPACKET_LEN(pack);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (nextpos > frm_len) {
|
|
|
|
if (printk_ratelimit()) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_NOTICE(xbus,
|
2012-01-12 03:56:35 +08:00
|
|
|
"%s: packet overflow nextpos=%d "
|
|
|
|
"frame_len=%d\n",
|
|
|
|
msg, nextpos, frm_len);
|
2010-08-28 05:59:27 +08:00
|
|
|
do_hexdump(msg, xframe->packets, frm_len);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
do_print = 0;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (debug == DBG_ANY)
|
2010-08-28 05:59:27 +08:00
|
|
|
do_print = 1;
|
2012-01-11 23:22:46 +08:00
|
|
|
else if (XPACKET_OP(pack) != XPROTO_NAME(GLOBAL, PCM_READ)
|
|
|
|
&& XPACKET_OP(pack) != XPROTO_NAME(GLOBAL, PCM_WRITE))
|
2010-08-28 05:59:27 +08:00
|
|
|
do_print = 1;
|
2012-01-11 23:20:05 +08:00
|
|
|
else if (debug & DBG_PCM) {
|
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++ % 1003) == 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
do_print = 1;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (do_print) {
|
|
|
|
if (num == 1) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_DBG(ANY, xbus, "%s: frame_len=%d. %s\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
msg, frm_len, (XPACKET_IS_PCM(pack))
|
|
|
|
? "(IS_PCM)" : "");
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_DBG(ANY, xbus,
|
2012-01-12 03:56:35 +08:00
|
|
|
" %3d. DATALEN=%d pcm=%d slot=%d OP=0x%02X "
|
|
|
|
"XPD-%d%d (pos=%d)\n",
|
|
|
|
num, XPACKET_LEN(pack), XPACKET_IS_PCM(pack),
|
|
|
|
XPACKET_PCMSLOT(pack), XPACKET_OP(pack),
|
|
|
|
XPACKET_ADDR_UNIT(pack),
|
|
|
|
XPACKET_ADDR_SUBUNIT(pack), pos);
|
2010-08-28 05:59:27 +08:00
|
|
|
dump_packet(" ", pack, debug);
|
|
|
|
}
|
|
|
|
num++;
|
|
|
|
pos = nextpos;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (pos >= frm_len)
|
2010-08-28 05:59:27 +08:00
|
|
|
break;
|
2012-01-11 23:20:05 +08:00
|
|
|
} while (1);
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_unlock_irqrestore(&serialize_dump_xframe, flags);
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(dump_xframe);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Frame is freed:
|
2012-01-11 23:19:01 +08:00
|
|
|
* - In case of error, by this function.
|
|
|
|
* - Otherwise, by the underlying sending mechanism
|
2010-08-28 05:59:27 +08:00
|
|
|
*/
|
|
|
|
int send_pcm_frame(xbus_t *xbus, xframe_t *xframe)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct xbus_ops *ops;
|
|
|
|
int ret = -ENODEV;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xframe);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!XBUS_IS(xbus, READY)) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_ERR(xbus,
|
|
|
|
"Dropped a pcm frame -- hardware is not ready.\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
ops = transportops_get(xbus);
|
|
|
|
BUG_ON(!ops);
|
|
|
|
ret = ops->xframe_send_pcm(xbus, xframe);
|
|
|
|
transportops_put(xbus);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (ret)
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_COUNTER(xbus, TX_BYTES) += XFRAME_LEN(xframe);
|
|
|
|
return ret;
|
|
|
|
|
2012-01-11 23:16:34 +08:00
|
|
|
error:
|
2010-08-28 05:59:27 +08:00
|
|
|
FREE_SEND_XFRAME(xbus, xframe);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(send_pcm_frame);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
static int really_send_cmd_frame(xbus_t *xbus, xframe_t *xframe)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct xbus_ops *ops;
|
|
|
|
int ret;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
BUG_ON(!xframe);
|
|
|
|
BUG_ON(xframe->xframe_magic != XFRAME_MAGIC);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!XBUS_FLAGS(xbus, CONNECTED)) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_ERR(xbus,
|
2012-01-12 03:56:35 +08:00
|
|
|
"Dropped command before sending -- "
|
|
|
|
"hardware deactivated.\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
dump_xframe("Dropped", xbus, xframe, DBG_ANY);
|
|
|
|
FREE_SEND_XFRAME(xbus, xframe);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
ops = transportops_get(xbus);
|
|
|
|
BUG_ON(!ops);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (debug & DBG_COMMANDS)
|
2010-08-28 05:59:27 +08:00
|
|
|
dump_xframe("TX-CMD", xbus, xframe, DBG_ANY);
|
|
|
|
ret = ops->xframe_send_cmd(xbus, xframe);
|
|
|
|
transportops_put(xbus);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (ret == 0) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_COUNTER(xbus, TX_CMD)++;
|
|
|
|
XBUS_COUNTER(xbus, TX_BYTES) += XFRAME_LEN(xframe);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xbus_command_queue_tick(xbus_t *xbus)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xframe_t *frm;
|
|
|
|
int ret = 0;
|
|
|
|
int packno;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
xbus->command_tick_counter++;
|
|
|
|
xbus->usec_nosend -= 1000; /* That's our budget */
|
2012-01-11 23:20:05 +08:00
|
|
|
for (packno = 0; packno < 3; packno++) {
|
|
|
|
if (xbus->usec_nosend > 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
break;
|
|
|
|
frm = xframe_dequeue(&xbus->command_queue);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!frm) {
|
2010-08-28 05:59:27 +08:00
|
|
|
wake_up(&xbus->command_queue_empty);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
BUG_ON(frm->xframe_magic != XFRAME_MAGIC);
|
|
|
|
xbus->usec_nosend += frm->usec_towait;
|
|
|
|
ret = really_send_cmd_frame(xbus, frm);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (ret < 0) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_ERR(xbus,
|
2012-01-11 23:22:46 +08:00
|
|
|
"Failed to send from command_queue (ret=%d)\n",
|
|
|
|
ret);
|
2010-08-28 05:59:27 +08:00
|
|
|
xbus_setstate(xbus, XBUS_STATE_FAIL);
|
|
|
|
}
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xbus->usec_nosend < 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
xbus->usec_nosend = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xbus_command_queue_tick);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
static void xbus_command_queue_clean(xbus_t *xbus)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xframe_t *frm;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
XBUS_DBG(DEVICES, xbus, "count=%d\n", xbus->command_queue.count);
|
|
|
|
xframe_queue_disable(&xbus->command_queue, 1);
|
2012-01-13 01:14:15 +08:00
|
|
|
while ((frm = xframe_dequeue(&xbus->command_queue)) != NULL)
|
2010-08-28 05:59:27 +08:00
|
|
|
FREE_SEND_XFRAME(xbus, frm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xbus_command_queue_waitempty(xbus_t *xbus)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int ret;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
XBUS_DBG(DEVICES, xbus, "Waiting for command_queue to empty\n");
|
2012-01-11 23:22:46 +08:00
|
|
|
ret =
|
|
|
|
wait_event_interruptible(xbus->command_queue_empty,
|
|
|
|
xframe_queue_count(&xbus->command_queue) ==
|
|
|
|
0);
|
2012-01-13 01:14:15 +08:00
|
|
|
if (ret)
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_ERR(xbus, "waiting for command_queue interrupted!!!\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int send_cmd_frame(xbus_t *xbus, xframe_t *xframe)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
static int rate_limit;
|
|
|
|
int ret = 0;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(xframe->xframe_magic != XFRAME_MAGIC);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!XBUS_FLAGS(xbus, CONNECTED)) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_ERR(xbus,
|
2012-01-12 03:56:35 +08:00
|
|
|
"Dropped command before queueing -- "
|
|
|
|
"hardware deactivated.\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto err;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (debug & DBG_COMMANDS)
|
2012-01-11 23:17:09 +08:00
|
|
|
dump_xframe(__func__, xbus, xframe, DBG_ANY);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xframe_enqueue(&xbus->command_queue, xframe)) {
|
|
|
|
if ((rate_limit++ % 1003) == 0) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_ERR(xbus,
|
2012-01-12 03:56:35 +08:00
|
|
|
"Dropped command xframe. Cannot enqueue (%d)\n",
|
|
|
|
rate_limit);
|
2012-01-11 23:17:09 +08:00
|
|
|
dump_xframe(__func__, xbus, xframe, DBG_ANY);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
xbus_setstate(xbus, XBUS_STATE_FAIL);
|
|
|
|
ret = -E2BIG;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
FREE_SEND_XFRAME(xbus, xframe);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(send_cmd_frame);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*------------------------- Receive Tasklet Handling ---------------*/
|
|
|
|
|
|
|
|
static void xframe_enqueue_recv(xbus_t *xbus, xframe_t *xframe)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int cpu = smp_processor_id();
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
xbus->cpu_rcv_intr[cpu]++;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xframe_enqueue(&xbus->receive_queue, xframe)) {
|
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++ % 1003) == 0)
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_ERR(xbus,
|
|
|
|
"Failed to enqueue for receive_tasklet (%d)\n",
|
|
|
|
rate_limit);
|
2010-08-28 05:59:27 +08:00
|
|
|
FREE_RECV_XFRAME(xbus, xframe); /* return to receive_pool */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tasklet_schedule(&xbus->receive_tasklet);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* process frames in the receive_queue in a tasklet
|
|
|
|
*/
|
|
|
|
static void receive_tasklet_func(unsigned long data)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_t *xbus = (xbus_t *)data;
|
|
|
|
xframe_t *xframe = NULL;
|
|
|
|
int cpu = smp_processor_id();
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
xbus->cpu_rcv_tasklet[cpu]++;
|
2012-01-13 01:14:15 +08:00
|
|
|
while ((xframe = xframe_dequeue(&xbus->receive_queue)) != NULL)
|
2010-08-28 05:59:27 +08:00
|
|
|
xframe_receive(xbus, xframe);
|
|
|
|
}
|
|
|
|
|
|
|
|
void xbus_receive_xframe(xbus_t *xbus, xframe_t *xframe)
|
|
|
|
{
|
|
|
|
BUG_ON(!xbus);
|
2014-05-12 22:51:59 +08:00
|
|
|
if (xbus_is_shutting_down(xbus->num)) {
|
|
|
|
static int rate_limit;
|
|
|
|
|
|
|
|
if ((rate_limit++ % 1000) == 0)
|
|
|
|
XBUS_NOTICE(xbus, "%s: during shutdown (%d)\n",
|
|
|
|
__func__, rate_limit);
|
|
|
|
return;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (rx_tasklet) {
|
2010-08-28 05:59:27 +08:00
|
|
|
xframe_enqueue_recv(xbus, xframe);
|
|
|
|
} else {
|
2012-01-11 23:20:05 +08:00
|
|
|
if (likely(XBUS_FLAGS(xbus, CONNECTED)))
|
2010-08-28 05:59:27 +08:00
|
|
|
xframe_receive(xbus, xframe);
|
|
|
|
else
|
2012-01-12 03:56:35 +08:00
|
|
|
/* return to receive_pool */
|
|
|
|
FREE_RECV_XFRAME(xbus, xframe);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xbus_receive_xframe);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*------------------------- Bus Management -------------------------*/
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd_of(const xbus_t *xbus, int xpd_num)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!VALID_XPD_NUM(xpd_num))
|
2010-08-28 05:59:27 +08:00
|
|
|
return NULL;
|
|
|
|
return xbus->xpds[xpd_num];
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xpd_of);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd_byaddr(const xbus_t *xbus, uint unit, uint subunit)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:20:05 +08:00
|
|
|
if (unit > MAX_UNIT || subunit > MAX_SUBUNIT)
|
2010-08-28 05:59:27 +08:00
|
|
|
return NULL;
|
2012-01-11 23:21:13 +08:00
|
|
|
return xbus->xpds[XPD_IDX(unit, subunit)];
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xpd_byaddr);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
int xbus_xpd_bind(xbus_t *xbus, xpd_t *xpd, int unit, int subunit)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
unsigned int xpd_num;
|
|
|
|
unsigned long flags;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
2012-01-11 23:21:13 +08:00
|
|
|
xpd_num = XPD_IDX(unit, subunit);
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_DBG(DEVICES, xbus, "XPD #%d\n", xpd_num);
|
|
|
|
spin_lock_irqsave(&xbus->lock, flags);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!VALID_XPD_NUM(xpd_num)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_ERR(xbus, "Bad xpd_num = %d\n", xpd_num);
|
|
|
|
BUG();
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xbus->xpds[xpd_num] != NULL) {
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *other = xbus->xpds[xpd_num];
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_ERR(xbus, "xpd_num=%d is occupied by %p (%s)\n", xpd_num,
|
|
|
|
other, other->xpdname);
|
2010-08-28 05:59:27 +08:00
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
snprintf(xpd->xpdname, XPD_NAMELEN, "XPD-%1d%1d", unit, subunit);
|
|
|
|
MKADDR(&xpd->addr, unit, subunit);
|
|
|
|
xpd->xbus_idx = xpd_num;
|
|
|
|
xbus->xpds[xpd_num] = xpd;
|
|
|
|
xpd->xbus = xbus;
|
|
|
|
atomic_inc(&xbus->num_xpds);
|
|
|
|
spin_unlock_irqrestore(&xbus->lock, flags);
|
|
|
|
/* Must be done out of atomic context */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xpd_device_register(xbus, xpd) < 0) {
|
2012-01-11 23:17:09 +08:00
|
|
|
XPD_ERR(xpd, "%s: xpd_device_register() failed\n", __func__);
|
2010-08-28 05:59:27 +08:00
|
|
|
/* FIXME: What to do? */
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xbus_xpd_unbind(xbus_t *xbus, xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
unsigned int xpd_num = xpd->xbus_idx;
|
|
|
|
unsigned long flags;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
XBUS_DBG(DEVICES, xbus, "XPD #%d\n", xpd_num);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!VALID_XPD_NUM(xpd_num)) {
|
2012-01-11 23:17:09 +08:00
|
|
|
XBUS_ERR(xbus, "%s: Bad xpd_num = %d\n", __func__, xpd_num);
|
2010-08-28 05:59:27 +08:00
|
|
|
BUG();
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xbus->xpds[xpd_num] == NULL) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_ERR(xbus, "%s: slot xpd_num=%d is empty\n", __func__,
|
|
|
|
xpd_num);
|
2010-08-28 05:59:27 +08:00
|
|
|
BUG();
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xbus->xpds[xpd_num] != xpd) {
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *other = xbus->xpds[xpd_num];
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
XBUS_ERR(xbus, "%s: slot xpd_num=%d is occupied by %p (%s)\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
__func__, xpd_num, other, other->xpdname);
|
2010-08-28 05:59:27 +08:00
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
spin_lock_irqsave(&xbus->lock, flags);
|
|
|
|
xpd->xbus = NULL;
|
|
|
|
xbus->xpds[xpd_num] = NULL;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (atomic_dec_and_test(&xbus->num_xpds))
|
2010-08-28 05:59:27 +08:00
|
|
|
xbus_setstate(xbus, XBUS_STATE_IDLE);
|
|
|
|
spin_unlock_irqrestore(&xbus->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-17 04:42:21 +08:00
|
|
|
static xpd_type_t xpd_hw2xpd_type(const struct unit_descriptor *unit_descriptor)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2015-11-17 04:42:21 +08:00
|
|
|
xpd_type_t xpd_type;
|
|
|
|
|
|
|
|
switch (unit_descriptor->type) {
|
|
|
|
case 1:
|
|
|
|
case 6:
|
|
|
|
xpd_type = XPD_TYPE_FXS;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
xpd_type = XPD_TYPE_FXO;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
xpd_type = XPD_TYPE_BRI;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
xpd_type = XPD_TYPE_PRI;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
xpd_type = XPD_TYPE_ECHO;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
xpd_type = XPD_TYPE_NOMODULE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NOTICE("WARNING: xpd hw type is: %d\n", unit_descriptor->type);
|
|
|
|
xpd_type = XPD_TYPE_NOMODULE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return xpd_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int new_card(xbus_t *xbus, const struct unit_descriptor *unit_descriptor)
|
|
|
|
{
|
|
|
|
int unit = unit_descriptor->addr.unit;
|
|
|
|
xpd_type_t xpd_type;
|
|
|
|
__u8 hw_type;
|
|
|
|
__u8 numchips;
|
|
|
|
__u8 ports_per_chip;
|
|
|
|
__u8 ports;
|
|
|
|
__u8 port_dir;
|
2012-01-11 23:22:46 +08:00
|
|
|
const xproto_table_t *proto_table;
|
|
|
|
int i;
|
|
|
|
int subunits;
|
|
|
|
int ret = 0;
|
|
|
|
int remaining_ports;
|
|
|
|
const struct echoops *echoops;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2015-11-17 04:42:21 +08:00
|
|
|
/* Translate parameters from "unit_descriptor" */
|
|
|
|
hw_type = unit_descriptor->type;
|
|
|
|
numchips = unit_descriptor->numchips;
|
|
|
|
ports_per_chip = unit_descriptor->ports_per_chip;
|
|
|
|
port_dir = unit_descriptor->port_dir;
|
|
|
|
ports = unit_descriptor->ports_per_chip * unit_descriptor->numchips;
|
|
|
|
xpd_type = xpd_hw2xpd_type(unit_descriptor);
|
|
|
|
proto_table = xproto_get(xpd_type);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!proto_table) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_NOTICE(xbus,
|
2015-11-17 04:42:21 +08:00
|
|
|
"CARD %d: missing protocol table for xpd_type %d. "
|
2012-01-12 03:56:35 +08:00
|
|
|
"Ignored.\n",
|
2015-11-17 04:42:21 +08:00
|
|
|
unit, xpd_type);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2011-06-29 02:23:00 +08:00
|
|
|
echoops = proto_table->echoops;
|
|
|
|
if (echoops) {
|
|
|
|
XBUS_INFO(xbus, "Detected ECHO Canceler (%d)\n", unit);
|
|
|
|
if (ECHOOPS(xbus)) {
|
|
|
|
XBUS_NOTICE(xbus,
|
2015-11-17 04:42:21 +08:00
|
|
|
"CARD %d: tryies to define echoops (xpd_type %d) "
|
2012-01-12 03:56:35 +08:00
|
|
|
"but we already have one. Ignored.\n",
|
2015-11-17 04:42:21 +08:00
|
|
|
unit, xpd_type);
|
2011-06-29 02:23:00 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
xbus->echo_state.echoops = echoops;
|
|
|
|
xbus->echo_state.xpd_idx = XPD_IDX(unit, 0);
|
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
remaining_ports = ports;
|
2012-01-11 23:22:46 +08:00
|
|
|
subunits =
|
|
|
|
(ports + proto_table->ports_per_subunit -
|
|
|
|
1) / proto_table->ports_per_subunit;
|
|
|
|
XBUS_DBG(DEVICES, xbus,
|
2015-11-17 04:42:21 +08:00
|
|
|
"CARD %d xpd_type=%d/hw_type=%d ports=%d (%dx%d), "
|
2012-01-12 03:56:35 +08:00
|
|
|
"%d subunits, port-dir=0x%02X\n",
|
2015-11-17 04:42:21 +08:00
|
|
|
unit, xpd_type, hw_type, ports, numchips, ports_per_chip, subunits,
|
2012-01-12 03:56:35 +08:00
|
|
|
port_dir);
|
2015-11-17 04:42:21 +08:00
|
|
|
if (xpd_type == XPD_TYPE_PRI || xpd_type == XPD_TYPE_BRI)
|
2011-07-04 22:04:33 +08:00
|
|
|
xbus->quirks.has_digital_span = 1;
|
2015-11-17 04:42:21 +08:00
|
|
|
if (xpd_type == XPD_TYPE_FXO)
|
2011-07-04 22:04:33 +08:00
|
|
|
xbus->quirks.has_fxo = 1;
|
2010-08-28 05:59:27 +08:00
|
|
|
xbus->worker.num_units += subunits - 1;
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < subunits; i++) {
|
2012-01-11 23:22:46 +08:00
|
|
|
int subunit_ports = proto_table->ports_per_subunit;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (subunit_ports > remaining_ports)
|
2010-08-28 05:59:27 +08:00
|
|
|
subunit_ports = remaining_ports;
|
|
|
|
remaining_ports -= proto_table->ports_per_subunit;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (subunit_ports <= 0) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_NOTICE(xbus,
|
2012-01-12 03:56:35 +08:00
|
|
|
"Subunit XPD=%d%d without ports (%d of %d)\n",
|
|
|
|
unit, i, subunit_ports, ports);
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!XBUS_IS(xbus, RECVD_DESC)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_NOTICE(xbus,
|
2012-01-11 23:22:46 +08:00
|
|
|
"Cannot create XPD=%d%d in state %s\n",
|
|
|
|
unit, i, xbus_statename(XBUS_STATE(xbus)));
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_DBG(DEVICES, xbus,
|
2015-11-17 04:42:21 +08:00
|
|
|
"Creating XPD=%d%d xpd_type=%d.%d hw_type=%d (%d ports)\n", unit, i,
|
|
|
|
xpd_type, unit_descriptor->subtype, hw_type, subunit_ports);
|
2012-01-11 23:22:46 +08:00
|
|
|
ret =
|
2015-11-17 04:42:21 +08:00
|
|
|
create_xpd(xbus, proto_table, unit_descriptor, unit, i, xpd_type);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (ret < 0) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_ERR(xbus, "Creation of XPD=%d%d failed %d\n", unit,
|
|
|
|
i, ret);
|
2010-08-28 05:59:27 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
xbus->worker.num_units_initialized++;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
xproto_put(proto_table); /* ref count is inside the xpds now */
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xbus_release_xpds(xbus_t *xbus)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
XBUS_DBG(DEVICES, xbus, "[%s] Release XPDS\n", xbus->label);
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < MAX_XPDS; i++) {
|
2010-08-28 05:59:27 +08:00
|
|
|
xpd_t *xpd = xpd_of(xbus, i);
|
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xpd)
|
2010-08-28 05:59:27 +08:00
|
|
|
put_xpd(__func__, xpd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xbus_aquire_xpds(xbus_t *xbus)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
unsigned long flags;
|
|
|
|
int i;
|
|
|
|
int ret = 0;
|
|
|
|
xpd_t *xpd;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
XBUS_DBG(DEVICES, xbus, "[%s] Aquire XPDS\n", xbus->label);
|
|
|
|
spin_lock_irqsave(&xbus->lock, flags);
|
|
|
|
for (i = 0; i < MAX_XPDS; i++) {
|
|
|
|
xpd = xpd_of(xbus, i);
|
|
|
|
if (xpd) {
|
|
|
|
xpd = get_xpd(__func__, xpd);
|
|
|
|
if (!xpd)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
spin_unlock_irqrestore(&xbus->lock, flags);
|
|
|
|
return ret;
|
|
|
|
err:
|
2012-01-11 23:22:46 +08:00
|
|
|
for (--i; i >= 0; i--) {
|
2010-08-28 05:59:27 +08:00
|
|
|
xpd = xpd_of(xbus, i);
|
|
|
|
if (xpd)
|
|
|
|
put_xpd(__func__, xpd);
|
|
|
|
}
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xpd_initialize(xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int ret = -ENODEV;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (CALL_XMETHOD(card_init, xpd) < 0) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_ERR(xpd, "Card Initialization failed\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
xpd->card_present = 1;
|
2011-01-30 22:13:22 +08:00
|
|
|
if (IS_PHONEDEV(xpd)) {
|
2011-06-29 02:23:00 +08:00
|
|
|
/*
|
|
|
|
* Set echo canceler channels (off)
|
|
|
|
* Asterisk will tell us when/if it's needed.
|
|
|
|
*/
|
|
|
|
CALL_PHONE_METHOD(echocancel_setmask, xpd, 0);
|
2012-01-12 03:56:35 +08:00
|
|
|
/* Turn on all channels */
|
|
|
|
CALL_PHONE_METHOD(card_state, xpd, 1);
|
2011-01-30 22:13:22 +08:00
|
|
|
}
|
2012-01-13 01:14:15 +08:00
|
|
|
if (!xpd_setstate(xpd, XPD_STATE_READY))
|
2010-08-28 05:59:27 +08:00
|
|
|
goto out;
|
|
|
|
XPD_INFO(xpd, "Initialized: %s\n", xpd->type_name);
|
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-06-29 02:23:00 +08:00
|
|
|
static int xbus_echocancel(xbus_t *xbus, int on)
|
|
|
|
{
|
|
|
|
int unit;
|
|
|
|
int subunit;
|
|
|
|
xpd_t *xpd;
|
|
|
|
|
|
|
|
if (!ECHOOPS(xbus))
|
|
|
|
return 0;
|
|
|
|
for (unit = 0; unit < MAX_UNIT; unit++) {
|
|
|
|
xpd = xpd_byaddr(xbus, unit, 0);
|
|
|
|
if (!xpd || !IS_PHONEDEV(xpd))
|
|
|
|
continue;
|
|
|
|
for (subunit = 0; subunit < MAX_SUBUNIT; subunit++) {
|
2012-01-11 23:22:46 +08:00
|
|
|
int ret;
|
2011-06-29 02:23:00 +08:00
|
|
|
|
|
|
|
xpd = xpd_byaddr(xbus, unit, subunit);
|
|
|
|
if (!xpd || !IS_PHONEDEV(xpd))
|
|
|
|
continue;
|
|
|
|
ret = echocancel_xpd(xpd, on);
|
|
|
|
if (ret < 0) {
|
|
|
|
XPD_ERR(xpd, "Fail in xbus_echocancel()\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-06 01:34:16 +08:00
|
|
|
static void xbus_deactivate_xpds(xbus_t *xbus)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int unit;
|
|
|
|
int subunit;
|
|
|
|
xpd_t *xpd;
|
|
|
|
|
|
|
|
for (unit = 0; unit < MAX_UNIT; unit++) {
|
|
|
|
xpd = xpd_byaddr(xbus, unit, 0);
|
|
|
|
if (!xpd)
|
|
|
|
continue;
|
|
|
|
for (subunit = 0; subunit < MAX_SUBUNIT; subunit++) {
|
|
|
|
xpd = xpd_byaddr(xbus, unit, subunit);
|
|
|
|
if (!xpd)
|
|
|
|
continue;
|
|
|
|
spin_lock_irqsave(&xpd->lock, flags);
|
|
|
|
xpd->card_present = 0;
|
|
|
|
xpd_setstate(xpd, XPD_STATE_NOHW);
|
|
|
|
spin_unlock_irqrestore(&xpd->lock, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
static int xbus_initialize(xbus_t *xbus)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int unit;
|
|
|
|
int subunit;
|
|
|
|
xpd_t *xpd;
|
|
|
|
struct timeval time_start;
|
|
|
|
struct timeval time_end;
|
|
|
|
unsigned long timediff;
|
|
|
|
int res = 0;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
do_gettimeofday(&time_start);
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_DBG(DEVICES, xbus, "refcount_xbus=%d\n", refcount_xbus(xbus));
|
2010-08-28 05:59:27 +08:00
|
|
|
if (xbus_aquire_xpds(xbus) < 0) /* Until end of initialization */
|
|
|
|
return -EBUSY;
|
2012-01-11 23:20:05 +08:00
|
|
|
for (unit = 0; unit < MAX_UNIT; unit++) {
|
2010-08-28 05:59:27 +08:00
|
|
|
xpd = xpd_byaddr(xbus, unit, 0);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd)
|
2010-08-28 05:59:27 +08:00
|
|
|
continue;
|
|
|
|
if (!XBUS_IS(xbus, RECVD_DESC)) {
|
|
|
|
XBUS_NOTICE(xbus,
|
2012-01-11 23:22:46 +08:00
|
|
|
"Cannot initialize UNIT=%d in state %s\n",
|
|
|
|
unit, xbus_statename(XBUS_STATE(xbus)));
|
2010-08-28 05:59:27 +08:00
|
|
|
goto err;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (run_initialize_registers(xpd) < 0) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_ERR(xbus,
|
|
|
|
"Register Initialization of card #%d failed\n",
|
|
|
|
unit);
|
2010-08-28 05:59:27 +08:00
|
|
|
goto err;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
for (subunit = 0; subunit < MAX_SUBUNIT; subunit++) {
|
2012-01-11 23:22:46 +08:00
|
|
|
int ret;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
xpd = xpd_byaddr(xbus, unit, subunit);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd)
|
2010-08-28 05:59:27 +08:00
|
|
|
continue;
|
|
|
|
if (!XBUS_IS(xbus, RECVD_DESC)) {
|
|
|
|
XBUS_ERR(xbus,
|
2012-01-11 23:22:46 +08:00
|
|
|
"XPD-%d%d Not in 'RECVD_DESC' state\n",
|
|
|
|
unit, subunit);
|
2010-08-28 05:59:27 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
ret = xpd_initialize(xpd);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (ret < 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
2011-06-29 02:23:00 +08:00
|
|
|
xbus_echocancel(xbus, 1);
|
2010-08-28 05:59:27 +08:00
|
|
|
do_gettimeofday(&time_end);
|
|
|
|
timediff = usec_diff(&time_end, &time_start);
|
2012-01-11 23:22:46 +08:00
|
|
|
timediff /= 1000 * 100;
|
|
|
|
XBUS_INFO(xbus, "Initialized in %ld.%1ld sec\n", timediff / 10,
|
|
|
|
timediff % 10);
|
2010-08-28 05:59:27 +08:00
|
|
|
out:
|
|
|
|
xbus_release_xpds(xbus); /* Initialization done/failed */
|
|
|
|
return res;
|
|
|
|
err:
|
|
|
|
xbus_setstate(xbus, XBUS_STATE_FAIL);
|
|
|
|
res = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
int xbus_is_registered(xbus_t *xbus)
|
2011-11-11 00:56:29 +08:00
|
|
|
{
|
|
|
|
return xbus->ddev && xbus->ddev->dev.parent;
|
|
|
|
}
|
|
|
|
|
2012-01-06 01:35:17 +08:00
|
|
|
static void xbus_free_ddev(xbus_t *xbus)
|
|
|
|
{
|
|
|
|
if (!xbus->ddev)
|
|
|
|
return;
|
2012-01-13 01:13:41 +08:00
|
|
|
kfree(xbus->ddev->devicetype); /* NULL is safe */
|
2012-01-06 01:35:17 +08:00
|
|
|
xbus->ddev->devicetype = NULL;
|
|
|
|
xbus->ddev->location = NULL;
|
|
|
|
xbus->ddev->hardware_id = NULL;
|
|
|
|
dahdi_free_device(xbus->ddev);
|
|
|
|
xbus->ddev = NULL;
|
|
|
|
}
|
|
|
|
|
2013-09-29 19:20:38 +08:00
|
|
|
static DEFINE_MUTEX(dahdi_registration_mutex);
|
|
|
|
|
2011-11-11 00:56:29 +08:00
|
|
|
int xbus_register_dahdi_device(xbus_t *xbus)
|
2011-10-27 02:58:14 +08:00
|
|
|
{
|
2012-01-06 01:35:17 +08:00
|
|
|
int i;
|
|
|
|
int offset = 0;
|
|
|
|
int ret;
|
2011-10-27 02:58:14 +08:00
|
|
|
|
2011-10-27 03:09:09 +08:00
|
|
|
XBUS_DBG(DEVICES, xbus, "Entering %s\n", __func__);
|
2013-09-29 19:20:38 +08:00
|
|
|
ret = mutex_lock_interruptible(&dahdi_registration_mutex);
|
|
|
|
if (ret < 0) {
|
|
|
|
XBUS_ERR(xbus, "dahdi_registration_mutex already taken\n");
|
|
|
|
goto err;
|
|
|
|
}
|
2011-11-11 00:56:29 +08:00
|
|
|
if (xbus_is_registered(xbus)) {
|
2014-03-17 23:55:29 +08:00
|
|
|
/*
|
|
|
|
* Ignore duplicate registrations (from dahdi_registration)
|
|
|
|
* Until we completely migrate to dahdi_autoreg=1 and
|
|
|
|
* hotplug-based span-assignments
|
|
|
|
*/
|
|
|
|
XBUS_DBG(DEVICES, xbus, "Already registered to DAHDI\n");
|
|
|
|
ret = 0;
|
|
|
|
goto out;
|
2011-11-11 00:56:29 +08:00
|
|
|
}
|
2011-10-27 02:58:14 +08:00
|
|
|
xbus->ddev = dahdi_create_device();
|
2012-01-06 01:35:17 +08:00
|
|
|
if (!xbus->ddev) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
2011-10-27 02:58:14 +08:00
|
|
|
/*
|
|
|
|
* This actually describe the dahdi_spaninfo version 3
|
|
|
|
* A bunch of unrelated data exported via a modified ioctl()
|
|
|
|
* What a bummer...
|
|
|
|
*/
|
|
|
|
xbus->ddev->manufacturer = "Xorcom Inc."; /* OK, that's obvious */
|
|
|
|
/* span->spantype = "...."; set in card_dahdi_preregistration() */
|
|
|
|
/*
|
|
|
|
* Yes, this basically duplicates information available
|
|
|
|
* from the description field. If some more is needed
|
|
|
|
* why not add it there?
|
|
|
|
* OK, let's add to the kernel more useless info.
|
|
|
|
*/
|
|
|
|
xbus->ddev->devicetype = kasprintf(GFP_KERNEL, "Astribank2");
|
2012-01-06 01:35:17 +08:00
|
|
|
if (!xbus->ddev->devicetype) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
2011-10-27 02:58:14 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* location is the only usefull new data item.
|
|
|
|
* For our devices it was available for ages via:
|
|
|
|
* - The legacy "/proc/xpp/XBUS-??/summary" (CONNECTOR=...)
|
|
|
|
* - The same info in "/proc/xpp/xbuses"
|
2012-01-12 03:56:35 +08:00
|
|
|
* - The modern "/sys/bus/astribanks/devices/xbus-??/connector"
|
|
|
|
* attribute
|
2011-10-27 02:58:14 +08:00
|
|
|
* So let's also export it via the newfangled "location" field.
|
|
|
|
*/
|
|
|
|
xbus->ddev->location = xbus->connector;
|
2011-10-27 02:59:20 +08:00
|
|
|
xbus->ddev->hardware_id = xbus->label;
|
2011-10-27 02:58:14 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare the span list
|
|
|
|
*/
|
|
|
|
for (i = 0; i < MAX_XPDS; i++) {
|
|
|
|
xpd_t *xpd = xpd_of(xbus, i);
|
|
|
|
if (xpd && IS_PHONEDEV(xpd)) {
|
|
|
|
XPD_DBG(DEVICES, xpd, "offset=%d\n", offset);
|
|
|
|
xpd_dahdi_preregister(xpd, offset++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dahdi_register_device(xbus->ddev, &xbus->astribank)) {
|
|
|
|
XBUS_ERR(xbus, "Failed to dahdi_register_device()\n");
|
2012-01-06 01:35:17 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto err;
|
2011-10-27 02:58:14 +08:00
|
|
|
}
|
|
|
|
for (i = 0; i < MAX_XPDS; i++) {
|
|
|
|
xpd_t *xpd = xpd_of(xbus, i);
|
|
|
|
if (xpd && IS_PHONEDEV(xpd)) {
|
|
|
|
XPD_DBG(DEVICES, xpd, "\n");
|
|
|
|
xpd_dahdi_postregister(xpd);
|
|
|
|
}
|
|
|
|
}
|
2013-09-29 19:20:38 +08:00
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
mutex_unlock(&dahdi_registration_mutex);
|
|
|
|
return ret;
|
2012-01-06 01:35:17 +08:00
|
|
|
err:
|
|
|
|
xbus_free_ddev(xbus);
|
2013-09-29 19:20:38 +08:00
|
|
|
goto out;
|
2011-10-27 02:58:14 +08:00
|
|
|
}
|
|
|
|
|
2011-11-11 00:56:29 +08:00
|
|
|
void xbus_unregister_dahdi_device(xbus_t *xbus)
|
2011-10-27 02:58:14 +08:00
|
|
|
{
|
|
|
|
int i;
|
2013-09-29 19:20:38 +08:00
|
|
|
int ret;
|
2011-10-27 02:58:14 +08:00
|
|
|
|
2014-05-12 23:36:16 +08:00
|
|
|
XBUS_DBG(DEVICES, xbus, "%s\n", __func__);
|
2013-09-29 19:20:38 +08:00
|
|
|
ret = mutex_lock_interruptible(&dahdi_registration_mutex);
|
|
|
|
if (ret < 0) {
|
|
|
|
XBUS_ERR(xbus, "dahdi_registration_mutex already taken\n");
|
|
|
|
return;
|
|
|
|
}
|
2014-04-07 02:01:55 +08:00
|
|
|
if (!xbus_is_registered(xbus)) {
|
|
|
|
/*
|
|
|
|
* Ignore duplicate unregistrations
|
|
|
|
*/
|
|
|
|
XBUS_DBG(DEVICES, xbus, "Already unregistered to DAHDI\n");
|
|
|
|
goto err;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < MAX_XPDS; i++) {
|
2011-10-27 02:58:14 +08:00
|
|
|
xpd_t *xpd = xpd_of(xbus, i);
|
|
|
|
xpd_dahdi_preunregister(xpd);
|
|
|
|
}
|
2011-10-27 03:06:32 +08:00
|
|
|
if (xbus->ddev) {
|
|
|
|
dahdi_unregister_device(xbus->ddev);
|
2014-05-12 23:36:16 +08:00
|
|
|
XBUS_DBG(DEVICES, xbus,
|
|
|
|
"%s: finished dahdi_unregister_device()\n", __func__);
|
2012-01-06 01:35:17 +08:00
|
|
|
xbus_free_ddev(xbus);
|
2011-10-27 03:06:32 +08:00
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < MAX_XPDS; i++) {
|
2011-10-27 02:58:14 +08:00
|
|
|
xpd_t *xpd = xpd_of(xbus, i);
|
|
|
|
xpd_dahdi_postunregister(xpd);
|
|
|
|
}
|
2014-04-07 02:01:55 +08:00
|
|
|
err:
|
2013-09-29 19:20:38 +08:00
|
|
|
mutex_unlock(&dahdi_registration_mutex);
|
2011-10-27 02:58:14 +08:00
|
|
|
}
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* This must be called from synchronous (non-interrupt) context
|
|
|
|
* it returns only when all XPD's on the bus are detected and
|
|
|
|
* initialized.
|
|
|
|
*/
|
2012-01-11 23:21:13 +08:00
|
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
|
2010-08-28 05:59:27 +08:00
|
|
|
static void xbus_populate(struct work_struct *work)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct xbus_workqueue *worker =
|
|
|
|
container_of(work, struct xbus_workqueue, xpds_init_work);
|
2010-08-28 05:59:27 +08:00
|
|
|
#else
|
|
|
|
void xbus_populate(void *data)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct xbus_workqueue *worker = data;
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_t *xbus;
|
|
|
|
struct list_head *card;
|
|
|
|
struct list_head *next_card;
|
|
|
|
unsigned long flags;
|
|
|
|
int ret = 0;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
xbus = container_of(worker, xbus_t, worker);
|
|
|
|
xbus = get_xbus(__func__, xbus->num); /* return in function end */
|
2012-01-11 23:17:09 +08:00
|
|
|
XBUS_DBG(DEVICES, xbus, "Entering %s\n", __func__);
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_lock_irqsave(&worker->worker_lock, flags);
|
|
|
|
list_for_each_safe(card, next_card, &worker->card_list) {
|
2012-01-11 23:22:46 +08:00
|
|
|
struct card_desc_struct *card_desc =
|
|
|
|
list_entry(card, struct card_desc_struct, card_list);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
list_del(card);
|
|
|
|
BUG_ON(card_desc->magic != CARD_DESC_MAGIC);
|
|
|
|
/* Release/Reacquire locks around blocking calls */
|
|
|
|
spin_unlock_irqrestore(&xbus->worker.worker_lock, flags);
|
2015-11-17 04:42:21 +08:00
|
|
|
ret = new_card(xbus, &card_desc->unit_descriptor);
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_lock_irqsave(&xbus->worker.worker_lock, flags);
|
|
|
|
KZFREE(card_desc);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (ret)
|
2010-08-28 05:59:27 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&worker->worker_lock, flags);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xbus_initialize(xbus) < 0) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_NOTICE(xbus,
|
2012-01-12 03:56:35 +08:00
|
|
|
"Initialization failed. Leave unused. "
|
|
|
|
"refcount_xbus=%d\n",
|
|
|
|
refcount_xbus(xbus));
|
2010-08-28 05:59:27 +08:00
|
|
|
goto failed;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xbus_setstate(xbus, XBUS_STATE_READY)) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_NOTICE(xbus,
|
2012-01-12 03:56:35 +08:00
|
|
|
"Illegal transition. Leave unused. refcount_xbus=%d\n",
|
|
|
|
refcount_xbus(xbus));
|
2010-08-28 05:59:27 +08:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
worker->xpds_init_done = 1;
|
|
|
|
/*
|
|
|
|
* Now request Astribank to start self_ticking.
|
|
|
|
* This is the last initialization command. So
|
|
|
|
* all others will reach the device before it.
|
|
|
|
*/
|
|
|
|
xbus_request_sync(xbus, SYNC_MODE_PLL);
|
|
|
|
elect_syncer("xbus_populate(end)"); /* FIXME: try to do it later */
|
2014-01-29 03:27:50 +08:00
|
|
|
if (!dahdi_get_auto_assign_spans())
|
2011-11-11 00:56:29 +08:00
|
|
|
xbus_register_dahdi_device(xbus);
|
2010-08-28 05:59:27 +08:00
|
|
|
out:
|
|
|
|
XBUS_DBG(DEVICES, xbus, "Leaving\n");
|
|
|
|
wake_up_interruptible_all(&worker->wait_for_xpd_initialization);
|
|
|
|
XBUS_DBG(DEVICES, xbus, "populate release\n");
|
|
|
|
up(&worker->running_initialization);
|
|
|
|
put_xbus(__func__, xbus); /* taken at function entry */
|
|
|
|
return;
|
|
|
|
failed:
|
|
|
|
xbus_setstate(xbus, XBUS_STATE_FAIL);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xbus_process_worker(xbus_t *xbus)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct xbus_workqueue *worker;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xbus) {
|
2012-01-11 23:17:09 +08:00
|
|
|
ERR("%s: xbus gone -- skip initialization\n", __func__);
|
2010-08-28 05:59:27 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
worker = &xbus->worker;
|
|
|
|
if (down_trylock(&worker->running_initialization)) {
|
2012-01-11 23:22:46 +08:00
|
|
|
ERR("%s: xbus is disconnected -- skip initialization\n",
|
|
|
|
__func__);
|
2010-08-28 05:59:27 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
XBUS_DBG(DEVICES, xbus, "\n");
|
|
|
|
/* Initialize the work. (adapt to kernel API changes). */
|
2012-01-11 23:21:13 +08:00
|
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
|
2010-08-28 05:59:27 +08:00
|
|
|
INIT_WORK(&worker->xpds_init_work, xbus_populate);
|
|
|
|
#else
|
|
|
|
INIT_WORK(&worker->xpds_init_work, xbus_populate, worker);
|
|
|
|
#endif
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
/* Now send it */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!queue_work(worker->wq, &worker->xpds_init_work)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_ERR(xbus, "Failed to queue xpd initialization work\n");
|
|
|
|
up(&worker->running_initialization);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void worker_reset(xbus_t *xbus)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct xbus_workqueue *worker;
|
|
|
|
struct list_head *card;
|
|
|
|
struct list_head *next_card;
|
|
|
|
unsigned long flags;
|
|
|
|
char *name;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
worker = &xbus->worker;
|
|
|
|
name = (xbus) ? xbus->busname : "detached";
|
|
|
|
DBG(DEVICES, "%s\n", name);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!worker->xpds_init_done) {
|
2014-05-12 23:36:16 +08:00
|
|
|
XBUS_NOTICE(xbus, "XPDS initialization was not finished\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
spin_lock_irqsave(&worker->worker_lock, flags);
|
|
|
|
list_for_each_safe(card, next_card, &worker->card_list) {
|
2012-01-11 23:22:46 +08:00
|
|
|
struct card_desc_struct *card_desc =
|
|
|
|
list_entry(card, struct card_desc_struct, card_list);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(card_desc->magic != CARD_DESC_MAGIC);
|
|
|
|
list_del(card);
|
|
|
|
KZFREE(card_desc);
|
|
|
|
}
|
|
|
|
worker->xpds_init_done = 0;
|
|
|
|
worker->num_units = 0;
|
|
|
|
worker->num_units_initialized = 0;
|
|
|
|
wake_up_interruptible_all(&worker->wait_for_xpd_initialization);
|
|
|
|
spin_unlock_irqrestore(&worker->worker_lock, flags);
|
|
|
|
}
|
|
|
|
|
2014-05-12 23:36:16 +08:00
|
|
|
/*
|
|
|
|
* Called only after worker_reset(xbus)
|
|
|
|
*/
|
2010-08-28 05:59:27 +08:00
|
|
|
static void worker_destroy(xbus_t *xbus)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct xbus_workqueue *worker;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
worker = &xbus->worker;
|
|
|
|
XBUS_DBG(DEVICES, xbus, "Waiting for worker to finish...\n");
|
|
|
|
down(&worker->running_initialization);
|
|
|
|
XBUS_DBG(DEVICES, xbus, "Waiting for worker to finish -- done\n");
|
|
|
|
if (worker->wq) {
|
|
|
|
XBUS_DBG(DEVICES, xbus, "destroying workqueue...\n");
|
|
|
|
flush_workqueue(worker->wq);
|
|
|
|
destroy_workqueue(worker->wq);
|
|
|
|
worker->wq = NULL;
|
|
|
|
XBUS_DBG(DEVICES, xbus, "destroying workqueue -- done\n");
|
|
|
|
}
|
|
|
|
XBUS_DBG(DEVICES, xbus, "detach worker\n");
|
|
|
|
put_xbus(__func__, xbus); /* got from worker_run() */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void worker_init(xbus_t *xbus)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct xbus_workqueue *worker;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
XBUS_DBG(DEVICES, xbus, "\n");
|
|
|
|
worker = &xbus->worker;
|
|
|
|
/* poll related variables */
|
|
|
|
spin_lock_init(&worker->worker_lock);
|
|
|
|
INIT_LIST_HEAD(&worker->card_list);
|
|
|
|
init_waitqueue_head(&worker->wait_for_xpd_initialization);
|
|
|
|
worker->wq = NULL;
|
2010-11-05 00:40:29 +08:00
|
|
|
sema_init(&xbus->worker.running_initialization, 1);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a worker for the xbus including the nessessary workqueue.
|
|
|
|
* May call blocking operations, but only briefly (as we are called
|
|
|
|
* from xbus_new() which is called from khubd.
|
|
|
|
*/
|
|
|
|
static int worker_run(xbus_t *xbus)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct xbus_workqueue *worker;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
xbus = get_xbus(__func__, xbus->num); /* return in worker_destroy() */
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
BUG_ON(xbus->busname[0] == '\0'); /* No name? */
|
|
|
|
worker = &xbus->worker;
|
|
|
|
BUG_ON(worker->wq); /* Hmmm... nested workers? */
|
|
|
|
XBUS_DBG(DEVICES, xbus, "\n");
|
|
|
|
/* poll related variables */
|
|
|
|
worker->wq = create_singlethread_workqueue(xbus->busname);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!worker->wq) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_ERR(xbus, "Failed to create worker workqueue.\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
err:
|
2014-05-12 23:36:16 +08:00
|
|
|
worker_reset(xbus);
|
2010-08-28 05:59:27 +08:00
|
|
|
worker_destroy(xbus);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool xbus_setflags(xbus_t *xbus, int flagbit, bool on)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
unsigned long flags;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&xbus->transport.state_lock, flags);
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_DBG(DEVICES, xbus, "%s flag %d\n", (on) ? "Set" : "Clear",
|
|
|
|
flagbit);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (on)
|
2010-08-28 05:59:27 +08:00
|
|
|
set_bit(flagbit, &(xbus->transport.transport_flags));
|
|
|
|
else
|
|
|
|
clear_bit(flagbit, &(xbus->transport.transport_flags));
|
|
|
|
spin_unlock_irqrestore(&xbus->transport.state_lock, flags);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool xbus_setstate(xbus_t *xbus, enum xbus_state newstate)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
unsigned long flags;
|
|
|
|
bool ret = 0;
|
|
|
|
int state_flip = 0;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&xbus->transport.state_lock, flags);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (newstate == XBUS_STATE(xbus)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_DBG(DEVICES, xbus, "stay at %s\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_statename(newstate));
|
2010-08-28 05:59:27 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/* Sanity tests */
|
2012-01-11 23:20:05 +08:00
|
|
|
switch (newstate) {
|
2012-01-11 23:22:46 +08:00
|
|
|
case XBUS_STATE_START:
|
|
|
|
goto bad_state;
|
|
|
|
case XBUS_STATE_IDLE:
|
|
|
|
if (!XBUS_IS(xbus, START) && !XBUS_IS(xbus, DEACTIVATED))
|
2010-08-28 05:59:27 +08:00
|
|
|
goto bad_state;
|
2012-01-11 23:22:46 +08:00
|
|
|
break;
|
|
|
|
case XBUS_STATE_SENT_REQUEST:
|
|
|
|
if (!XBUS_IS(xbus, IDLE) && !XBUS_IS(xbus, SENT_REQUEST))
|
|
|
|
goto bad_state;
|
|
|
|
break;
|
|
|
|
case XBUS_STATE_RECVD_DESC:
|
|
|
|
if (!XBUS_IS(xbus, SENT_REQUEST))
|
|
|
|
goto bad_state;
|
|
|
|
break;
|
|
|
|
case XBUS_STATE_READY:
|
|
|
|
if (!XBUS_IS(xbus, RECVD_DESC))
|
|
|
|
goto bad_state;
|
|
|
|
state_flip = 1; /* We are good */
|
|
|
|
break;
|
|
|
|
case XBUS_STATE_DEACTIVATING:
|
|
|
|
if (XBUS_IS(xbus, DEACTIVATING))
|
|
|
|
goto bad_state;
|
|
|
|
if (XBUS_IS(xbus, DEACTIVATED))
|
|
|
|
goto bad_state;
|
|
|
|
break;
|
|
|
|
case XBUS_STATE_DEACTIVATED:
|
|
|
|
if (!XBUS_IS(xbus, DEACTIVATING))
|
|
|
|
goto bad_state;
|
|
|
|
break;
|
|
|
|
case XBUS_STATE_FAIL:
|
|
|
|
if (XBUS_IS(xbus, DEACTIVATING))
|
|
|
|
goto bad_state;
|
|
|
|
if (XBUS_IS(xbus, DEACTIVATED))
|
|
|
|
goto bad_state;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
XBUS_NOTICE(xbus, "%s: unknown state %d\n", __func__, newstate);
|
|
|
|
goto out;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
/* All good */
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_DBG(DEVICES, xbus, "%s -> %s\n", xbus_statename(XBUS_STATE(xbus)),
|
|
|
|
xbus_statename(newstate));
|
|
|
|
if (xbus->transport.xbus_state == XBUS_STATE_READY
|
|
|
|
&& newstate != XBUS_STATE_READY)
|
2010-08-28 05:59:27 +08:00
|
|
|
state_flip = -1; /* We became bad */
|
|
|
|
xbus->transport.xbus_state = newstate;
|
|
|
|
ret = 1;
|
|
|
|
out:
|
|
|
|
spin_unlock_irqrestore(&xbus->transport.state_lock, flags);
|
|
|
|
/* Should be sent out of spinlocks */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (state_flip > 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
astribank_uevent_send(xbus, KOBJ_ONLINE);
|
2012-01-11 23:20:05 +08:00
|
|
|
else if (state_flip < 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
astribank_uevent_send(xbus, KOBJ_OFFLINE);
|
|
|
|
return ret;
|
|
|
|
bad_state:
|
|
|
|
XBUS_NOTICE(xbus, "Bad state transition %s -> %s ignored.\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_statename(XBUS_STATE(xbus)), xbus_statename(newstate));
|
2010-08-28 05:59:27 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xbus_setstate);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
int xbus_activate(xbus_t *xbus)
|
|
|
|
{
|
|
|
|
XBUS_INFO(xbus, "[%s] Activating\n", xbus->label);
|
|
|
|
xpp_drift_init(xbus);
|
|
|
|
xbus_set_command_timer(xbus, 1);
|
|
|
|
xframe_queue_disable(&xbus->command_queue, 0);
|
2012-01-12 03:56:35 +08:00
|
|
|
/* must be done after transport is valid */
|
|
|
|
xbus_setstate(xbus, XBUS_STATE_IDLE);
|
2010-08-28 05:59:27 +08:00
|
|
|
CALL_PROTO(GLOBAL, AB_REQUEST, xbus, NULL);
|
|
|
|
/*
|
|
|
|
* Make sure Astribank knows not to send us ticks.
|
|
|
|
*/
|
|
|
|
xbus_request_sync(xbus, SYNC_MODE_NONE);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xbus_activate);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
int xbus_connect(xbus_t *xbus)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct xbus_ops *ops;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
XBUS_DBG(DEVICES, xbus, "\n");
|
|
|
|
ops = transportops_get(xbus);
|
|
|
|
BUG_ON(!ops);
|
|
|
|
/* Sanity checks */
|
|
|
|
BUG_ON(!ops->xframe_send_pcm);
|
|
|
|
BUG_ON(!ops->xframe_send_cmd);
|
|
|
|
BUG_ON(!ops->alloc_xframe);
|
|
|
|
BUG_ON(!ops->free_xframe);
|
|
|
|
xbus_setflags(xbus, XBUS_FLAG_CONNECTED, 1);
|
|
|
|
xbus_activate(xbus);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xbus_connect);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
void xbus_deactivate(xbus_t *xbus)
|
|
|
|
{
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
XBUS_INFO(xbus, "[%s] Deactivating\n", xbus->label);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xbus_setstate(xbus, XBUS_STATE_DEACTIVATING))
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
xbus_request_sync(xbus, SYNC_MODE_NONE); /* no more ticks */
|
|
|
|
elect_syncer("deactivate");
|
2011-06-29 02:23:00 +08:00
|
|
|
xbus_echocancel(xbus, 0);
|
2012-01-06 01:34:16 +08:00
|
|
|
xbus_deactivate_xpds(xbus);
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_DBG(DEVICES, xbus, "[%s] Waiting for queues\n", xbus->label);
|
|
|
|
xbus_command_queue_clean(xbus);
|
|
|
|
xbus_command_queue_waitempty(xbus);
|
|
|
|
xbus_setstate(xbus, XBUS_STATE_DEACTIVATED);
|
|
|
|
worker_reset(xbus);
|
2011-10-27 02:58:14 +08:00
|
|
|
xbus_unregister_dahdi_device(xbus);
|
2010-08-28 05:59:27 +08:00
|
|
|
xbus_release_xpds(xbus); /* taken in xpd_alloc() [kref_init] */
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xbus_deactivate);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
void xbus_disconnect(xbus_t *xbus)
|
|
|
|
{
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
XBUS_INFO(xbus, "[%s] Disconnecting\n", xbus->label);
|
|
|
|
xbus_setflags(xbus, XBUS_FLAG_CONNECTED, 0);
|
|
|
|
xbus_deactivate(xbus);
|
|
|
|
xbus_command_queue_clean(xbus);
|
|
|
|
xbus_command_queue_waitempty(xbus);
|
|
|
|
tasklet_kill(&xbus->receive_tasklet);
|
|
|
|
xframe_queue_clear(&xbus->receive_queue);
|
|
|
|
xframe_queue_clear(&xbus->send_pool);
|
|
|
|
xframe_queue_clear(&xbus->receive_pool);
|
|
|
|
xframe_queue_clear(&xbus->pcm_tospan);
|
|
|
|
del_timer_sync(&xbus->command_timer);
|
|
|
|
transportops_put(xbus);
|
|
|
|
transport_destroy(xbus);
|
2014-05-12 23:36:16 +08:00
|
|
|
/* worker_reset(xbus) was called in xbus_deactivate(xbus) */
|
2010-08-28 05:59:27 +08:00
|
|
|
worker_destroy(xbus);
|
|
|
|
XBUS_DBG(DEVICES, xbus, "Deactivated refcount_xbus=%d\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
refcount_xbus(xbus));
|
2010-08-28 05:59:27 +08:00
|
|
|
xbus_sysfs_transport_remove(xbus); /* Device-Model */
|
|
|
|
put_xbus(__func__, xbus); /* from xbus_new() [kref_init()] */
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xbus_disconnect);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
static xbus_t *xbus_alloc(void)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
unsigned long flags;
|
|
|
|
xbus_t *xbus;
|
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
xbus = KZALLOC(sizeof(xbus_t), GFP_KERNEL);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xbus) {
|
2012-01-11 23:17:09 +08:00
|
|
|
ERR("%s: out of memory\n", __func__);
|
2010-08-28 05:59:27 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
spin_lock_irqsave(&xbuses_lock, flags);
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < MAX_BUSES; i++)
|
|
|
|
if (xbuses_array[i].xbus == NULL)
|
2010-08-28 05:59:27 +08:00
|
|
|
break;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (i >= MAX_BUSES) {
|
2012-01-11 23:17:09 +08:00
|
|
|
ERR("%s: No free slot for new bus. i=%d\n", __func__, i);
|
2010-08-28 05:59:27 +08:00
|
|
|
KZFREE(xbus);
|
|
|
|
xbus = NULL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/* Found empty slot */
|
|
|
|
xbus->num = i;
|
|
|
|
init_xbus(i, xbus);
|
|
|
|
out:
|
|
|
|
spin_unlock_irqrestore(&xbuses_lock, flags);
|
|
|
|
return xbus;
|
|
|
|
}
|
|
|
|
|
|
|
|
void xbus_free(xbus_t *xbus)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
unsigned long flags;
|
|
|
|
uint num;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xbus)
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
XBUS_DBG(DEVICES, xbus, "Free\n");
|
|
|
|
spin_lock_irqsave(&xbuses_lock, flags);
|
|
|
|
num = xbus->num;
|
|
|
|
BUG_ON(!xbuses_array[num].xbus);
|
|
|
|
BUG_ON(xbus != xbuses_array[num].xbus);
|
2014-05-12 22:51:59 +08:00
|
|
|
init_xbus(num, NULL);
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_unlock_irqrestore(&xbuses_lock, flags);
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xbus->proc_xbus_dir) {
|
|
|
|
if (xbus->proc_xbus_summary) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_DBG(PROC, xbus, "Removing proc '%s'\n",
|
|
|
|
PROC_XBUS_SUMMARY);
|
|
|
|
remove_proc_entry(PROC_XBUS_SUMMARY,
|
|
|
|
xbus->proc_xbus_dir);
|
2010-08-28 05:59:27 +08:00
|
|
|
xbus->proc_xbus_summary = NULL;
|
|
|
|
}
|
|
|
|
#ifdef PROTOCOL_DEBUG
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xbus->proc_xbus_command) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_DBG(PROC, xbus, "Removing proc '%s'\n",
|
|
|
|
PROC_XBUS_COMMAND);
|
|
|
|
remove_proc_entry(PROC_XBUS_COMMAND,
|
|
|
|
xbus->proc_xbus_dir);
|
2010-08-28 05:59:27 +08:00
|
|
|
xbus->proc_xbus_command = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
XBUS_DBG(PROC, xbus, "Removing proc directory\n");
|
|
|
|
remove_proc_entry(xbus->busname, xpp_proc_toplevel);
|
|
|
|
xbus->proc_xbus_dir = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
spin_lock_irqsave(&xbuses_lock, flags);
|
|
|
|
XBUS_DBG(DEVICES, xbus, "Going to free...\n");
|
|
|
|
spin_unlock_irqrestore(&xbuses_lock, flags);
|
|
|
|
KZFREE(xbus);
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xbus_free);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_t *xbus_new(struct xbus_ops *ops, ushort max_send_size,
|
|
|
|
struct device *transport_device, void *priv)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int err;
|
|
|
|
xbus_t *xbus = NULL;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!ops);
|
|
|
|
xbus = xbus_alloc();
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xbus) {
|
2012-01-11 23:17:09 +08:00
|
|
|
ERR("%s: Failed allocating new xbus\n", __func__);
|
2010-08-28 05:59:27 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
snprintf(xbus->busname, XBUS_NAMELEN, "XBUS-%02d", xbus->num);
|
|
|
|
XBUS_DBG(DEVICES, xbus, "\n");
|
|
|
|
transport_init(xbus, ops, max_send_size, transport_device, priv);
|
|
|
|
spin_lock_init(&xbus->lock);
|
|
|
|
init_waitqueue_head(&xbus->command_queue_empty);
|
|
|
|
init_timer(&xbus->command_timer);
|
|
|
|
atomic_set(&xbus->pcm_rx_counter, 0);
|
|
|
|
xbus->min_tx_sync = INT_MAX;
|
|
|
|
xbus->min_rx_sync = INT_MAX;
|
2012-01-11 23:16:34 +08:00
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
kref_init(&xbus->kref);
|
|
|
|
worker_init(xbus);
|
|
|
|
atomic_set(&xbus->num_xpds, 0);
|
|
|
|
xbus->sync_mode = SYNC_MODE_NONE;
|
|
|
|
xbus->sync_mode_default = SYNC_MODE_PLL;
|
|
|
|
err = xbus_sysfs_create(xbus);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (err) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_ERR(xbus, "SYSFS creation failed: %d\n", err);
|
|
|
|
goto nobus;
|
|
|
|
}
|
|
|
|
err = xbus_sysfs_transport_create(xbus);
|
|
|
|
if (err) {
|
|
|
|
XBUS_ERR(xbus, "SYSFS transport link creation failed: %d\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
err);
|
2010-08-28 05:59:27 +08:00
|
|
|
goto nobus;
|
|
|
|
}
|
|
|
|
xbus_reset_counters(xbus);
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
XBUS_DBG(PROC, xbus, "Creating xbus proc directory\n");
|
|
|
|
xbus->proc_xbus_dir = proc_mkdir(xbus->busname, xpp_proc_toplevel);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xbus->proc_xbus_dir) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_ERR(xbus, "Failed to create proc directory\n");
|
|
|
|
err = -EIO;
|
|
|
|
goto nobus;
|
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
xbus->proc_xbus_summary = proc_create_data(PROC_XBUS_SUMMARY, 0444,
|
|
|
|
xbus->proc_xbus_dir,
|
|
|
|
&xbus_read_proc_ops,
|
|
|
|
(void *)((unsigned long)xbus->num));
|
2010-08-28 05:59:27 +08:00
|
|
|
if (!xbus->proc_xbus_summary) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_ERR(xbus, "Failed to create proc file '%s'\n",
|
|
|
|
PROC_XBUS_SUMMARY);
|
2010-08-28 05:59:27 +08:00
|
|
|
err = -EIO;
|
|
|
|
goto nobus;
|
|
|
|
}
|
|
|
|
#ifdef PROTOCOL_DEBUG
|
2013-05-22 04:33:18 +08:00
|
|
|
xbus->proc_xbus_command = proc_create_data(PROC_XBUS_COMMAND, 0200,
|
|
|
|
xbus->proc_xbus_dir,
|
|
|
|
&proc_xbus_command_ops, xbus);
|
2010-08-28 05:59:27 +08:00
|
|
|
if (!xbus->proc_xbus_command) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_ERR(xbus, "Failed to create proc file '%s'\n",
|
|
|
|
PROC_XBUS_COMMAND);
|
2010-08-28 05:59:27 +08:00
|
|
|
err = -EIO;
|
|
|
|
goto nobus;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
2012-01-11 23:22:46 +08:00
|
|
|
xframe_queue_init(&xbus->command_queue, 10, command_queue_length,
|
|
|
|
"command_queue", xbus);
|
2010-08-28 05:59:27 +08:00
|
|
|
xframe_queue_init(&xbus->receive_queue, 10, 50, "receive_queue", xbus);
|
|
|
|
xframe_queue_init(&xbus->send_pool, 10, 100, "send_pool", xbus);
|
|
|
|
xframe_queue_init(&xbus->receive_pool, 10, 50, "receive_pool", xbus);
|
|
|
|
xframe_queue_init(&xbus->pcm_tospan, 5, 10, "pcm_tospan", xbus);
|
2012-01-11 23:22:46 +08:00
|
|
|
tasklet_init(&xbus->receive_tasklet, receive_tasklet_func,
|
|
|
|
(unsigned long)xbus);
|
2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* Create worker after /proc/XBUS-?? so the directory exists
|
|
|
|
* before /proc/XBUS-??/waitfor_xpds tries to get created.
|
|
|
|
*/
|
|
|
|
if (!worker_run(xbus)) {
|
|
|
|
ERR("Failed to allocate worker\n");
|
|
|
|
goto nobus;
|
|
|
|
}
|
|
|
|
return xbus;
|
|
|
|
nobus:
|
|
|
|
xbus_free(xbus);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xbus_new);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*------------------------- Proc handling --------------------------*/
|
|
|
|
|
|
|
|
void xbus_reset_counters(xbus_t *xbus)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
XBUS_DBG(GENERAL, xbus, "Reseting counters\n");
|
2012-01-13 01:14:15 +08:00
|
|
|
for (i = 0; i < XBUS_COUNTER_MAX; i++)
|
2010-08-28 05:59:27 +08:00
|
|
|
xbus->counters[i] = 0;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xbus_reset_counters);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
static bool xpds_done(xbus_t *xbus)
|
|
|
|
{
|
|
|
|
if (XBUS_IS(xbus, FAIL))
|
|
|
|
return 1; /* Nothing to wait for */
|
|
|
|
if (xbus->worker.xpds_init_done)
|
|
|
|
return 1; /* All good */
|
|
|
|
/* Keep waiting */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int waitfor_xpds(xbus_t *xbus, char *buf)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct xbus_workqueue *worker;
|
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
|
|
|
int len = 0;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: worker is created before ?????
|
|
|
|
* So by now it exists and initialized.
|
|
|
|
*/
|
|
|
|
worker = &xbus->worker;
|
|
|
|
BUG_ON(!worker);
|
|
|
|
if (!worker->wq) {
|
|
|
|
XBUS_ERR(xbus, "Missing worker thread. Skipping.\n");
|
|
|
|
len = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
XBUS_DBG(DEVICES, xbus,
|
2013-07-28 21:12:00 +08:00
|
|
|
"Waiting for card init of XPDs max %d seconds\n",
|
|
|
|
INITIALIZATION_TIMEOUT / HZ);
|
2012-01-11 23:22:46 +08:00
|
|
|
ret =
|
|
|
|
wait_event_interruptible_timeout(worker->
|
|
|
|
wait_for_xpd_initialization,
|
|
|
|
xpds_done(xbus),
|
|
|
|
INITIALIZATION_TIMEOUT);
|
2010-08-28 05:59:27 +08:00
|
|
|
if (ret == 0) {
|
|
|
|
XBUS_ERR(xbus, "Card Initialization Timeout\n");
|
|
|
|
len = -ETIMEDOUT;
|
|
|
|
goto out;
|
|
|
|
} else if (ret < 0) {
|
|
|
|
XBUS_ERR(xbus, "Card Initialization Interrupted %d\n", ret);
|
|
|
|
len = ret;
|
|
|
|
goto out;
|
|
|
|
} else
|
|
|
|
XBUS_DBG(DEVICES, xbus,
|
2012-01-11 23:22:46 +08:00
|
|
|
"Finished initialization of %d XPD's in %d seconds.\n",
|
|
|
|
worker->num_units_initialized,
|
|
|
|
(INITIALIZATION_TIMEOUT - ret) / HZ);
|
2010-08-28 05:59:27 +08:00
|
|
|
if (XBUS_IS(xbus, FAIL)) {
|
|
|
|
len += sprintf(buf, "FAILED: %s\n", xbus->busname);
|
|
|
|
} else {
|
|
|
|
spin_lock_irqsave(&xbus->lock, flags);
|
2012-01-11 23:22:46 +08:00
|
|
|
len +=
|
|
|
|
sprintf(buf, "XPDS_READY: %s: %d/%d\n", xbus->busname,
|
|
|
|
worker->num_units_initialized, worker->num_units);
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_unlock_irqrestore(&xbus->lock, flags);
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
|
2013-05-22 04:33:18 +08:00
|
|
|
static void xbus_fill_proc_queue(struct seq_file *sfile, struct xframe_queue *q)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile,
|
2012-01-12 03:56:35 +08:00
|
|
|
"%-15s: counts %3d, %3d, %3d worst %3d, overflows %3d "
|
|
|
|
"worst_lag %02ld.%ld ms\n",
|
|
|
|
q->name, q->steady_state_count, q->count, q->max_count,
|
|
|
|
q->worst_count, q->overflows, q->worst_lag_usec / 1000,
|
|
|
|
q->worst_lag_usec % 1000);
|
2010-08-28 05:59:27 +08:00
|
|
|
xframe_queue_clearstats(q);
|
|
|
|
}
|
|
|
|
|
2013-05-22 04:33:18 +08:00
|
|
|
static int xbus_proc_show(struct seq_file *sfile, void *data)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_t *xbus;
|
|
|
|
unsigned long flags;
|
|
|
|
int len = 0;
|
2013-05-22 04:33:18 +08:00
|
|
|
int i = (int)((unsigned long)sfile->private);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2013-05-22 04:33:18 +08:00
|
|
|
xbus = get_xbus(__func__, i); /* until end of xbus_proc_show() */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xbus)
|
2013-05-22 04:33:18 +08:00
|
|
|
return -EINVAL;
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_lock_irqsave(&xbus->lock, flags);
|
|
|
|
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%s: CONNECTOR=%s LABEL=[%s] STATUS=%s\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus->busname, xbus->connector, xbus->label,
|
|
|
|
(XBUS_FLAGS(xbus, CONNECTED)) ? "connected" : "missing");
|
2013-05-22 04:33:18 +08:00
|
|
|
xbus_fill_proc_queue(sfile, &xbus->send_pool);
|
|
|
|
xbus_fill_proc_queue(sfile, &xbus->receive_pool);
|
|
|
|
xbus_fill_proc_queue(sfile, &xbus->command_queue);
|
|
|
|
xbus_fill_proc_queue(sfile, &xbus->receive_queue);
|
|
|
|
xbus_fill_proc_queue(sfile, &xbus->pcm_tospan);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (rx_tasklet) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\ncpu_rcv_intr: ");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_online_cpu(i)
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%5d ", xbus->cpu_rcv_intr[i]);
|
|
|
|
seq_printf(sfile, "\ncpu_rcv_tasklet: ");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_online_cpu(i)
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%5d ", xbus->cpu_rcv_tasklet[i]);
|
|
|
|
seq_printf(sfile, "\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "self_ticking: %d (last_tick at %ld)\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus->self_ticking, xbus->ticker.last_sample.tv.tv_sec);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "command_tick: %d\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus->command_tick_counter);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "usec_nosend: %d\n", xbus->usec_nosend);
|
|
|
|
seq_printf(sfile, "xbus: pcm_rx_counter = %d, frag = %d\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
atomic_read(&xbus->pcm_rx_counter), xbus->xbus_frag_count);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "max_rx_process = %2ld.%ld ms\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus->max_rx_process / 1000, xbus->max_rx_process % 1000);
|
2010-08-28 05:59:27 +08:00
|
|
|
xbus->max_rx_process = 0;
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\nTRANSPORT: max_send_size=%d refcount=%d\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
MAX_SEND_SIZE(xbus),
|
|
|
|
atomic_read(&xbus->transport.transport_refcount)
|
|
|
|
);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "PCM Metrices:\n");
|
|
|
|
seq_printf(sfile, "\tPCM TX: min=%ld max=%ld\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus->min_tx_sync, xbus->max_tx_sync);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\tPCM RX: min=%ld max=%ld\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus->min_rx_sync, xbus->max_rx_sync);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "COUNTERS:\n");
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < XBUS_COUNTER_MAX; i++) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\t%-15s = %d\n", xbus_counters[i].name,
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus->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);
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_unlock_irqrestore(&xbus->lock, flags);
|
2013-05-22 04:33:18 +08:00
|
|
|
put_xbus(__func__, xbus); /* from xbus_proc_show() */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2013-05-22 04:33:18 +08:00
|
|
|
static int xbus_read_proc_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return single_open(file, xbus_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 xbus_read_proc_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = xbus_read_proc_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
};
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
#ifdef PROTOCOL_DEBUG
|
2013-05-22 04:33:18 +08:00
|
|
|
static ssize_t proc_xbus_command_write(struct file *file,
|
|
|
|
const char __user *buffer, size_t count, loff_t *offset)
|
2012-01-11 23:22:46 +08:00
|
|
|
{
|
|
|
|
char *buf;
|
2013-05-22 04:33:18 +08:00
|
|
|
xbus_t *xbus = file->private_data;
|
2012-01-11 23:22:46 +08:00
|
|
|
char *p;
|
|
|
|
__u8 *pack_start;
|
|
|
|
__u8 *q;
|
|
|
|
xframe_t *xframe;
|
|
|
|
size_t len;
|
|
|
|
const size_t max_len = xbus->transport.max_send_size;
|
|
|
|
const size_t max_text = max_len * 3 + 10;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (count > max_text) {
|
2013-05-22 04:33:18 +08:00
|
|
|
XBUS_ERR(xbus, "%s: line too long (%zd > %zd)\n", __func__,
|
2012-01-11 23:22:46 +08:00
|
|
|
count, max_len);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EFBIG;
|
|
|
|
}
|
|
|
|
/* 3 bytes per hex-digit and space */
|
|
|
|
buf = kmalloc(max_text, GFP_KERNEL);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!buf)
|
2010-08-28 05:59:27 +08:00
|
|
|
return -ENOMEM;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (copy_from_user(buf, buffer, count)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
count = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
buf[count] = '\0';
|
2013-05-22 04:33:18 +08:00
|
|
|
XBUS_DBG(GENERAL, xbus, "count=%zd\n", count);
|
2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* We replace the content of buf[] from
|
|
|
|
* ascii representation to packet content
|
|
|
|
* as the binary representation is shorter
|
|
|
|
*/
|
|
|
|
q = pack_start = buf;
|
2012-01-11 23:20:05 +08:00
|
|
|
for (p = buf; *p;) {
|
2012-01-11 23:22:46 +08:00
|
|
|
int val;
|
|
|
|
char hexdigit[3];
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-13 01:12:48 +08:00
|
|
|
/* skip whitespace */
|
|
|
|
while (*p && isspace(*p))
|
2010-08-28 05:59:27 +08:00
|
|
|
p++;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!(*p))
|
2010-08-28 05:59:27 +08:00
|
|
|
break;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!isxdigit(*p)) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_ERR(xbus,
|
2012-01-12 03:56:35 +08:00
|
|
|
"%s: bad hex value ASCII='0x%X' "
|
|
|
|
"at position %ld\n",
|
|
|
|
__func__, *p, (long)(p - buf));
|
2010-08-28 05:59:27 +08:00
|
|
|
count = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
hexdigit[0] = *p++;
|
|
|
|
hexdigit[1] = '\0';
|
|
|
|
hexdigit[2] = '\0';
|
2012-01-11 23:20:05 +08:00
|
|
|
if (isxdigit(*p))
|
2010-08-28 05:59:27 +08:00
|
|
|
hexdigit[1] = *p++;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (sscanf(hexdigit, "%2X", &val) != 1) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_ERR(xbus,
|
|
|
|
"%s: bad hex value '%s' at position %ld\n",
|
|
|
|
__func__, hexdigit, (long)(p - buf));
|
2010-08-28 05:59:27 +08:00
|
|
|
count = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
*q++ = val;
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_DBG(GENERAL, xbus, "%3zd> '%s' val=%d\n", q - pack_start,
|
|
|
|
hexdigit, val);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
len = q - pack_start;
|
|
|
|
xframe = ALLOC_SEND_XFRAME(xbus);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xframe) {
|
2010-08-28 05:59:27 +08:00
|
|
|
count = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (len > max_len)
|
2010-08-28 05:59:27 +08:00
|
|
|
len = max_len;
|
|
|
|
atomic_set(&xframe->frame_len, len);
|
2012-01-11 23:22:46 +08:00
|
|
|
memcpy(xframe->packets, pack_start, len); /* FIXME: checksum? */
|
2010-08-28 05:59:27 +08:00
|
|
|
dump_xframe("COMMAND", xbus, xframe, debug);
|
|
|
|
send_cmd_frame(xbus, xframe);
|
|
|
|
out:
|
|
|
|
kfree(buf);
|
|
|
|
return count;
|
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
|
|
|
|
static int proc_xbus_command_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
file->private_data = PDE_DATA(inode);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations proc_xbus_command_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = proc_xbus_command_open,
|
|
|
|
.write = proc_xbus_command_write,
|
|
|
|
};
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
|
2013-05-22 04:33:18 +08:00
|
|
|
static int xpp_proc_read_show(struct seq_file *sfile, void *data)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < MAX_BUSES; i++) {
|
2010-08-28 05:59:27 +08:00
|
|
|
xbus_t *xbus = get_xbus(__func__, i);
|
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xbus) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile,
|
2012-01-11 23:22:46 +08:00
|
|
|
"%s: CONNECTOR=%s LABEL=[%s] STATUS=%s\n",
|
|
|
|
xbus->busname, xbus->connector, xbus->label,
|
|
|
|
(XBUS_FLAGS(xbus, CONNECTED)) ? "connected"
|
|
|
|
: "missing");
|
2010-08-28 05:59:27 +08:00
|
|
|
put_xbus(__func__, xbus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if 0
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "<-- len=%d\n", len);
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
2013-05-22 04:33:18 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2013-05-22 04:33:18 +08:00
|
|
|
static int xpp_proc_read_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return single_open(file, xpp_proc_read_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 xpp_proc_read_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = xpp_proc_read_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
};
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
static void transport_init(xbus_t *xbus, struct xbus_ops *ops,
|
|
|
|
ushort max_send_size,
|
|
|
|
struct device *transport_device, void *priv)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
BUG_ON(!ops);
|
|
|
|
BUG_ON(!ops->xframe_send_pcm);
|
|
|
|
BUG_ON(!ops->xframe_send_cmd);
|
|
|
|
BUG_ON(!ops->alloc_xframe);
|
|
|
|
BUG_ON(!ops->free_xframe);
|
|
|
|
xbus->transport.ops = ops;
|
|
|
|
xbus->transport.max_send_size = max_send_size;
|
|
|
|
xbus->transport.transport_device = transport_device;
|
|
|
|
xbus->transport.priv = priv;
|
|
|
|
xbus->transport.xbus_state = XBUS_STATE_START;
|
|
|
|
spin_lock_init(&xbus->transport.state_lock);
|
|
|
|
spin_lock_init(&xbus->transport.lock);
|
|
|
|
atomic_set(&xbus->transport.transport_refcount, 0);
|
|
|
|
xbus_setflags(xbus, XBUS_FLAG_CONNECTED, 0);
|
|
|
|
init_waitqueue_head(&xbus->transport.transport_unused);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void transport_destroy(xbus_t *xbus)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int ret;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
XBUS_DBG(DEVICES, xbus, "Waiting... (transport_refcount=%d)\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
atomic_read(&xbus->transport.transport_refcount));
|
|
|
|
ret =
|
|
|
|
wait_event_interruptible(xbus->transport.transport_unused,
|
|
|
|
atomic_read(&xbus->transport.
|
|
|
|
transport_refcount) == 0);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (ret)
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_ERR(xbus,
|
|
|
|
"Waiting for transport_refcount interrupted!!!\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
xbus->transport.ops = NULL;
|
|
|
|
xbus->transport.priv = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct xbus_ops *transportops_get(xbus_t *xbus)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct xbus_ops *ops;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
atomic_inc(&xbus->transport.transport_refcount);
|
|
|
|
ops = xbus->transport.ops;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!ops)
|
2010-08-28 05:59:27 +08:00
|
|
|
atomic_dec(&xbus->transport.transport_refcount);
|
|
|
|
/* fall through */
|
|
|
|
return ops;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(transportops_get);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
void transportops_put(xbus_t *xbus)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct xbus_ops *ops;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
ops = xbus->transport.ops;
|
|
|
|
BUG_ON(!ops);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (atomic_dec_and_test(&xbus->transport.transport_refcount))
|
2010-08-28 05:59:27 +08:00
|
|
|
wake_up(&xbus->transport.transport_unused);
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(transportops_put);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*------------------------- Initialization -------------------------*/
|
|
|
|
static void xbus_core_cleanup(void)
|
|
|
|
{
|
|
|
|
finalize_xbuses_array();
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2012-01-11 23:20:05 +08:00
|
|
|
if (proc_xbuses) {
|
2010-08-28 05:59:27 +08:00
|
|
|
DBG(PROC, "Removing " PROC_XBUSES " from proc\n");
|
|
|
|
remove_proc_entry(PROC_XBUSES, xpp_proc_toplevel);
|
|
|
|
proc_xbuses = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int __init xbus_core_init(void)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int ret = 0;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2014-01-26 22:11:01 +08:00
|
|
|
if (dahdi_autoreg == 1) {
|
|
|
|
NOTICE("WARNING: The dahdi_autoreg parameter is deprecated " \
|
|
|
|
"-- just set dahdi.auto_assign_spans=0\n");
|
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
initialize_xbuses_array();
|
|
|
|
#ifdef PROTOCOL_DEBUG
|
|
|
|
INFO("FEATURE: with PROTOCOL_DEBUG\n");
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2013-05-22 04:33:18 +08:00
|
|
|
proc_xbuses = proc_create_data(PROC_XBUSES, 0444, xpp_proc_toplevel,
|
|
|
|
&xpp_proc_read_ops, NULL);
|
2010-08-28 05:59:27 +08:00
|
|
|
if (!proc_xbuses) {
|
|
|
|
ERR("Failed to create proc file %s\n", PROC_XBUSES);
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
#endif
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((ret = xpp_driver_init()) < 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
goto err;
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
xbus_core_cleanup();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void xbus_core_shutdown(void)
|
|
|
|
{
|
|
|
|
xbus_core_cleanup();
|
|
|
|
xpp_driver_exit();
|
|
|
|
}
|