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 "xpd.h"
|
|
|
|
#include "xproto.h"
|
|
|
|
#include "xpp_dahdi.h"
|
|
|
|
#include "xbus-core.h"
|
|
|
|
#include "dahdi_debug.h"
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
|
|
|
|
static const char rcsid[] = "$Id$";
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
extern int debug;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
static const xproto_table_t *xprotocol_tables[XPD_TYPE_NOMODULE];
|
|
|
|
|
|
|
|
#if MAX_UNIT*MAX_SUBUNIT > MAX_XPDS
|
|
|
|
#error MAX_XPDS is too small
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool valid_xpd_addr(const struct xpd_addr *addr)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
return ((addr->subunit & ~BITMASK(SUBUNIT_BITS)) == 0)
|
|
|
|
&& ((addr->unit & ~BITMASK(UNIT_BITS)) == 0);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(valid_xpd_addr);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-12 03:56:35 +08:00
|
|
|
/*------ General Protocol Management ----------------------------*/
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
const xproto_entry_t *xproto_card_entry(const xproto_table_t *table,
|
|
|
|
__u8 opcode)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
|
|
|
const xproto_entry_t *xe;
|
|
|
|
|
|
|
|
//DBG(GENERAL, "\n");
|
|
|
|
xe = &table->entries[opcode];
|
|
|
|
return (xe->handler != NULL) ? xe : NULL;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xproto_card_entry);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:21:54 +08:00
|
|
|
const xproto_entry_t *xproto_global_entry(__u8 opcode)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
|
|
|
const xproto_entry_t *xe;
|
|
|
|
|
|
|
|
xe = xproto_card_entry(&PROTO_TABLE(GLOBAL), opcode);
|
|
|
|
//DBG(GENERAL, "opcode=0x%X xe=%p\n", opcode, xe);
|
|
|
|
return xe;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xproto_global_entry);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:21:54 +08:00
|
|
|
xproto_handler_t xproto_global_handler(__u8 opcode)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
|
|
|
return xproto_card_handler(&PROTO_TABLE(GLOBAL), opcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const xproto_table_t *xproto_table(xpd_type_t cardtype)
|
|
|
|
{
|
2012-01-11 23:20:05 +08:00
|
|
|
if (cardtype >= XPD_TYPE_NOMODULE)
|
2010-08-28 05:59:27 +08:00
|
|
|
return NULL;
|
|
|
|
return xprotocol_tables[cardtype];
|
|
|
|
}
|
|
|
|
|
2012-03-15 23:41:40 +08:00
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
|
|
|
|
#define MODULE_REFCOUNT_FORMAT "%s refcount was %d\n"
|
|
|
|
#else
|
|
|
|
#define MODULE_REFCOUNT_FORMAT "%s refcount was %lu\n"
|
|
|
|
#endif
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
const xproto_table_t *xproto_get(xpd_type_t cardtype)
|
|
|
|
{
|
|
|
|
const xproto_table_t *xtable;
|
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (cardtype >= XPD_TYPE_NOMODULE)
|
2010-08-28 05:59:27 +08:00
|
|
|
return NULL;
|
|
|
|
xtable = xprotocol_tables[cardtype];
|
2012-01-11 23:22:46 +08:00
|
|
|
if (!xtable) { /* Try to load the relevant module */
|
2010-08-28 05:59:27 +08:00
|
|
|
int ret = request_module(XPD_TYPE_PREFIX "%d", cardtype);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (ret != 0) {
|
2012-01-12 03:56:35 +08:00
|
|
|
NOTICE("%s: Failed to load module for type=%d. "
|
|
|
|
"exit status=%d.\n",
|
|
|
|
__func__, cardtype, ret);
|
2010-08-28 05:59:27 +08:00
|
|
|
/* Drop through: we may be lucky... */
|
|
|
|
}
|
|
|
|
xtable = xprotocol_tables[cardtype];
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xtable) {
|
2010-08-28 05:59:27 +08:00
|
|
|
BUG_ON(!xtable->owner);
|
|
|
|
#ifdef CONFIG_MODULE_UNLOAD
|
2012-03-15 23:41:40 +08:00
|
|
|
DBG(GENERAL, MODULE_REFCOUNT_FORMAT, xtable->name,
|
2012-01-11 23:22:46 +08:00
|
|
|
module_refcount(xtable->owner));
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!try_module_get(xtable->owner)) {
|
2012-01-11 23:22:46 +08:00
|
|
|
ERR("%s: try_module_get for %s failed.\n", __func__,
|
|
|
|
xtable->name);
|
2010-08-28 05:59:27 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return xtable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void xproto_put(const xproto_table_t *xtable)
|
|
|
|
{
|
|
|
|
BUG_ON(!xtable);
|
|
|
|
#ifdef CONFIG_MODULE_UNLOAD
|
2012-03-15 23:41:40 +08:00
|
|
|
DBG(GENERAL, MODULE_REFCOUNT_FORMAT, xtable->name,
|
2012-01-11 23:22:46 +08:00
|
|
|
module_refcount(xtable->owner));
|
2010-08-28 05:59:27 +08:00
|
|
|
BUG_ON(module_refcount(xtable->owner) <= 0);
|
|
|
|
#endif
|
|
|
|
module_put(xtable->owner);
|
|
|
|
}
|
|
|
|
|
2012-01-12 03:56:35 +08:00
|
|
|
xproto_handler_t xproto_card_handler(const xproto_table_t *table,
|
|
|
|
__u8 opcode)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
|
|
|
const xproto_entry_t *xe;
|
|
|
|
|
|
|
|
//DBG(GENERAL, "\n");
|
|
|
|
xe = xproto_card_entry(table, opcode);
|
|
|
|
return xe->handler;
|
|
|
|
}
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
void notify_bad_xpd(const char *funcname, xbus_t *xbus,
|
|
|
|
const struct xpd_addr addr, const char *msg)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_NOTICE(xbus, "%s: non-existing address (%1d%1d): %s\n", funcname,
|
|
|
|
addr.unit, addr.subunit, msg);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(notify_bad_xpd);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
static int packet_process(xbus_t *xbus, xpacket_t *pack)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
__u8 op;
|
|
|
|
const xproto_entry_t *xe;
|
|
|
|
xproto_handler_t handler;
|
|
|
|
xproto_table_t *table;
|
|
|
|
xpd_t *xpd;
|
|
|
|
int ret = -EPROTO;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!pack);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!valid_xpd_addr(&XPACKET_ADDR(pack))) {
|
|
|
|
if (printk_ratelimit()) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_NOTICE(xbus, "%s: from %d%d: bad address.\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
__func__, XPACKET_ADDR_UNIT(pack),
|
|
|
|
XPACKET_ADDR_SUBUNIT(pack));
|
|
|
|
dump_packet("packet_process -- bad address", pack,
|
|
|
|
debug);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
op = XPACKET_OP(pack);
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd =
|
|
|
|
xpd_byaddr(xbus, XPACKET_ADDR_UNIT(pack),
|
|
|
|
XPACKET_ADDR_SUBUNIT(pack));
|
2010-08-28 05:59:27 +08:00
|
|
|
/* XPD may be NULL (e.g: during bus polling */
|
|
|
|
xe = xproto_global_entry(op);
|
|
|
|
/*-------- Validations -----------*/
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xe) {
|
2010-08-28 05:59:27 +08:00
|
|
|
const xproto_table_t *xtable;
|
2012-01-11 23:16:34 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd) {
|
|
|
|
if (printk_ratelimit()) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XBUS_NOTICE(xbus,
|
2012-01-12 03:56:35 +08:00
|
|
|
"%s: from %d%d opcode=0x%02X: "
|
|
|
|
"no such global command.\n",
|
|
|
|
__func__, XPACKET_ADDR_UNIT(pack),
|
|
|
|
XPACKET_ADDR_SUBUNIT(pack), op);
|
2012-01-11 23:22:46 +08:00
|
|
|
dump_packet
|
|
|
|
("packet_process -- no such global command",
|
|
|
|
pack, 1);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
xtable = xproto_table(xpd->type);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xtable) {
|
|
|
|
if (printk_ratelimit())
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_ERR(xpd,
|
|
|
|
"%s: no protocol table (type=%d)\n",
|
|
|
|
__func__, xpd->type);
|
2010-08-28 05:59:27 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
xe = xproto_card_entry(xtable, op);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xe) {
|
|
|
|
if (printk_ratelimit()) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_NOTICE(xpd,
|
2012-01-12 03:56:35 +08:00
|
|
|
"%s: bad command (type=%d,opcode=0x%x)\n",
|
|
|
|
__func__, xpd->type, op);
|
2012-01-11 23:22:46 +08:00
|
|
|
dump_packet("packet_process -- bad command",
|
2012-01-12 03:56:35 +08:00
|
|
|
pack, 1);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
table = xe->table;
|
|
|
|
BUG_ON(!table);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!table->packet_is_valid(pack)) {
|
|
|
|
if (printk_ratelimit()) {
|
2010-08-28 05:59:27 +08:00
|
|
|
ERR("xpp: %s: wrong size %d for opcode=0x%02X\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
__func__, XPACKET_LEN(pack), op);
|
|
|
|
dump_packet("packet_process -- wrong size", pack,
|
|
|
|
debug);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
ret = 0; /* All well */
|
2010-08-28 05:59:27 +08:00
|
|
|
handler = xe->handler;
|
|
|
|
BUG_ON(!handler);
|
|
|
|
XBUS_COUNTER(xbus, RX_BYTES) += XPACKET_LEN(pack);
|
|
|
|
handler(xbus, xpd, xe, pack);
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xframe_receive_cmd(xbus_t *xbus, xframe_t *xframe)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
__u8 *xframe_end;
|
|
|
|
xpacket_t *pack;
|
|
|
|
__u8 *p;
|
|
|
|
int len;
|
|
|
|
int ret;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (debug & DBG_COMMANDS)
|
2010-08-28 05:59:27 +08:00
|
|
|
dump_xframe("RX-CMD", xbus, xframe, DBG_ANY);
|
|
|
|
p = xframe->packets;
|
|
|
|
xframe_end = p + XFRAME_LEN(xframe);
|
|
|
|
do {
|
|
|
|
pack = (xpacket_t *)p;
|
|
|
|
len = XPACKET_LEN(pack);
|
|
|
|
/* Sanity checks */
|
2012-01-11 23:21:13 +08:00
|
|
|
if (unlikely(XPACKET_OP(pack) == XPROTO_NAME(GLOBAL, PCM_READ))) {
|
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_DBG(GENERAL, xbus,
|
2012-01-12 03:56:35 +08:00
|
|
|
"A PCM packet within a Non-PCM xframe\n");
|
|
|
|
dump_xframe("In Non-PCM xframe",
|
|
|
|
xbus, xframe, debug);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
ret = -EPROTO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
p += len;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (p > xframe_end || len < RPACKET_HEADERSIZE) {
|
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_NOTICE(xbus, "Invalid packet length %d\n",
|
|
|
|
len);
|
2010-08-28 05:59:27 +08:00
|
|
|
dump_xframe("BAD LENGTH", xbus, xframe, debug);
|
|
|
|
}
|
|
|
|
ret = -EPROTO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
ret = packet_process(xbus, pack);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (unlikely(ret < 0))
|
2010-08-28 05:59:27 +08:00
|
|
|
break;
|
2012-01-11 23:20:05 +08:00
|
|
|
} while (p < xframe_end);
|
2010-08-28 05:59:27 +08:00
|
|
|
out:
|
|
|
|
FREE_RECV_XFRAME(xbus, xframe);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xframe_receive(xbus_t *xbus, xframe_t *xframe)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int ret = 0;
|
|
|
|
struct timeval now;
|
|
|
|
struct timeval tv_received;
|
|
|
|
int usec;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (XFRAME_LEN(xframe) < RPACKET_HEADERSIZE) {
|
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
|
|
|
XBUS_NOTICE(xbus, "short xframe\n");
|
|
|
|
dump_xframe("short xframe", xbus, xframe, debug);
|
|
|
|
}
|
|
|
|
FREE_RECV_XFRAME(xbus, xframe);
|
|
|
|
return -EPROTO;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!XBUS_FLAGS(xbus, CONNECTED)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_DBG(GENERAL, xbus, "Dropped xframe. Is shutting down.\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
tv_received = xframe->tv_received;
|
|
|
|
/*
|
|
|
|
* We want to check that xframes do not mix PCM and other commands
|
|
|
|
*/
|
2012-01-11 23:20:05 +08:00
|
|
|
if (XPACKET_IS_PCM((xpacket_t *)xframe->packets)) {
|
|
|
|
if (!XBUS_IS(xbus, READY))
|
2010-08-28 05:59:27 +08:00
|
|
|
FREE_RECV_XFRAME(xbus, xframe);
|
|
|
|
else
|
|
|
|
xframe_receive_pcm(xbus, xframe);
|
|
|
|
} else {
|
|
|
|
XBUS_COUNTER(xbus, RX_CMD)++;
|
|
|
|
ret = xframe_receive_cmd(xbus, xframe);
|
|
|
|
}
|
|
|
|
/* Calculate total processing time */
|
|
|
|
do_gettimeofday(&now);
|
2012-01-11 23:22:46 +08:00
|
|
|
usec =
|
|
|
|
(now.tv_sec - tv_received.tv_sec) * 1000000 + now.tv_usec -
|
|
|
|
tv_received.tv_usec;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (usec > xbus->max_rx_process)
|
2010-08-28 05:59:27 +08:00
|
|
|
xbus->max_rx_process = usec;
|
|
|
|
return ret;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xframe_receive);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
#define VERBOSE_DEBUG 1
|
|
|
|
#define ERR_REPORT_LIMIT 20
|
|
|
|
|
|
|
|
void dump_packet(const char *msg, const xpacket_t *packet, bool debug)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
__u8 op = XPACKET_OP(packet);
|
|
|
|
__u8 *addr = (__u8 *)&XPACKET_ADDR(packet);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!debug)
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
2012-01-11 23:22:46 +08:00
|
|
|
printk(KERN_DEBUG "%s: XPD=%1X-%1X%c (0x%X) OP=0x%02X LEN=%d", msg,
|
|
|
|
XPACKET_ADDR_UNIT(packet), XPACKET_ADDR_SUBUNIT(packet),
|
|
|
|
(XPACKET_ADDR_SYNC(packet)) ? '+' : ' ', *addr, op,
|
|
|
|
XPACKET_LEN(packet));
|
2010-08-28 05:59:27 +08:00
|
|
|
#if VERBOSE_DEBUG
|
|
|
|
{
|
|
|
|
int i;
|
2012-01-11 23:22:46 +08:00
|
|
|
__u8 *p = (__u8 *)packet;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
printk(" BYTES: ");
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < XPACKET_LEN(packet); i++) {
|
2012-01-11 23:17:42 +08:00
|
|
|
static int limiter;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (i >= sizeof(xpacket_t)) {
|
|
|
|
if (limiter < ERR_REPORT_LIMIT) {
|
2012-01-12 03:56:35 +08:00
|
|
|
ERR("%s: length overflow "
|
|
|
|
"i=%d > sizeof(xpacket_t)=%lu\n",
|
|
|
|
__func__, i + 1,
|
|
|
|
(long)sizeof(xpacket_t));
|
2012-01-11 23:20:05 +08:00
|
|
|
} else if (limiter == ERR_REPORT_LIMIT) {
|
2012-01-12 03:56:35 +08:00
|
|
|
ERR("%s: error packet #%d... "
|
|
|
|
"squelsh reports.\n",
|
|
|
|
__func__, limiter);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
limiter++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (debug)
|
|
|
|
printk("%02X ", p[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
printk("\n");
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(dump_packet);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-12 03:56:35 +08:00
|
|
|
void dump_reg_cmd(const char msg[], bool writing, xbus_t *xbus,
|
|
|
|
__u8 unit, xportno_t port, const reg_cmd_t *regcmd)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
char action;
|
|
|
|
char modifier;
|
|
|
|
char port_buf[MAX_PROC_WRITE];
|
|
|
|
char reg_buf[MAX_PROC_WRITE];
|
|
|
|
char data_buf[MAX_PROC_WRITE];
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-12 03:56:35 +08:00
|
|
|
/* The size byte is not included */
|
|
|
|
if (regcmd->bytes > sizeof(*regcmd) - 1) {
|
2012-01-11 23:22:46 +08:00
|
|
|
PORT_NOTICE(xbus, unit, port,
|
|
|
|
"%s: %s: Too long: regcmd->bytes = %d\n", __func__,
|
|
|
|
msg, regcmd->bytes);
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (regcmd->is_multibyte) {
|
2012-01-11 23:22:46 +08:00
|
|
|
char buf[MAX_PROC_WRITE + 1];
|
|
|
|
int i;
|
|
|
|
int n = 0;
|
|
|
|
size_t len = regcmd->bytes;
|
|
|
|
const __u8 *p = REG_XDATA(regcmd);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
buf[0] = '\0';
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < len && n < MAX_PROC_WRITE; i++)
|
2012-01-11 23:22:46 +08:00
|
|
|
n += snprintf(&buf[n], MAX_PROC_WRITE - n, "%02X ",
|
|
|
|
p[i]);
|
2010-08-28 05:59:27 +08:00
|
|
|
PORT_DBG(REGS, xbus, unit, port,
|
2012-01-12 03:56:35 +08:00
|
|
|
"UNIT-%d PORT-%d: Multibyte(eoframe=%d) "
|
|
|
|
"%s[0..%zd]: %s%s\n",
|
|
|
|
unit, port, regcmd->eoframe, msg, len - 1, buf,
|
|
|
|
(n >= MAX_PROC_WRITE) ? "..." : "");
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-01-12 03:56:35 +08:00
|
|
|
/* The size byte is not included */
|
|
|
|
if (regcmd->bytes != sizeof(*regcmd) - 1) {
|
2012-01-11 23:22:46 +08:00
|
|
|
PORT_NOTICE(xbus, unit, port,
|
|
|
|
"%s: %s: Wrong size: regcmd->bytes = %d\n",
|
|
|
|
__func__, msg, regcmd->bytes);
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
snprintf(port_buf, MAX_PROC_WRITE, "%d%s", regcmd->portnum,
|
|
|
|
(REG_FIELD(regcmd, all_ports_broadcast)) ? "*" : "");
|
2010-08-28 05:59:27 +08:00
|
|
|
action = (REG_FIELD(regcmd, read_request)) ? 'R' : 'W';
|
|
|
|
modifier = 'D';
|
2012-01-11 23:20:05 +08:00
|
|
|
if (REG_FIELD(regcmd, do_subreg)) {
|
2012-01-11 23:16:34 +08:00
|
|
|
snprintf(reg_buf, MAX_PROC_WRITE, "%02X %02X",
|
2012-01-11 23:22:46 +08:00
|
|
|
REG_FIELD(regcmd, regnum), REG_FIELD(regcmd, subreg));
|
2010-08-28 05:59:27 +08:00
|
|
|
modifier = 'S';
|
|
|
|
} else {
|
2012-01-11 23:16:34 +08:00
|
|
|
snprintf(reg_buf, MAX_PROC_WRITE, "%02X",
|
2012-01-11 23:22:46 +08:00
|
|
|
REG_FIELD(regcmd, regnum));
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (REG_FIELD(regcmd, read_request)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
data_buf[0] = '\0';
|
2012-01-11 23:20:05 +08:00
|
|
|
} else if (REG_FIELD(regcmd, do_datah)) {
|
2012-01-11 23:16:34 +08:00
|
|
|
snprintf(data_buf, MAX_PROC_WRITE, "%02X %02X",
|
2012-01-11 23:22:46 +08:00
|
|
|
REG_FIELD(regcmd, data_low), REG_FIELD(regcmd,
|
|
|
|
data_high));
|
2010-08-28 05:59:27 +08:00
|
|
|
modifier = 'I';
|
|
|
|
} else {
|
2012-01-11 23:16:34 +08:00
|
|
|
snprintf(data_buf, MAX_PROC_WRITE, "%02X",
|
2012-01-11 23:22:46 +08:00
|
|
|
REG_FIELD(regcmd, data_low));
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
PORT_DBG(REGS, xbus, unit, port, "%s: %s %c%c %s %s\n", msg, port_buf,
|
|
|
|
action, modifier, reg_buf, data_buf);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(dump_reg_cmd);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
const char *xproto_name(xpd_type_t xpd_type)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
const xproto_table_t *proto_table;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(xpd_type >= XPD_TYPE_NOMODULE);
|
|
|
|
proto_table = xprotocol_tables[xpd_type];
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!proto_table)
|
2010-08-28 05:59:27 +08:00
|
|
|
return NULL;
|
|
|
|
return proto_table->name;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xproto_name);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2011-01-30 22:11:49 +08:00
|
|
|
#define CHECK_XOP(xops, f) \
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!(xops)->f) { \
|
2012-01-12 03:56:35 +08:00
|
|
|
ERR("%s: missing xmethod %s [%s (%d)]\n", \
|
|
|
|
__func__, #f, name, type); \
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EINVAL; \
|
|
|
|
}
|
|
|
|
|
2011-01-31 02:12:02 +08:00
|
|
|
#define CHECK_PHONEOP(phoneops, f) \
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!(phoneops)->f) { \
|
2012-01-12 03:56:35 +08:00
|
|
|
ERR("%s: missing phone method %s [%s (%d)]\n", \
|
|
|
|
__func__, #f, name, type); \
|
2011-01-31 02:12:02 +08:00
|
|
|
return -EINVAL; \
|
|
|
|
}
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
int xproto_register(const xproto_table_t *proto_table)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int type;
|
|
|
|
const char *name;
|
|
|
|
const struct xops *xops;
|
|
|
|
const struct phoneops *phoneops;
|
2012-01-11 23:16:34 +08:00
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
BUG_ON(!proto_table);
|
|
|
|
type = proto_table->type;
|
|
|
|
name = proto_table->name;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (type >= XPD_TYPE_NOMODULE) {
|
2012-01-11 23:17:09 +08:00
|
|
|
NOTICE("%s: Bad xproto type %d\n", __func__, type);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
DBG(GENERAL, "%s (%d)\n", name, type);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xprotocol_tables[type])
|
2012-01-11 23:22:46 +08:00
|
|
|
NOTICE("%s: overriding registration of %s (%d)\n", __func__,
|
|
|
|
name, type);
|
2011-01-30 22:11:49 +08:00
|
|
|
xops = proto_table->xops;
|
|
|
|
CHECK_XOP(xops, card_new);
|
|
|
|
CHECK_XOP(xops, card_init);
|
|
|
|
CHECK_XOP(xops, card_remove);
|
|
|
|
CHECK_XOP(xops, card_tick);
|
2011-01-31 02:12:02 +08:00
|
|
|
CHECK_XOP(xops, card_register_reply);
|
|
|
|
|
|
|
|
phoneops = proto_table->phoneops;
|
|
|
|
if (phoneops) {
|
|
|
|
CHECK_PHONEOP(phoneops, card_pcm_recompute);
|
|
|
|
CHECK_PHONEOP(phoneops, card_pcm_fromspan);
|
|
|
|
CHECK_PHONEOP(phoneops, card_pcm_tospan);
|
2011-06-29 02:23:00 +08:00
|
|
|
CHECK_PHONEOP(phoneops, echocancel_timeslot);
|
|
|
|
CHECK_PHONEOP(phoneops, echocancel_setmask);
|
2011-01-31 02:12:02 +08:00
|
|
|
CHECK_PHONEOP(phoneops, card_dahdi_preregistration);
|
|
|
|
CHECK_PHONEOP(phoneops, card_dahdi_postregistration);
|
|
|
|
/* optional method -- call after testing: */
|
2012-01-11 23:22:46 +08:00
|
|
|
/*CHECK_PHONEOP(phoneops, card_ioctl); */
|
2011-01-31 02:12:02 +08:00
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
xprotocol_tables[type] = proto_table;
|
|
|
|
return 0;
|
|
|
|
}
|
2012-01-12 04:01:32 +08:00
|
|
|
EXPORT_SYMBOL(xproto_register);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
void xproto_unregister(const xproto_table_t *proto_table)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int type;
|
|
|
|
const char *name;
|
2012-01-11 23:16:34 +08:00
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
BUG_ON(!proto_table);
|
|
|
|
type = proto_table->type;
|
|
|
|
name = proto_table->name;
|
|
|
|
DBG(GENERAL, "%s (%d)\n", name, type);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (type >= XPD_TYPE_NOMODULE) {
|
2012-01-11 23:17:09 +08:00
|
|
|
NOTICE("%s: Bad xproto type %s (%d)\n", __func__, name, type);
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xprotocol_tables[type])
|
2012-01-11 23:22:46 +08:00
|
|
|
NOTICE("%s: xproto type %s (%d) is already unregistered\n",
|
|
|
|
__func__, name, type);
|
2010-08-28 05:59:27 +08:00
|
|
|
xprotocol_tables[type] = NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(xproto_unregister);
|