xpp: More adaptations for non-PHONEDEV XPDs

* Add IS_PHONEDEV(xpd) macro
* Reject dahdi_register_xpd()/dahdi_unregister_xpd() for non-PHONEDEV
* Make sysfs 'offhook' attribute contain '\n' if empty (no channels)
* Skip PHONEDEV related xbus_tick() parts -- we still want to process
  the end of it for the card_tick() calls.
* Remove BUG_ON() for missing phoneops
  (also remove old duplicate test for XBUS_IS...)
* Call XPD_STATE method only for PHONEDEV XPD's

Signed-off-by: Oron Peled <oron@actcom.co.il>
Acked-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>

git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@9705 a0bf4364-ded3-4de4-8d8a-66a801d63aff
This commit is contained in:
Oron Peled 2011-01-30 14:13:22 +00:00 committed by Tzafrir Cohen
parent af702dafff
commit 1584ff6a7d
6 changed files with 25 additions and 19 deletions

View File

@ -809,7 +809,6 @@ static int new_card(xbus_t *xbus,
subunits,
port_dir
);
BUG_ON(!proto_table->phoneops);
xbus->worker.num_units += subunits - 1;
for(i = 0; i < subunits; i++) {
int subunit_ports = proto_table->ports_per_subunit;
@ -841,12 +840,6 @@ static int new_card(xbus_t *xbus,
i,
type,
subtype, subunit_ports);
if(!XBUS_IS(xbus, RECVD_DESC)) {
XBUS_ERR(xbus, "Aborting creation -- In bad state %s\n",
xbus_statename(XBUS_STATE(xbus)));
ret = -ENODEV;
goto out;
}
ret = create_xpd(xbus, proto_table, unit, i, type, subtype, subunits, subunit_ports, port_dir);
if(ret < 0) {
XBUS_ERR(xbus, "Creation of XPD=%d%d failed %d\n",
@ -913,7 +906,9 @@ static int xpd_initialize(xpd_t *xpd)
}
//CALL_XMETHOD(XPD_STATE, xpd->xbus, xpd, 0); /* Turn off all channels */
xpd->card_present = 1;
PHONE_METHOD(xpd, XPD_STATE)(xpd->xbus, xpd, 1); /* Turn on all channels */
if (IS_PHONEDEV(xpd)) {
PHONE_METHOD(xpd, XPD_STATE)(xpd->xbus, xpd, 1); /* Turn on all channels */
}
if(!xpd_setstate(xpd, XPD_STATE_READY)) {
goto out;
}

View File

@ -628,7 +628,7 @@ void elect_syncer(const char *msg)
xpd_t *xpd = xpd_of(xbus, j);
int prio;
if(!xpd || !xpd->card_present)
if(!xpd || !xpd->card_present || !IS_PHONEDEV(xpd))
continue;
prio = PHONE_METHOD(xpd, card_timing_priority)(xbus, xpd);
if (prio < 0) {
@ -1045,12 +1045,13 @@ static void xbus_tick(xbus_t *xbus)
* Fill xframes
*/
for(i = 0; i < MAX_XPDS; i++) {
size_t pcm_len;
if((xpd = xpd_of(xbus, i)) == NULL)
continue;
pcm_len = PHONEDEV(xpd).pcm_len;
if (!IS_PHONEDEV(xpd))
continue;
if(SPAN_REGISTERED(xpd)) {
size_t pcm_len = PHONEDEV(xpd).pcm_len;
if(pcm_len && xpd->card_present) {
do {
// pack = NULL; /* FORCE single packet frames */
@ -1118,11 +1119,13 @@ static void xbus_tick(xbus_t *xbus)
xpd = xpd_of(xbus, i);
if(!xpd || !xpd->card_present)
continue;
if(SPAN_REGISTERED(xpd)) {
do_ec(xpd);
dahdi_receive(&PHONEDEV(xpd).span);
if (IS_PHONEDEV(xpd)) {
if(SPAN_REGISTERED(xpd)) {
do_ec(xpd);
dahdi_receive(&PHONEDEV(xpd).span);
}
PHONEDEV(xpd).silence_pcm = 0; /* silence was injected */
}
PHONEDEV(xpd).silence_pcm = 0; /* silence was injected */
xpd->timer_count = xbus->global_counter;
/*
* Must be called *after* tx/rx so

View File

@ -677,8 +677,8 @@ static DEVICE_ATTR_READER(offhook_show, dev, buf)
}
if(len) {
len--; /* backout last space */
len += sprintf(buf + len, "\n");
}
len += sprintf(buf + len, "\n");
return len;
}

View File

@ -149,7 +149,8 @@ enum xpd_state {
bool xpd_setstate(xpd_t *xpd, enum xpd_state newstate);
const char *xpd_statename(enum xpd_state st);
#define PHONEDEV(xpd) ((xpd)->phonedev)
#define PHONEDEV(xpd) ((xpd)->phonedev)
#define IS_PHONEDEV(xpd) (PHONEDEV(xpd).phoneops)
struct phonedev {
const struct phoneops *phoneops; /* Card level operations */

View File

@ -1066,6 +1066,10 @@ int dahdi_unregister_xpd(xpd_t *xpd)
BUG_ON(!xpd);
spin_lock_irqsave(&xpd->lock, flags);
if (!IS_PHONEDEV(xpd)) {
XPD_ERR(xpd, "Not a telephony device\n");
return -EBADF;
}
if(!SPAN_REGISTERED(xpd)) {
XPD_NOTICE(xpd, "Already unregistered\n");
spin_unlock_irqrestore(&xpd->lock, flags);
@ -1118,6 +1122,10 @@ int dahdi_register_xpd(xpd_t *xpd)
xbus = xpd->xbus;
if (!IS_PHONEDEV(xpd)) {
XPD_ERR(xpd, "Not a telephony device\n");
return -EBADF;
}
if (SPAN_REGISTERED(xpd)) {
XPD_ERR(xpd, "Already registered\n");
return -EEXIST;

View File

@ -255,7 +255,6 @@ struct xproto_table {
xproto_entry_t entries[256]; /* Indexed by opcode */
const struct xops *xops; /* Card level operations */
const struct phoneops *phoneops; /* DAHDI operations */
//const struct echoops *echo;
xpd_type_t type;
byte ports_per_subunit;
const char *name;