From 13316100480005fcac5121438411d8c42dc9b0ed Mon Sep 17 00:00:00 2001 From: Oron Peled Date: Sun, 30 Jan 2011 14:14:14 +0000 Subject: [PATCH] xpp: phonedev: Cleanup method macros * Caller to CALL_XMETHOD() no longer need to explicitly pass xbus (calculate xpd->xbus) * Create CALL_PHONE_METHOD() similar to CALL_XMETHOD() -- inlining the extra parameters (more readable) * Reverse parameter order in PHONE_METHOD() and CALL_PHONE_METHOD() to be consistent with XMETHOD() and CALL_XMETHOD() * Rename XPD_STATE phonedev method to card_state: - Consistency with other phonedev methods. - These calls now Wrap internal calls to XPD_STATE protocol HOSTCMD in PRI, BRI, FXS, FXO Signed-off-by: Oron Peled Acked-by: Tzafrir Cohen git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@9706 a0bf4364-ded3-4de4-8d8a-66a801d63aff --- drivers/dahdi/xpp/card_bri.c | 35 ++++++++++++++++++--------------- drivers/dahdi/xpp/card_fxo.c | 12 +++++++---- drivers/dahdi/xpp/card_fxs.c | 26 +++++++++++++----------- drivers/dahdi/xpp/card_global.c | 6 +++++- drivers/dahdi/xpp/card_pri.c | 25 ++++++++++++----------- drivers/dahdi/xpp/xbus-core.c | 5 ++--- drivers/dahdi/xpp/xbus-pcm.c | 17 ++++++++-------- drivers/dahdi/xpp/xbus-pcm.h | 8 ++++---- drivers/dahdi/xpp/xpp_dahdi.c | 31 ++++++++++++++--------------- drivers/dahdi/xpp/xproto.h | 30 ++++++++++++++++++---------- 10 files changed, 110 insertions(+), 85 deletions(-) diff --git a/drivers/dahdi/xpp/card_bri.c b/drivers/dahdi/xpp/card_bri.c index 556d175..13bb054 100644 --- a/drivers/dahdi/xpp/card_bri.c +++ b/drivers/dahdi/xpp/card_bri.c @@ -932,7 +932,7 @@ static int BRI_card_dahdi_preregistration(xpd_t *xpd, bool on) cur_chan->sigcap = BRI_BCHAN_SIGCAP; } } - PHONE_METHOD(xpd, card_pcm_recompute)(xpd->xbus, xpd, 0); + CALL_PHONE_METHOD(card_pcm_recompute, xpd, 0); PHONEDEV(xpd).span.ops = &BRI_span_ops; return 0; } @@ -950,7 +950,7 @@ static int BRI_card_dahdi_postregistration(xpd_t *xpd, bool on) return(0); } -static int BRI_card_hooksig(xbus_t *xbus, xpd_t *xpd, int pos, enum dahdi_txsig txsig) +static int BRI_card_hooksig(xpd_t *xpd, int pos, enum dahdi_txsig txsig) { LINE_DBG(SIGNAL, xpd, pos, "%s\n", txsig2str(txsig)); return 0; @@ -1154,7 +1154,7 @@ static int BRI_card_open(xpd_t *xpd, lineno_t pos) BIT_SET(PHONEDEV(xpd).offhook_state, 0); BIT_SET(PHONEDEV(xpd).offhook_state, 1); BIT_SET(PHONEDEV(xpd).offhook_state, 2); - PHONE_METHOD(xpd, card_pcm_recompute)(xpd->xbus, xpd, 0); + CALL_PHONE_METHOD(card_pcm_recompute, xpd, 0); } return 0; } @@ -1176,7 +1176,7 @@ static int BRI_card_close(xpd_t *xpd, lineno_t pos) BIT_CLR(PHONEDEV(xpd).offhook_state, 0); BIT_CLR(PHONEDEV(xpd).offhook_state, 1); BIT_CLR(PHONEDEV(xpd).offhook_state, 2); - PHONE_METHOD(xpd, card_pcm_recompute)(xpd->xbus, xpd, 0); + CALL_PHONE_METHOD(card_pcm_recompute, xpd, 0); } return 0; } @@ -1257,7 +1257,7 @@ static int bri_startup(struct dahdi_span *span) } XPD_DBG(GENERAL, xpd, "STARTUP\n"); // Turn on all channels - PHONE_METHOD(xpd, XPD_STATE)(xpd->xbus, xpd, 1); + CALL_PHONE_METHOD(card_state, xpd, 1); if(SPAN_REGISTERED(xpd)) { dchan = XPD_CHAN(xpd, 2); span->flags |= DAHDI_FLAG_RUNNING; @@ -1293,11 +1293,11 @@ static int bri_shutdown(struct dahdi_span *span) } XPD_DBG(GENERAL, xpd, "SHUTDOWN\n"); // Turn off all channels - PHONE_METHOD(xpd, XPD_STATE)(xpd->xbus, xpd, 0); + CALL_PHONE_METHOD(card_state, xpd, 0); return 0; } -static void BRI_card_pcm_recompute(xbus_t *xbus, xpd_t *xpd, +static void BRI_card_pcm_recompute(xpd_t *xpd, xpp_line_t dont_care) { int i; @@ -1308,7 +1308,7 @@ static void BRI_card_pcm_recompute(xbus_t *xbus, xpd_t *xpd, unsigned long flags; BUG_ON(!xpd); - main_xpd = xpd_byaddr(xbus, xpd->addr.unit, 0); + main_xpd = xpd_byaddr(xpd->xbus, xpd->addr.unit, 0); if(!main_xpd) { XPD_DBG(DEVICES, xpd, "Unit 0 is already gone. Ignore request\n"); return; @@ -1321,7 +1321,7 @@ static void BRI_card_pcm_recompute(xbus_t *xbus, xpd_t *xpd, line_count = 0; pcm_mask = 0; for(i = 0; i < MAX_SUBUNIT; i++) { - xpd_t *sub_xpd = xpd_byaddr(xbus, main_xpd->addr.unit, i); + xpd_t *sub_xpd = xpd_byaddr(xpd->xbus, main_xpd->addr.unit, i); if(sub_xpd) { xpp_line_t lines = @@ -1355,7 +1355,7 @@ static void BRI_card_pcm_recompute(xbus_t *xbus, xpd_t *xpd, spin_unlock_irqrestore(&PHONEDEV(main_xpd).lock_recompute_pcm, flags); } -static void BRI_card_pcm_fromspan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack) +static void BRI_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack) { byte *pcm; unsigned long flags; @@ -1365,14 +1365,13 @@ static void BRI_card_pcm_fromspan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack) xpp_line_t wanted_lines; - BUG_ON(!xbus); BUG_ON(!xpd); BUG_ON(!pack); pcm = RPACKET_FIELD(pack, GLOBAL, PCM_WRITE, pcm); for(subunit = 0; subunit < MAX_SUBUNIT; subunit++) { xpd_t *tmp_xpd; - tmp_xpd = xpd_byaddr(xbus, xpd->addr.unit, subunit); + tmp_xpd = xpd_byaddr(xpd->xbus, xpd->addr.unit, subunit); if(!tmp_xpd || !tmp_xpd->card_present) continue; spin_lock_irqsave(&tmp_xpd->lock, flags); @@ -1402,7 +1401,7 @@ static void BRI_card_pcm_fromspan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack) RPACKET_FIELD(pack, GLOBAL, PCM_WRITE, lines) = pcm_mask; } -static void BRI_card_pcm_tospan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack) +static void BRI_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack) { byte *pcm; xpp_line_t pcm_mask; @@ -1424,7 +1423,7 @@ static void BRI_card_pcm_tospan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack) if(!pcm_mask) break; /* optimize */ - tmp_xpd = xpd_byaddr(xbus, xpd->addr.unit, subunit); + tmp_xpd = xpd_byaddr(xpd->xbus, xpd->addr.unit, subunit); if(!tmp_xpd || !tmp_xpd->card_present || !SPAN_REGISTERED(tmp_xpd)) continue; spin_lock_irqsave(&tmp_xpd->lock, flags); @@ -1670,6 +1669,11 @@ end: return 0; } +static int BRI_card_state(xpd_t *xpd, bool on) +{ + return CALL_PROTO(BRI, XPD_STATE, xpd->xbus, xpd, on); +} + static const struct xops bri_xops = { .card_new = BRI_card_new, .card_init = BRI_card_init, @@ -1689,8 +1693,7 @@ static const struct phoneops bri_phoneops = { .card_ioctl = BRI_card_ioctl, .card_open = BRI_card_open, .card_close = BRI_card_close, - - .XPD_STATE = XPROTO_CALLER(BRI, XPD_STATE), + .card_state = BRI_card_state, }; static xproto_table_t PROTO_TABLE(BRI) = { diff --git a/drivers/dahdi/xpp/card_fxo.c b/drivers/dahdi/xpp/card_fxo.c index 5ee41c5..00c9320 100644 --- a/drivers/dahdi/xpp/card_fxo.c +++ b/drivers/dahdi/xpp/card_fxo.c @@ -482,7 +482,7 @@ static int FXO_card_init(xbus_t *xbus, xpd_t *xpd) do_led(xpd, i, LED_GREEN, 0); msleep(50); } - PHONE_METHOD(xpd, card_pcm_recompute)(xbus, xpd, 0); + CALL_PHONE_METHOD(card_pcm_recompute, xpd, 0); return 0; } @@ -555,7 +555,7 @@ static int FXO_card_dahdi_postregistration(xpd_t *xpd, bool on) return 0; } -static int FXO_card_hooksig(xbus_t *xbus, xpd_t *xpd, int pos, enum dahdi_txsig txsig) +static int FXO_card_hooksig(xpd_t *xpd, int pos, enum dahdi_txsig txsig) { struct FXO_priv_data *priv; int ret = 0; @@ -1111,6 +1111,11 @@ static int FXO_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info) return 0; } +static int FXO_card_state(xpd_t *xpd, bool on) +{ + return CALL_PROTO(FXO, XPD_STATE, xpd->xbus, xpd, on); +} + static const struct xops fxo_xops = { .card_new = FXO_card_new, .card_init = FXO_card_init, @@ -1129,8 +1134,7 @@ static const struct phoneops fxo_phoneops = { .card_timing_priority = generic_timing_priority, .card_ioctl = FXO_card_ioctl, .card_open = FXO_card_open, - - .XPD_STATE = XPROTO_CALLER(FXO, XPD_STATE), + .card_state = FXO_card_state, }; static xproto_table_t PROTO_TABLE(FXO) = { diff --git a/drivers/dahdi/xpp/card_fxs.c b/drivers/dahdi/xpp/card_fxs.c index e3606b5..ebd0eeb 100644 --- a/drivers/dahdi/xpp/card_fxs.c +++ b/drivers/dahdi/xpp/card_fxs.c @@ -455,7 +455,7 @@ static int FXS_card_init(xbus_t *xbus, xpd_t *xpd) msleep(50); } restore_leds(xpd); - PHONE_METHOD(xpd, card_pcm_recompute)(xbus, xpd, 0); + CALL_PHONE_METHOD(card_pcm_recompute, xpd, 0); /* * We should query our offhook state long enough time after we * set the linefeed_control() @@ -559,7 +559,7 @@ static void __do_mute_dtmf(xpd_t *xpd, int pos, bool muteit) BIT_SET(PHONEDEV(xpd).mute_dtmf, pos); else BIT_CLR(PHONEDEV(xpd).mute_dtmf, pos); - PHONE_METHOD(xpd, card_pcm_recompute)(xpd->xbus, xpd, 0); /* already spinlocked */ + CALL_PHONE_METHOD(card_pcm_recompute, xpd, 0); /* already spinlocked */ } static int set_vm_led_mode(xbus_t *xbus, xpd_t *xpd, int pos, @@ -661,7 +661,7 @@ static int send_ring(xpd_t *xpd, lineno_t chan, bool on) return ret; } -static int FXS_card_hooksig(xbus_t *xbus, xpd_t *xpd, int pos, enum dahdi_txsig txsig) +static int FXS_card_hooksig(xpd_t *xpd, int pos, enum dahdi_txsig txsig) { struct FXS_priv_data *priv; int ret = 0; @@ -698,13 +698,13 @@ static int FXS_card_hooksig(xbus_t *xbus, xpd_t *xpd, int pos, enum dahdi_txsig * Restore state after KEWL hangup. */ LINE_DBG(SIGNAL, xpd, pos, "KEWL STOP\n"); - linefeed_control(xbus, xpd, pos, FXS_LINE_POL_ACTIVE); + linefeed_control(xpd->xbus, xpd, pos, FXS_LINE_POL_ACTIVE); if(IS_OFFHOOK(xpd, pos)) MARK_ON(priv, pos, LED_GREEN); } ret = send_ring(xpd, pos, 0); // RING off if (!IS_OFFHOOK(xpd, pos)) - start_stop_vm_led(xbus, xpd, pos); + start_stop_vm_led(xpd->xbus, xpd, pos); txhook = priv->lasttxhook[pos]; if(chan) { switch(chan->sig) { @@ -718,7 +718,7 @@ static int FXS_card_hooksig(xbus_t *xbus, xpd_t *xpd, int pos, enum dahdi_txsig break; } } - ret = linefeed_control(xbus, xpd, pos, txhook); + ret = linefeed_control(xpd->xbus, xpd, pos, txhook); break; case DAHDI_TXSIG_OFFHOOK: if(IS_SET(PHONEDEV(xpd).digital_outputs, pos)) { @@ -741,7 +741,7 @@ static int FXS_card_hooksig(xbus_t *xbus, xpd_t *xpd, int pos, enum dahdi_txsig break; } } - ret = linefeed_control(xbus, xpd, pos, txhook); + ret = linefeed_control(xpd->xbus, xpd, pos, txhook); break; case DAHDI_TXSIG_START: PHONEDEV(xpd).ringing[pos] = 1; @@ -759,7 +759,7 @@ static int FXS_card_hooksig(xbus_t *xbus, xpd_t *xpd, int pos, enum dahdi_txsig LINE_DBG(SIGNAL, xpd, pos, "%s -> Is digital output. Ignored\n", txsig2str(txsig)); return -EINVAL; } - linefeed_control(xbus, xpd, pos, FXS_LINE_OPEN); + linefeed_control(xpd->xbus, xpd, pos, FXS_LINE_OPEN); MARK_OFF(priv, pos, LED_GREEN); break; default: @@ -847,7 +847,7 @@ static int FXS_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long a priv->ohttimer[pos] = val; priv->idletxhookstate[pos] = FXS_LINE_POL_OHTRANS; vmwi_search(xpd, pos, 1); - PHONE_METHOD(xpd, card_pcm_recompute)(xbus, xpd, priv->search_fsk_pattern); + CALL_PHONE_METHOD(card_pcm_recompute, xpd, priv->search_fsk_pattern); LINE_DBG(SIGNAL, xpd, pos, "Start OHT_TIMER. wanted_pcm_mask=0x%X\n", PHONEDEV(xpd).wanted_pcm_mask); } if (VMWI_NEON(priv, pos) && !IS_OFFHOOK(xpd, pos)) @@ -1394,6 +1394,11 @@ static int FXS_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info) return 0; } +static int FXS_card_state(xpd_t *xpd, bool on) +{ + return CALL_PROTO(FXS, XPD_STATE, xpd->xbus, xpd, on); +} + static const struct xops fxs_xops = { .card_new = FXS_card_new, .card_init = FXS_card_init, @@ -1413,8 +1418,7 @@ static const struct phoneops fxs_phoneops = { .card_open = FXS_card_open, .card_close = FXS_card_close, .card_ioctl = FXS_card_ioctl, - - .XPD_STATE = XPROTO_CALLER(FXS, XPD_STATE), + .card_state = FXS_card_state, }; static xproto_table_t PROTO_TABLE(FXS) = { diff --git a/drivers/dahdi/xpp/card_global.c b/drivers/dahdi/xpp/card_global.c index ecb79fd..ba66b9e 100644 --- a/drivers/dahdi/xpp/card_global.c +++ b/drivers/dahdi/xpp/card_global.c @@ -685,7 +685,11 @@ HANDLER_DEF(GLOBAL, REGISTER_REPLY) dump_reg_cmd("REG_REPLY", 0, xbus, xpd->addr.unit, reg->portnum, reg); dump_packet("REG_REPLY", pack, 1); } - return CALL_XMETHOD(card_register_reply, xbus, xpd, reg); + if (! XMETHOD(card_register_reply, xpd)) { + XPD_ERR(xpd, "REGISTER_REPLY: without card_register_reply() method\n"); + return -EINVAL; + } + return CALL_XMETHOD(card_register_reply, xpd, reg); } HANDLER_DEF(GLOBAL, SYNC_REPLY) diff --git a/drivers/dahdi/xpp/card_pri.c b/drivers/dahdi/xpp/card_pri.c index 7e91d2d..3d152c7 100644 --- a/drivers/dahdi/xpp/card_pri.c +++ b/drivers/dahdi/xpp/card_pri.c @@ -552,7 +552,7 @@ static bool valid_pri_modes(const xpd_t *xpd) return 1; } -static void PRI_card_pcm_recompute(xbus_t *xbus, xpd_t *xpd, +static void PRI_card_pcm_recompute(xpd_t *xpd, xpp_line_t pcm_mask) { struct PRI_priv_data *priv; @@ -652,7 +652,7 @@ static int set_pri_proto(xpd_t *xpd, enum pri_protocol set_proto) priv->is_cas = -1; PHONEDEV(xpd).channels = pri_num_channels(set_proto); PHONEDEV(xpd).offhook_state = BITMASK(PHONEDEV(xpd).channels); - PHONE_METHOD(xpd, card_pcm_recompute)(xpd->xbus, xpd, 0); + CALL_PHONE_METHOD(card_pcm_recompute, xpd, 0); priv->deflaw = deflaw; priv->dchan_num = dchan_num; priv->local_loopback = 0; @@ -1037,7 +1037,7 @@ static int pri_lineconfig(xpd_t *xpd, int lineconfig) force_cas = 1; set_mode_cas(xpd, 1); } - PHONE_METHOD(xpd, card_pcm_recompute)(xpd->xbus, xpd, 0); + CALL_PHONE_METHOD(card_pcm_recompute, xpd, 0); /* * E1's can enable CRC checking * CRC4 is legal only for E1, and it is checked by pri_linecompat() @@ -1545,7 +1545,7 @@ static int pri_startup(struct dahdi_span *span) } XPD_DBG(GENERAL, xpd, "STARTUP\n"); // Turn on all channels - PHONE_METHOD(xpd, XPD_STATE)(xpd->xbus, xpd, 1); + CALL_PHONE_METHOD(card_state, xpd, 1); set_rbslines(xpd, 0); write_subunit(xpd, REG_XPM2, 0x00); return 0; @@ -1569,7 +1569,7 @@ static int pri_shutdown(struct dahdi_span *span) } XPD_DBG(GENERAL, xpd, "SHUTDOWN\n"); // Turn off all channels - PHONE_METHOD(xpd, XPD_STATE)(xpd->xbus, xpd, 0); + CALL_PHONE_METHOD(card_state, xpd, 0); return 0; } @@ -1728,7 +1728,7 @@ static int pri_rbsbits(struct dahdi_chan *chan, int bits) * send 31 channels to the device, but they should be called 1-31 rather * than 0-30 . */ -static void PRI_card_pcm_fromspan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack) +static void PRI_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack) { struct PRI_priv_data *priv; byte *pcm; @@ -1738,7 +1738,6 @@ static void PRI_card_pcm_fromspan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack) int physical_chan; int physical_mask = 0; - BUG_ON(!xbus); BUG_ON(!xpd); BUG_ON(!pack); priv = xpd->priv; @@ -1802,7 +1801,7 @@ static void PRI_card_pcm_fromspan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack) * * \see PRI_card_pcm_fromspan */ -static void PRI_card_pcm_tospan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack) +static void PRI_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack) { struct PRI_priv_data *priv; byte *pcm; @@ -1855,7 +1854,7 @@ static void PRI_card_pcm_tospan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack) spin_unlock_irqrestore(&xpd->lock, flags); } -int PRI_timing_priority(xbus_t *xbus, xpd_t *xpd) +int PRI_timing_priority(xpd_t *xpd) { struct PRI_priv_data *priv; @@ -2169,6 +2168,11 @@ end: return 0; } +static int PRI_card_state(xpd_t *xpd, bool on) +{ + return CALL_PROTO(PRI, XPD_STATE, xpd->xbus, xpd, on); +} + static const struct xops pri_xops = { .card_new = PRI_card_new, .card_init = PRI_card_init, @@ -2186,8 +2190,7 @@ static const struct phoneops pri_phoneops = { .card_timing_priority = PRI_timing_priority, .card_ioctl = PRI_card_ioctl, .card_close = PRI_card_close, - - .XPD_STATE = XPROTO_CALLER(PRI, XPD_STATE), + .card_state = PRI_card_state, }; static xproto_table_t PROTO_TABLE(PRI) = { diff --git a/drivers/dahdi/xpp/xbus-core.c b/drivers/dahdi/xpp/xbus-core.c index 55c00f6..9feaeaa 100644 --- a/drivers/dahdi/xpp/xbus-core.c +++ b/drivers/dahdi/xpp/xbus-core.c @@ -900,14 +900,13 @@ static int xpd_initialize(xpd_t *xpd) { int ret = -ENODEV; - if(CALL_XMETHOD(card_init, xpd->xbus, xpd) < 0) { + if(CALL_XMETHOD(card_init, xpd) < 0) { XPD_ERR(xpd, "Card Initialization failed\n"); goto out; } - //CALL_XMETHOD(XPD_STATE, xpd->xbus, xpd, 0); /* Turn off all channels */ xpd->card_present = 1; if (IS_PHONEDEV(xpd)) { - PHONE_METHOD(xpd, XPD_STATE)(xpd->xbus, xpd, 1); /* Turn on all channels */ + CALL_PHONE_METHOD(card_state, 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 843a411..65cf9c0 100644 --- a/drivers/dahdi/xpp/xbus-pcm.c +++ b/drivers/dahdi/xpp/xbus-pcm.c @@ -630,7 +630,7 @@ void elect_syncer(const char *msg) if(!xpd || !xpd->card_present || !IS_PHONEDEV(xpd)) continue; - prio = PHONE_METHOD(xpd, card_timing_priority)(xbus, xpd); + prio = CALL_PHONE_METHOD(card_timing_priority, xpd); if (prio < 0) { DBG(SYNC, "%s/%s: skip sync\n", xbus->busname, xpd->xpdname); @@ -679,7 +679,7 @@ void update_wanted_pcm_mask(xpd_t *xpd, xpp_line_t new_mask, uint new_pcm_len) * channels which should be *added* to the automatic calculation. * Normally, this argument is 0. */ -void generic_card_pcm_recompute(xbus_t *xbus, xpd_t *xpd, xpp_line_t pcm_mask) +void generic_card_pcm_recompute(xpd_t *xpd, xpp_line_t pcm_mask) { int i; int line_count = 0; @@ -854,14 +854,13 @@ dropit: * Generic implementations of card_pcmfromspan()/card_pcmtospan() * For FXS/FXO */ -void generic_card_pcm_fromspan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack) +void generic_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack) { byte *pcm; unsigned long flags; xpp_line_t wanted_lines; int i; - BUG_ON(!xbus); BUG_ON(!xpd); BUG_ON(!pack); wanted_lines = PHONEDEV(xpd).wanted_pcm_mask; @@ -890,7 +889,7 @@ void generic_card_pcm_fromspan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack) spin_unlock_irqrestore(&xpd->lock, flags); } -void generic_card_pcm_tospan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack) +void generic_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack) { byte *pcm; xpp_line_t pcm_mask; @@ -993,7 +992,7 @@ static int copy_pcm_tospan(xbus_t *xbus, xframe_t *xframe) goto out; if(SPAN_REGISTERED(xpd)) { XBUS_COUNTER(xbus, RX_PACK_PCM)++; - PHONE_METHOD(xpd, card_pcm_tospan)(xbus, xpd, pack); + CALL_PHONE_METHOD(card_pcm_tospan, xpd, pack); } } while(p < xframe_end); ret = 0; /* all good */ @@ -1003,7 +1002,7 @@ out: return ret; } -int generic_timing_priority(xbus_t *xbus, xpd_t *xpd) +int generic_timing_priority(xpd_t *xpd) { return PHONEDEV(xpd).timing_priority; } @@ -1080,7 +1079,7 @@ static void xbus_tick(xbus_t *xbus) XPACKET_ADDR_SYNC(pack) = 1; sent_sync_bit = 1; } - PHONE_METHOD(xpd, card_pcm_fromspan)(xbus, xpd, pack); + CALL_PHONE_METHOD(card_pcm_fromspan, xpd, pack); XBUS_COUNTER(xbus, TX_PACK_PCM)++; } } @@ -1131,7 +1130,7 @@ static void xbus_tick(xbus_t *xbus) * Must be called *after* tx/rx so * D-Chan counters may be cleared */ - CALL_XMETHOD(card_tick, xbus, xpd); + CALL_XMETHOD(card_tick, xpd); } } diff --git a/drivers/dahdi/xpp/xbus-pcm.h b/drivers/dahdi/xpp/xbus-pcm.h index de2a829..f050541 100644 --- a/drivers/dahdi/xpp/xbus-pcm.h +++ b/drivers/dahdi/xpp/xbus-pcm.h @@ -105,10 +105,10 @@ int send_pcm_frame(xbus_t *xbus, xframe_t *xframe); void pcm_recompute(xpd_t *xpd, xpp_line_t tmp_pcm_mask); void xframe_receive_pcm(xbus_t *xbus, xframe_t *xframe); void update_wanted_pcm_mask(xpd_t *xpd, xpp_line_t new_mask, uint new_pcm_len); -void generic_card_pcm_recompute(xbus_t *xbus, xpd_t *xpd, xpp_line_t pcm_mask); -void generic_card_pcm_fromspan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack); -void generic_card_pcm_tospan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack); -int generic_timing_priority(xbus_t *xbus, xpd_t *xpd); +void generic_card_pcm_recompute(xpd_t *xpd, xpp_line_t pcm_mask); +void generic_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack); +void generic_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack); +int generic_timing_priority(xpd_t *xpd); void fill_beep(u_char *buf, int num, int duration); const char *sync_mode_name(enum sync_mode mode); void xbus_set_command_timer(xbus_t *xbus, bool on); diff --git a/drivers/dahdi/xpp/xpp_dahdi.c b/drivers/dahdi/xpp/xpp_dahdi.c index 0355bb1..c587219 100644 --- a/drivers/dahdi/xpp/xpp_dahdi.c +++ b/drivers/dahdi/xpp/xpp_dahdi.c @@ -661,7 +661,7 @@ void xpd_remove(xpd_t *xpd) xbus = xpd->xbus; XPD_INFO(xpd, "Remove\n"); dahdi_unregister_xpd(xpd); - CALL_XMETHOD(card_remove, xbus, xpd); + CALL_XMETHOD(card_remove, xpd); xpd_free(xpd); } @@ -702,7 +702,7 @@ void oht_pcm(xpd_t *xpd, int pos, bool pass) LINE_DBG(SIGNAL, xpd, pos, "OHT PCM: block\n"); BIT_CLR(PHONEDEV(xpd).oht_pcm_pass, pos); } - PHONE_METHOD(xpd, card_pcm_recompute)(xpd->xbus, xpd, 0); + CALL_PHONE_METHOD(card_pcm_recompute, xpd, 0); } /* @@ -717,7 +717,7 @@ void mark_offhook(xpd_t *xpd, int pos, bool to_offhook) LINE_DBG(SIGNAL, xpd, pos, "ONHOOK\n"); BIT_CLR(PHONEDEV(xpd).offhook_state, pos); } - PHONE_METHOD(xpd, card_pcm_recompute)(xpd->xbus, xpd, 0); + CALL_PHONE_METHOD(card_pcm_recompute, xpd, 0); } /* @@ -907,8 +907,8 @@ int xpp_open(struct dahdi_chan *chan) current->comm, current->pid, atomic_read(&PHONEDEV(xpd).open_counter)); spin_unlock_irqrestore(&xbus->lock, flags); - if(PHONE_METHOD(xpd, card_open)) - PHONE_METHOD(xpd, card_open)(xpd, pos); + if(PHONE_METHOD(card_open, xpd)) + CALL_PHONE_METHOD(card_open, xpd, pos); return 0; } @@ -921,8 +921,8 @@ int xpp_close(struct dahdi_chan *chan) spin_lock_irqsave(&xbus->lock, flags); spin_unlock_irqrestore(&xbus->lock, flags); - if(PHONE_METHOD(xpd, card_close)) - PHONE_METHOD(xpd, card_close)(xpd, pos); + if(PHONE_METHOD(card_close, xpd)) + CALL_PHONE_METHOD(card_close, xpd, pos); LINE_DBG(DEVICES, xpd, pos, "%s[%d]: open_counter=%d\n", current->comm, current->pid, atomic_read(&PHONEDEV(xpd).open_counter)); @@ -958,8 +958,8 @@ int xpp_ioctl(struct dahdi_chan *chan, unsigned int cmd, unsigned long arg) switch (cmd) { default: /* Some span-specific commands before we give up: */ - if (PHONE_METHOD(xpd, card_ioctl)) { - return PHONE_METHOD(xpd, card_ioctl)(xpd, pos, cmd, arg); + if (PHONE_METHOD(card_ioctl, xpd)) { + return CALL_PHONE_METHOD(card_ioctl, xpd, pos, cmd, arg); } report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd); return -ENOTTY; @@ -978,7 +978,7 @@ int xpp_hooksig(struct dahdi_chan *chan, enum dahdi_txsig txsig) __FUNCTION__, pos); return -ENODEV; } - if(!PHONE_METHOD(xpd, card_hooksig)) { + if(!PHONE_METHOD(card_hooksig, xpd)) { LINE_ERR(xpd, pos, "%s: No hooksig method for this channel. Ignore.\n", __FUNCTION__); @@ -987,7 +987,7 @@ int xpp_hooksig(struct dahdi_chan *chan, enum dahdi_txsig txsig) xbus = xpd->xbus; BUG_ON(!xbus); DBG(SIGNAL, "Setting %s to %s (%d)\n", chan->name, txsig2str(txsig), txsig); - return PHONE_METHOD(xpd, card_hooksig)(xbus, xpd, pos, txsig); + return CALL_PHONE_METHOD(card_hooksig, xpd, pos, txsig); } EXPORT_SYMBOL(xpp_hooksig); @@ -1018,7 +1018,6 @@ int xpp_maint(struct dahdi_span *span, int cmd) break; case DAHDI_MAINT_LOOPUP: INFO("XXX Send loopup code XXX\n"); - // CALL_XMETHOD(LOOPBACK_AX, xpd->xbus, xpd, loopback_data, ARRAY_SIZE(loopback_data)); break; case DAHDI_MAINT_LOOPDOWN: INFO("XXX Send loopdown code XXX\n"); @@ -1085,12 +1084,12 @@ int dahdi_unregister_xpd(xpd_t *xpd) mdelay(2); // FIXME: This is to give chance for transmit/receiveprep to finish. spin_unlock_irqrestore(&xpd->lock, flags); if(xpd->card_present) - PHONE_METHOD(xpd, card_dahdi_preregistration)(xpd, 0); + CALL_PHONE_METHOD(card_dahdi_preregistration, xpd, 0); atomic_dec(&PHONEDEV(xpd).dahdi_registered); atomic_dec(&num_registered_spans); dahdi_unregister(&PHONEDEV(xpd).span); if(xpd->card_present) - PHONE_METHOD(xpd, card_dahdi_postregistration)(xpd, 0); + CALL_PHONE_METHOD(card_dahdi_postregistration, xpd, 0); return 0; } @@ -1185,14 +1184,14 @@ int dahdi_register_xpd(xpd_t *xpd) snprintf(PHONEDEV(xpd).span.desc, MAX_SPANDESC, "Xorcom XPD #%02d/%1d%1d: %s", xbus->num, xpd->addr.unit, xpd->addr.subunit, xpd->type_name); XPD_DBG(GENERAL, xpd, "Registering span '%s'\n", PHONEDEV(xpd).span.desc); - PHONE_METHOD(xpd, card_dahdi_preregistration)(xpd, 1); + CALL_PHONE_METHOD(card_dahdi_preregistration, xpd, 1); if(dahdi_register(&PHONEDEV(xpd).span, prefmaster)) { XPD_ERR(xpd, "Failed to dahdi_register span\n"); return -ENODEV; } atomic_inc(&num_registered_spans); atomic_inc(&PHONEDEV(xpd).dahdi_registered); - PHONE_METHOD(xpd, card_dahdi_postregistration)(xpd, 1); + CALL_PHONE_METHOD(card_dahdi_postregistration, xpd, 1); /* * Update dahdi about our state: * - Since asterisk didn't open the channel yet, diff --git a/drivers/dahdi/xpp/xproto.h b/drivers/dahdi/xpp/xproto.h index c772273..78ef980 100644 --- a/drivers/dahdi/xpp/xproto.h +++ b/drivers/dahdi/xpp/xproto.h @@ -213,24 +213,34 @@ xproto_handler_t xproto_card_handler(const xproto_table_t *table, byte opcode); const xproto_entry_t *xproto_global_entry(byte opcode); xproto_handler_t xproto_global_handler(byte opcode); -#define CALL_XMETHOD(name, xbus, xpd, ...) \ - (xpd)->xops->name(xbus, xpd, ## __VA_ARGS__ ) +/* + * XMETHOD() resolve to method pointer (NULL for optional methods) + * CALL_XMETHOD() calls the method, passing mandatory arguments + */ +#define XMETHOD(name, xpd) ((xpd)->xops->name) +#define CALL_XMETHOD(name, xpd, ...) \ + (XMETHOD(name, (xpd))((xpd)->xbus, (xpd), ## __VA_ARGS__ )) -#define PHONE_METHOD(xpd, name) PHONEDEV(xpd).phoneops->name +/* + * PHONE_METHOD() resolve to method pointer (NULL for optional methods) + * CALL_PHONE_METHOD() calls the method, passing mandatory arguments + */ +#define PHONE_METHOD(name, xpd) (PHONEDEV(xpd).phoneops->name) +#define CALL_PHONE_METHOD(name, xpd, ...) \ + (PHONE_METHOD(name, (xpd))((xpd), ## __VA_ARGS__ )) struct phoneops { - void (*card_pcm_recompute)(xbus_t *xbus, xpd_t *xpd, xpp_line_t pcm_mask); - void (*card_pcm_fromspan)(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack); - void (*card_pcm_tospan)(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack); - int (*card_timing_priority)(xbus_t *xbus, xpd_t *xpd); + void (*card_pcm_recompute)(xpd_t *xpd, xpp_line_t pcm_mask); + void (*card_pcm_fromspan)(xpd_t *xpd, xpacket_t *pack); + void (*card_pcm_tospan)(xpd_t *xpd, xpacket_t *pack); + int (*card_timing_priority)(xpd_t *xpd); int (*card_dahdi_preregistration)(xpd_t *xpd, bool on); int (*card_dahdi_postregistration)(xpd_t *xpd, bool on); - int (*card_hooksig)(xbus_t *xbus, xpd_t *xpd, int pos, enum dahdi_txsig txsig); + int (*card_hooksig)(xpd_t *xpd, int pos, enum dahdi_txsig txsig); int (*card_ioctl)(xpd_t *xpd, int pos, unsigned int cmd, unsigned long arg); int (*card_open)(xpd_t *xpd, lineno_t pos); int (*card_close)(xpd_t *xpd, lineno_t pos); - - int (*XPD_STATE)(xbus_t *xbus, xpd_t *xpd, bool on); + int (*card_state)(xpd_t *xpd, bool on); }; struct xops {