From 1584ff6a7de005e74854cb257a51a0aa9dd2d4c2 Mon Sep 17 00:00:00 2001 From: Oron Peled Date: Sun, 30 Jan 2011 14:13:22 +0000 Subject: [PATCH] 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 Acked-by: Tzafrir Cohen git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@9705 a0bf4364-ded3-4de4-8d8a-66a801d63aff --- drivers/dahdi/xpp/xbus-core.c | 11 +++-------- drivers/dahdi/xpp/xbus-pcm.c | 19 +++++++++++-------- drivers/dahdi/xpp/xbus-sysfs.c | 2 +- drivers/dahdi/xpp/xpd.h | 3 ++- drivers/dahdi/xpp/xpp_dahdi.c | 8 ++++++++ drivers/dahdi/xpp/xproto.h | 1 - 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/drivers/dahdi/xpp/xbus-core.c b/drivers/dahdi/xpp/xbus-core.c index b0c3261..55c00f6 100644 --- a/drivers/dahdi/xpp/xbus-core.c +++ b/drivers/dahdi/xpp/xbus-core.c @@ -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; } diff --git a/drivers/dahdi/xpp/xbus-pcm.c b/drivers/dahdi/xpp/xbus-pcm.c index e63e533..843a411 100644 --- a/drivers/dahdi/xpp/xbus-pcm.c +++ b/drivers/dahdi/xpp/xbus-pcm.c @@ -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 diff --git a/drivers/dahdi/xpp/xbus-sysfs.c b/drivers/dahdi/xpp/xbus-sysfs.c index b9d3e3d..095baf6 100644 --- a/drivers/dahdi/xpp/xbus-sysfs.c +++ b/drivers/dahdi/xpp/xbus-sysfs.c @@ -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; } diff --git a/drivers/dahdi/xpp/xpd.h b/drivers/dahdi/xpp/xpd.h index 52bef64..2d4b6eb 100644 --- a/drivers/dahdi/xpp/xpd.h +++ b/drivers/dahdi/xpp/xpd.h @@ -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 */ diff --git a/drivers/dahdi/xpp/xpp_dahdi.c b/drivers/dahdi/xpp/xpp_dahdi.c index c5e2f6f..0355bb1 100644 --- a/drivers/dahdi/xpp/xpp_dahdi.c +++ b/drivers/dahdi/xpp/xpp_dahdi.c @@ -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; diff --git a/drivers/dahdi/xpp/xproto.h b/drivers/dahdi/xpp/xproto.h index 5be6797..c772273 100644 --- a/drivers/dahdi/xpp/xproto.h +++ b/drivers/dahdi/xpp/xproto.h @@ -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;