From c88eaa22e13bd4c092b367a28e57064659660466 Mon Sep 17 00:00:00 2001 From: tzafrir Date: Thu, 2 Aug 2007 12:21:11 +0000 Subject: Merge xpp r4372: * Update to zaptel-1.2.18 and zaptel-1.4.3 (r4308 onward) * Fix a critical race with zaptel synchronization (r4362) * Added a /proc/xpp/cmds for statistics about command timing (r4360) * Fix a digit mapping bug with hardware dtmf detection (r4357) * In xpp/utils/Makefile add perl syntax checks to our scripts (r4337) * Better USB data error checking (r4336) * udev rules (xpp.rules) avoid false calls from wrong nodes (r4331) * Improve hardware detection and reporting in lszaptel, zaptel_hardware. zapconf is basically functional. * Leds are blinked synchronously on all Astribanks now (r4262) * Fix a BRI bug if OPTIMIZE_CHANMUTE was compiled into zaptel (r4258) (This feature was not yet accepted into official zaptel) * Removed compile warning about HZ != 1000 (r4218) * Firmware updates. * fpga_load now supports USB pathes without zeros (r4211) * XPD numbers have changed to '' (r4196) * Proper support for ZT_VMWI ioctl, if used in zaptel (r4092) * Fix FXO power denial detection (r4054) * FXO could accidentally go off-hook with some compilers (r4048) (From branches/1.2 r2732, r2735 - branches/1.4 2736) git-svn-id: http://svn.digium.com/svn/zaptel/trunk@2813 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- xpp/card_bri.c | 365 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 285 insertions(+), 80 deletions(-) (limited to 'xpp/card_bri.c') diff --git a/xpp/card_bri.c b/xpp/card_bri.c index 9919036..286c04a 100644 --- a/xpp/card_bri.c +++ b/xpp/card_bri.c @@ -42,6 +42,10 @@ static const char rcsid[] = "$Id$"; DEF_PARM(int, print_dbg, 0, 0644, "Print DBG statements"); /* must be before zap_debug.h */ DEF_PARM(uint, poll_interval, 500, 0644, "Poll channel state interval in milliseconds (0 - disable)"); +#ifdef DEBUG_PCMTX +DEF_PARM(int, pcmtx, -1, 0644, "Forced PCM value to transmit (negative to disable)"); +DEF_PARM(int, pcmtx_chan, 0, 0644, "channel to force PCM value"); +#endif enum xhfc_states { ST_RESET = 0, /* G/F0 */ @@ -146,6 +150,7 @@ typedef union { ) #define BRI_BCHAN_SIGCAP ZT_SIG_CLEAR +#define IS_NT(xpd) ((xpd)->type == XPD_TYPE_BRI_NT) /*---------------- BRI Protocol Commands ----------------------------------*/ @@ -155,6 +160,10 @@ static void bri_packet_dump(const char *msg, xpacket_t *pack); static int proc_bri_info_read(char *page, char **start, off_t off, int count, int *eof, void *data); static int proc_xpd_register_read(char *page, char **start, off_t off, int count, int *eof, void *data); static int proc_xpd_register_write(struct file *file, const char __user *buffer, unsigned long count, void *data); +static int bri_spanconfig(struct zt_span *span, struct zt_lineconfig *lc); +static int bri_chanconfig(struct zt_chan *chan, int sigtype); +static int bri_startup(struct zt_span *span); +static int bri_shutdown(struct zt_span *span); #define PROC_REGISTER_FNAME "slics" #define PROC_BRI_INFO_FNAME "bri_info" @@ -205,6 +214,7 @@ struct BRI_priv_data { bool reg30_good; uint reg30_ticks; bool layer1_up; + xpp_line_t card_pcm_mask; /* * D-Chan: buffers + extra state info. @@ -228,17 +238,20 @@ struct BRI_priv_data { enum led_state ledstate[NUM_LEDS]; }; -xproto_table_t PROTO_TABLE(BRI_NT); -xproto_table_t PROTO_TABLE(BRI_TE); +static xproto_table_t PROTO_TABLE(BRI_NT); +static xproto_table_t PROTO_TABLE(BRI_TE); DEF_RPACKET_DATA(BRI, SET_LED, /* Set one of the LED's */ struct bri_leds bri_leds; ); -static /* 0x33 */ DECLARE_CMD(BRI, SET_LED, bool red_led, enum led_state to_led_state); +static /* 0x33 */ DECLARE_CMD(BRI, SET_LED, enum bri_led_names which_led, enum led_state to_led_state); static /* 0x0F */ DECLARE_CMD(BRI, REGISTER_REQUEST, byte chipsel, bool writing, bool do_subreg, byte regnum, byte subreg, byte data_low, byte data_high); +#define DO_LED(xpd, which, tostate) \ + CALL_PROTO(BRI, SET_LED, (xpd)->xbus, (xpd), (which), (tostate)) + #define DEBUG_BUF_SIZE (100) static void dump_hex_buf(xpd_t *xpd, char *msg, byte *buf, size_t len) { @@ -474,7 +487,7 @@ static int send_bri_multibyte(xpd_t *xpd, byte *buf, int len, bool eoftx) ERR("%s: len=%d is too long. dropping.\n", __FUNCTION__, len); return -EINVAL; } - XFRAME_NEW(xframe, pack, xbus, BRI, REGISTER_REQUEST, xpd->id); + XFRAME_NEW(xframe, pack, xbus, BRI, REGISTER_REQUEST, xpd->xbus_idx); reg_cmd = &RPACKET_FIELD(pack, BRI, REGISTER_REQUEST, reg_cmd); reg_cmd->bytes = len; reg_cmd->eoframe = eoftx; @@ -490,7 +503,7 @@ static int send_bri_multibyte(xpd_t *xpd, byte *buf, int len, bool eoftx) if(print_dbg) dump_xframe("SEND_BRI_MULTI", xbus, xframe); #endif - ret = xframe_send(xbus, xframe); + ret = send_cmd_frame(xbus, xframe); if(ret < 0) NOTICE("%s: %s: failed sending xframe\n", __FUNCTION__, xbus->busname); return ret; @@ -509,7 +522,7 @@ static int tx_dchan(xpd_t *xpd) priv = xpd->priv; BUG_ON(!priv); - if(xpd->type == XPD_TYPE_BRI_TE) { + if(!IS_NT(xpd)) { static int rate_limit; if (priv->t3 > HFC_TIMER_OFF) { @@ -562,25 +575,27 @@ static int tx_dchan(xpd_t *xpd) if(ret < 0) NOTICE("%s/%s: %s: failed sending xframe\n", __FUNCTION__, xpd->xbus->busname, xpd->xpdname); - priv->dchan_tx_counter++; + if(eoframe) + priv->dchan_tx_counter++; priv->dchan_notx_ticks = 0; return ret; } /*---------------- BRI: Methods -------------------------------------------*/ -static xpd_t *BRI_card_new(xbus_t *xbus, int xpd_num, const xproto_table_t *proto_table, byte revision) +static xpd_t *BRI_card_new(xbus_t *xbus, int unit, int subunit, const xproto_table_t *proto_table, byte revision) { xpd_t *xpd = NULL; int channels = min(3, CHANNELS_PERXPD); DBG("\n"); - xpd = xpd_alloc(sizeof(struct BRI_priv_data), xbus, xpd_num, proto_table, channels, revision); + xpd = xpd_alloc(sizeof(struct BRI_priv_data), proto_table, channels); if(!xpd) return NULL; xpd->direction = (proto_table == &PROTO_TABLE(BRI_NT)) ? TO_PHONE : TO_PSTN; xpd->revision = revision; + xpd->type_name = proto_table->name; return xpd; } @@ -643,6 +658,7 @@ static int BRI_card_init(xbus_t *xbus, xpd_t *xpd) */ CALL_PROTO(GLOBAL, SYNC_SOURCE, xbus, NULL, SYNC_MODE_HOST, 0); DBG("done: %s/%s\n", xbus->busname, xpd->xpdname); + priv->initialized = 1; return 0; err: @@ -666,6 +682,9 @@ static int BRI_card_zaptel_preregistration(xpd_t *xpd, bool on) { xbus_t *xbus; struct BRI_priv_data *priv; + xpp_line_t tmp_pcm_mask; + int tmp_pcm_len; + unsigned long flags; int i; BUG_ON(!xpd); @@ -677,10 +696,6 @@ static int BRI_card_zaptel_preregistration(xpd_t *xpd, bool on) /* Nothing to do yet */ return 0; } - snprintf(xpd->span.desc, MAX_SPANDESC, "Xorcom XPD #%d/%d: %s", - xbus->num, xpd->id, - xpd->xproto->name - ); xpd->span.linecompat = ZT_CONFIG_AMI | ZT_CONFIG_CCS; xpd->span.deflaw = ZT_LAW_ALAW; BIT_SET(xpd->digital_signalling, 2); /* D-Channel */ @@ -688,8 +703,9 @@ static int BRI_card_zaptel_preregistration(xpd_t *xpd, bool on) struct zt_chan *cur_chan = &xpd->chans[i]; DBG("setting BRI channel %d\n", i); - snprintf(cur_chan->name, MAX_CHANNAME, "XPP_%s/%d/%d/%d", - xpd->xproto->name, xbus->num, xpd->id, i); + snprintf(cur_chan->name, MAX_CHANNAME, "XPP_%s/%02d/%1d%1d/%d", + xpd->xproto->name, xbus->num, + xpd->addr.unit, xpd->addr.subunit, i); cur_chan->chanpos = i + 1; cur_chan->pvt = xpd; if(i == 2) { /* D-CHAN */ @@ -710,6 +726,34 @@ static int BRI_card_zaptel_preregistration(xpd_t *xpd, bool on) cur_chan->sigcap = BRI_BCHAN_SIGCAP; } xpd->offhook = BIT(0) | BIT(1); /* 2*bchan */ + + /* + * Compute PCM lentgh and mask + * We know all cards have been initialized until now + */ + tmp_pcm_mask = 0; + if(xpd->addr.subunit == 0) { + int line_count = 0; + + for(i = 0; i < MAX_SUBUNIT; i++) { + xpd_t *sub_xpd = xpd_byaddr(xbus, xpd->addr.unit, i); + if(sub_xpd) { + tmp_pcm_mask |= (sub_xpd->wanted_pcm_mask << (SUBUNIT_PCM_SHIFT * i)); + line_count += 2; + } + } + tmp_pcm_len = RPACKET_HEADERSIZE + sizeof(xpp_line_t) + line_count * ZT_CHUNKSIZE; + } else + tmp_pcm_len = 0; + spin_lock_irqsave(&xpd->lock, flags); + xpd->pcm_len = tmp_pcm_len; + xpd->wanted_pcm_mask = xpd->offhook; + priv->card_pcm_mask = tmp_pcm_mask; + xpd->span.spanconfig = bri_spanconfig; + xpd->span.chanconfig = bri_chanconfig; + xpd->span.startup = bri_startup; + xpd->span.shutdown = bri_shutdown; + spin_unlock_irqrestore(&xpd->lock, flags); return 0; } @@ -744,45 +788,42 @@ static void handle_leds(xbus_t *xbus, xpd_t *xpd) unsigned int timer_count; int which_led; int other_led; - enum led_state ledstate; int mod; BUG_ON(!xpd); - if(xpd->type == XPD_TYPE_BRI_TE) { - which_led = GREEN_LED; - other_led = RED_LED; - } else { + if(IS_NT(xpd)) { which_led = RED_LED; other_led = GREEN_LED; + } else { + which_led = GREEN_LED; + other_led = RED_LED; } priv = xpd->priv; BUG_ON(!priv); - ledstate = priv->ledstate[which_led]; timer_count = xpd->timer_count; - if((timer_count % DEFAULT_LED_PERIOD) == 0) { - if(xpd->blink_mode) { + if(xpd->blink_mode) { + if((timer_count % DEFAULT_LED_PERIOD) == 0) { // led state is toggled - if(ledstate == BRI_LED_OFF) { - CALL_PROTO(BRI, SET_LED, xbus, xpd, which_led, BRI_LED_ON); - CALL_PROTO(BRI, SET_LED, xbus, xpd, other_led, BRI_LED_ON); - } else { - CALL_PROTO(BRI, SET_LED, xbus, xpd, which_led, BRI_LED_OFF); - CALL_PROTO(BRI, SET_LED, xbus, xpd, other_led, BRI_LED_OFF); - } - return; - } else if(priv->ledstate[other_led] == BRI_LED_ON) /* cleanup after blink */ - CALL_PROTO(BRI, SET_LED, xbus, xpd, other_led, BRI_LED_OFF); + if(priv->ledstate[which_led] == BRI_LED_OFF) { + DO_LED(xpd, which_led, BRI_LED_ON); + DO_LED(xpd, other_led, BRI_LED_ON); + } else { + DO_LED(xpd, which_led, BRI_LED_OFF); + DO_LED(xpd, other_led, BRI_LED_OFF); + } + } + return; } + if(priv->ledstate[other_led] != BRI_LED_OFF) + DO_LED(xpd, other_led, BRI_LED_OFF); if(priv->dchan_alive) { mod = timer_count % 1000; switch(mod) { case 0: - if(ledstate == BRI_LED_OFF) - CALL_PROTO(BRI, SET_LED, xbus, xpd, which_led, BRI_LED_ON); + DO_LED(xpd, which_led, BRI_LED_ON); break; case 500: - if(ledstate == BRI_LED_ON) - CALL_PROTO(BRI, SET_LED, xbus, xpd, which_led, BRI_LED_OFF); + DO_LED(xpd, which_led, BRI_LED_OFF); break; } } else if(priv->layer1_up) { @@ -790,18 +831,16 @@ static void handle_leds(xbus_t *xbus, xpd_t *xpd) switch(mod) { case 0: case 100: - if(ledstate == BRI_LED_OFF) - CALL_PROTO(BRI, SET_LED, xbus, xpd, which_led, BRI_LED_ON); + DO_LED(xpd, which_led, BRI_LED_ON); break; case 50: case 150: - if(ledstate == BRI_LED_ON) - CALL_PROTO(BRI, SET_LED, xbus, xpd, which_led, BRI_LED_OFF); + DO_LED(xpd, which_led, BRI_LED_OFF); break; } } else { if(priv->ledstate[which_led] != BRI_LED_ON) - CALL_PROTO(BRI, SET_LED, xbus, xpd, which_led, BRI_LED_ON); + DO_LED(xpd, which_led, BRI_LED_ON); } } @@ -854,7 +893,7 @@ static int BRI_card_tick(xbus_t *xbus, xpd_t *xpd) */ /* Detect T1 timer expiry on NT */ - if(xpd->type == XPD_TYPE_BRI_NT) { + if(IS_NT(xpd)) { if (priv->t1 > HFC_TIMER_OFF) { if (--priv->t1 == 0) { DBG("%s/%s: T1 Expired. Kick NT\n", xbus->busname, xpd->xpdname); @@ -882,8 +921,69 @@ static int BRI_card_close(xpd_t *xpd, lineno_t pos) return 0; } -static int BRI_span_startup(xpd_t *xpd) +/* + * Called only for 'span' keyword in /etc/zaptel.conf + */ +static int bri_spanconfig(struct zt_span *span, struct zt_lineconfig *lc) +{ + xpd_t *xpd = span->pvt; + const char *framingstr = ""; + const char *codingstr = ""; + const char *crcstr = ""; + + /* framing first */ + if (lc->lineconfig & ZT_CONFIG_B8ZS) + framingstr = "B8ZS"; + else if (lc->lineconfig & ZT_CONFIG_AMI) + framingstr = "AMI"; + else if (lc->lineconfig & ZT_CONFIG_HDB3) + framingstr = "HDB3"; + /* then coding */ + if (lc->lineconfig & ZT_CONFIG_ESF) + codingstr = "ESF"; + else if (lc->lineconfig & ZT_CONFIG_D4) + codingstr = "D4"; + else if (lc->lineconfig & ZT_CONFIG_CCS) + codingstr = "CCS"; + /* E1's can enable CRC checking */ + if (lc->lineconfig & ZT_CONFIG_CRC4) + crcstr = "CRC4"; + DBG("%s/%s[%s]: span=%d (%s) lbo=%d lineconfig=%s/%s/%s (0x%X) sync=%d\n", + xpd->xbus->busname, xpd->xpdname, + IS_NT(xpd)?"NT":"TE", + lc->span, + lc->name, + lc->lbo, + framingstr, codingstr, crcstr, + lc->lineconfig, + lc->sync); + /* + * FIXME: validate + */ + span->lineconfig = lc->lineconfig; + return 0; +} + +/* + * Set signalling type (if appropriate) + * Called from zaptel with spinlock held on chan. Must not call back + * zaptel functions. + */ +static int bri_chanconfig(struct zt_chan *chan, int sigtype) { + DBG("channel %d (%s) -> %s\n", chan->channo, chan->name, sig2str(sigtype)); + // FIXME: sanity checks: + // - should be supported (within the sigcap) + // - should not replace fxs <->fxo ??? (covered by previous?) + return 0; +} + +/* + * Called only for 'span' keyword in /etc/zaptel.conf + */ +static int bri_startup(struct zt_span *span) +{ + xpd_t *xpd = span->pvt; struct BRI_priv_data *priv; struct zt_chan *dchan; @@ -891,11 +991,13 @@ static int BRI_span_startup(xpd_t *xpd) priv = xpd->priv; BUG_ON(!priv); DBG("%s/%s: STARTUP\n", xpd->xbus->busname, xpd->xpdname); + // Turn on all channels + CALL_XMETHOD(XPD_STATE, xpd->xbus, xpd, 1); write_state_register(xpd, 0); /* Enable L1 state machine */ xpd_activation(xpd, 1); if(SPAN_REGISTERED(xpd)) { - dchan = &xpd->span.chans[2]; - xpd->span.flags |= ZT_FLAG_RUNNING; + dchan = &span->chans[2]; + span->flags |= ZT_FLAG_RUNNING; /* * Zaptel (wrongly) assume that D-Channel need HDLC decoding * and during zaptel registration override our flags. @@ -908,19 +1010,115 @@ static int BRI_span_startup(xpd_t *xpd) return 0; } -static int BRI_span_shutdown(xpd_t *xpd) +/* + * Called only for 'span' keyword in /etc/zaptel.conf + */ +static int bri_shutdown(struct zt_span *span) { + xpd_t *xpd = span->pvt; struct BRI_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; BUG_ON(!priv); DBG("%s/%s: SHUTDOWN\n", xpd->xbus->busname, xpd->xpdname); - if(xpd->type == XPD_TYPE_BRI_NT) + // Turn off all channels + CALL_XMETHOD(XPD_STATE, xpd->xbus, xpd, 0); + if(IS_NT(xpd)) xpd_activation(xpd, 0); return 0; } +static void BRI_card_pcm_fromspan(xbus_t *xbus, xpd_t *xpd, xpp_line_t wanted_lines, xpacket_t *pack) +{ + byte *pcm; + struct zt_chan *chans; + unsigned long flags; + int i; + int subunit; + xpp_line_t pcm_mask = 0; + + + 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); + if(!tmp_xpd || !tmp_xpd->card_present) + continue; + spin_lock_irqsave(&tmp_xpd->lock, flags); + chans = tmp_xpd->span.chans; + for_each_line(tmp_xpd, i) { + if(IS_SET(wanted_lines, i)) { + if(SPAN_REGISTERED(tmp_xpd)) { +#ifdef DEBUG_PCMTX + if(pcmtx >= 0 && pcmtx_chan == i) + memset((u_char *)pcm, pcmtx, ZT_CHUNKSIZE); + else +#endif + memcpy((u_char *)pcm, chans[i].writechunk, ZT_CHUNKSIZE); + // fill_beep((u_char *)pcm, tmp_xpd->addr.subunit, 2); + } else + memset((u_char *)pcm, 0x7F, ZT_CHUNKSIZE); + pcm += ZT_CHUNKSIZE; + } + } + pcm_mask |= (wanted_lines << SUBUNIT_PCM_SHIFT * subunit); + XPD_COUNTER(tmp_xpd, PCM_WRITE)++; + spin_unlock_irqrestore(&tmp_xpd->lock, flags); + } + RPACKET_FIELD(pack, GLOBAL, PCM_WRITE, lines) = pcm_mask; +} + +static void BRI_card_pcm_tospan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack) +{ + volatile u_char *r; + byte *pcm; + xpp_line_t pcm_mask; + unsigned long flags; + int subunit; + int i; + + /* + * Subunit 0 handle all other subunits + */ + if(xpd->addr.subunit != 0) + return; + pcm = RPACKET_FIELD(pack, GLOBAL, PCM_READ, pcm); + pcm_mask = RPACKET_FIELD(pack, GLOBAL, PCM_WRITE, lines); + for(subunit = 0; subunit < MAX_SUBUNIT; subunit++, pcm_mask >>= SUBUNIT_PCM_SHIFT) { + xpd_t *tmp_xpd; + + if(!pcm_mask) + break; /* optimize */ + tmp_xpd = xpd_byaddr(xbus, xpd->addr.unit, subunit); + if(!tmp_xpd || !tmp_xpd->card_present) + continue; + spin_lock_irqsave(&tmp_xpd->lock, flags); + if (tmp_xpd->timer_count & 1) { + /* First part */ + r = tmp_xpd->readchunk; + } else { + r = tmp_xpd->readchunk + ZT_CHUNKSIZE * CHANNELS_PERXPD; + } + for (i = 0; i < 2; i++, r += ZT_CHUNKSIZE) { + xpp_line_t tmp_mask = pcm_mask & (BIT(0) | BIT(1)); + + if(IS_SET(tmp_mask, i)) { + // memset((u_char *)r, 0x5A, ZT_CHUNKSIZE); // DEBUG + // fill_beep((u_char *)r, 1, 1); // DEBUG: BEEP + memcpy((u_char *)r, pcm, ZT_CHUNKSIZE); + pcm += ZT_CHUNKSIZE; + } + } + XPD_COUNTER(tmp_xpd, PCM_READ)++; + spin_unlock_irqrestore(&tmp_xpd->lock, flags); + } +} + /*---------------- BRI: HOST COMMANDS -------------------------------------*/ /* 0x0F */ HOSTCMD(BRI, REGISTER_REQUEST, byte chipsel, bool writing, bool do_subreg, byte regnum, byte subreg, byte data_low, byte data_high) @@ -934,7 +1132,7 @@ static int BRI_span_shutdown(xpd_t *xpd) DBG("NO XBUS\n"); return -EINVAL; } - XFRAME_NEW(xframe, pack, xbus, BRI, REGISTER_REQUEST, xpd->id); + XFRAME_NEW(xframe, pack, xbus, BRI, REGISTER_REQUEST, xpd->xbus_idx); #if 0 DBG("%s/%s/%d: %c%c R%02X S%02X %02X %02X\n", xbus->busname, xpd->xpdname, chipsel, @@ -951,7 +1149,7 @@ static int BRI_span_shutdown(xpd_t *xpd) REG_FIELD(reg_cmd, subreg) = subreg; REG_FIELD(reg_cmd, data_low) = data_low; REG_FIELD(reg_cmd, data_high) = data_high; - ret = xframe_send(xbus, xframe); + ret = send_cmd_frame(xbus, xframe); return ret; } @@ -975,24 +1173,29 @@ static int BRI_span_shutdown(xpd_t *xpd) return -ENOSYS; } -/* 0x33 */ HOSTCMD(BRI, SET_LED, bool red_led, enum led_state to_led_state) +/* 0x33 */ HOSTCMD(BRI, SET_LED, enum bri_led_names which_led, enum led_state to_led_state) { int ret = 0; - xframe_t *xframe; + xframe_t *xframe; xpacket_t *pack; struct bri_leds *bri_leds; struct BRI_priv_data *priv; - int which_led = (red_led) ? RED_LED : GREEN_LED; BUG_ON(!xbus); priv = xpd->priv; BUG_ON(!priv); - XFRAME_NEW(xframe, pack, xbus, BRI, SET_LED, xpd->id); +#if 0 + DBG("%s/%s: %s -> %d\n", + xbus->busname, xpd->xpdname, + (which_led)?"RED":"GREEN", + to_led_state); +#endif + XFRAME_NEW(xframe, pack, xbus, BRI, SET_LED, xpd->xbus_idx); bri_leds = &RPACKET_FIELD(pack, BRI, SET_LED, bri_leds); bri_leds->state = to_led_state; bri_leds->led_sel = which_led; pack->datalen = RPACKET_SIZE(BRI, SET_LED); - ret = xframe_send(xbus, xframe); + ret = send_cmd_frame(xbus, xframe); priv->ledstate[which_led] = to_led_state; return ret; } @@ -1033,8 +1236,8 @@ static void su_new_state(xpd_t *xpd, byte reg_x30) new_state.reg = reg_x30; priv->reg30_ticks = 0; priv->reg30_good = 1; - if((xpd->type == XPD_TYPE_BRI_TE && new_state.bits.v_su_sta == ST_TE_ACTIVATED) || - (xpd->type == XPD_TYPE_BRI_NT && new_state.bits.v_su_sta == ST_NT_ACTIVATED)) { + if((!IS_NT(xpd) && new_state.bits.v_su_sta == ST_TE_ACTIVATED) || + (IS_NT(xpd) && new_state.bits.v_su_sta == ST_NT_ACTIVATED)) { if(!priv->layer1_up) { layer1_state(xpd, 1); update_xpd_status(xpd, ZT_ALARM_NONE); @@ -1063,10 +1266,10 @@ static void su_new_state(xpd_t *xpd, byte reg_x30) return; /* same same */ DBG("%02X ---> %02X\n", priv->state_register.reg, reg_x30); DBG("%s/%s: %s%i\n", xbus->busname, xpd->xpdname, - (xpd->type == XPD_TYPE_BRI_NT)?"G":"F", + IS_NT(xpd)?"G":"F", new_state.bits.v_su_sta); - if(xpd->type == XPD_TYPE_BRI_TE) { + if(!IS_NT(xpd)) { /* disable T3 ? */ if ((new_state.bits.v_su_sta <= ST_TE_DEACTIVATED) || (new_state.bits.v_su_sta >= ST_TE_ACTIVATED)) { DBG("%s/%s: Disable T3 ?\n", xbus->busname, xpd->xpdname); @@ -1105,7 +1308,7 @@ static void su_new_state(xpd_t *xpd, byte reg_x30) break; } - } else if(xpd->type == XPD_TYPE_BRI_NT) { + } else if(IS_NT(xpd)) { switch (new_state.bits.v_su_sta) { case ST_NT_DEACTIVATED: /* G1 */ DBG("%s/%s: State ST_NT_DEACTIVATED (G1)\n", xbus->busname, xpd->xpdname); @@ -1144,8 +1347,9 @@ HANDLER_DEF(BRI, REGISTER_REPLY) int ret; if(!xpd) { - NOTICE("%s: received %s for non-existing xpd: %d\n", - __FUNCTION__, cmd->name, XPD_NUM(pack->addr)); + NOTICE("%s: received %s for non-existing %s(%1d%1d)\n", + __FUNCTION__, cmd->name, + xbus->busname, pack->addr.unit, pack->addr.subunit); return -EPROTO; } spin_lock_irqsave(&xpd->lock, flags); @@ -1192,7 +1396,7 @@ end: return 0; } -xproto_table_t PROTO_TABLE(BRI_NT) = { +static xproto_table_t PROTO_TABLE(BRI_NT) = { .owner = THIS_MODULE, .entries = { /* Table Card Opcode */ @@ -1208,9 +1412,9 @@ xproto_table_t PROTO_TABLE(BRI_NT) = { .card_zaptel_postregistration = BRI_card_zaptel_postregistration, .card_hooksig = BRI_card_hooksig, .card_tick = BRI_card_tick, + .card_pcm_fromspan = BRI_card_pcm_fromspan, + .card_pcm_tospan = BRI_card_pcm_tospan, .card_close = BRI_card_close, - .span_startup = BRI_span_startup, - .span_shutdown = BRI_span_shutdown, .RING = XPROTO_CALLER(BRI, RING), .RELAY_OUT = XPROTO_CALLER(BRI, RELAY_OUT), @@ -1220,7 +1424,7 @@ xproto_table_t PROTO_TABLE(BRI_NT) = { .packet_dump = bri_packet_dump, }; -xproto_table_t PROTO_TABLE(BRI_TE) = { +static xproto_table_t PROTO_TABLE(BRI_TE) = { .owner = THIS_MODULE, .entries = { /* Table Card Opcode */ @@ -1236,8 +1440,8 @@ xproto_table_t PROTO_TABLE(BRI_TE) = { .card_zaptel_postregistration = BRI_card_zaptel_postregistration, .card_hooksig = BRI_card_hooksig, .card_tick = BRI_card_tick, - .span_startup = BRI_span_startup, - .span_shutdown = BRI_span_shutdown, + .card_pcm_fromspan = BRI_card_pcm_fromspan, + .card_pcm_tospan = BRI_card_pcm_tospan, .RING = XPROTO_CALLER(BRI, RING), .RELAY_OUT = XPROTO_CALLER(BRI, RELAY_OUT), @@ -1269,7 +1473,6 @@ static int proc_bri_info_read(char *page, char **start, off_t off, int count, in unsigned long flags; xpd_t *xpd = data; struct BRI_priv_data *priv; - int led; DBG("\n"); if(!xpd) @@ -1281,7 +1484,7 @@ static int proc_bri_info_read(char *page, char **start, off_t off, int count, in if(priv->reg30_good) { len += sprintf(page + len, "%-5s ", (priv->layer1_up) ? "UP" : "DOWN"); len += sprintf(page + len, "%c%d %-15s -- fr_sync=%d t2_exp=%d info0=%d g2_g3=%d\n", - (xpd->type == XPD_TYPE_BRI_NT)?'G':'F', + IS_NT(xpd)?'G':'F', priv->state_register.bits.v_su_sta, xhfc_state_name(xpd->type, priv->state_register.bits.v_su_sta), priv->state_register.bits.v_su_fr_sync, @@ -1290,21 +1493,23 @@ static int proc_bri_info_read(char *page, char **start, off_t off, int count, in priv->state_register.bits.v_g2_g3); } else len += sprintf(page + len, "Unkown\n"); - if(xpd->type == XPD_TYPE_BRI_NT) + if(IS_NT(xpd)) len += sprintf(page + len, "T1 Timer: %d\n", priv->t1); len += sprintf(page + len, "Tick Counter: %d\n", priv->tick_counter); len += sprintf(page + len, "Last Poll Reply: %d ticks ago\n", priv->reg30_ticks); len += sprintf(page + len, "reg30_good=%d\n", priv->reg30_good); - len += sprintf(page + len, "D-Channel: TX=[%5d] RX=[%5d] BAD=[%5d] (%s)\n\n", - priv->dchan_tx_counter, priv->dchan_rx_counter, priv->dchan_rx_drops, - (priv->dchan_alive) ? "alive" : "dead"); - len += sprintf(page + len, "dchan_alive_ticks: %d\n", priv->dchan_alive_ticks); + len += sprintf(page + len, "D-Channel: TX=[%5d] RX=[%5d] BAD=[%5d] ", + priv->dchan_tx_counter, priv->dchan_rx_counter, priv->dchan_rx_drops); + if(priv->dchan_alive) { + len += sprintf(page + len, "(alive %d K-ticks)\n", + priv->dchan_alive_ticks/1000); + } else { + len += sprintf(page + len, "(dead)\n"); + } len += sprintf(page + len, "dchan_notx_ticks: %d\n", priv->dchan_notx_ticks); len += sprintf(page + len, "dchan_norx_ticks: %d\n", priv->dchan_norx_ticks); - for(led = 0; led < NUM_LEDS; led++) { - len += sprintf(page + len, "LED #%d\n", led); - len += sprintf(page + len, "\tledstate : %d\n", priv->ledstate[led]); - } + len += sprintf(page + len, "LED: %-10s = %d\n", "GREEN", priv->ledstate[GREEN_LED]); + len += sprintf(page + len, "LED: %-10s = %d\n", "RED", priv->ledstate[RED_LED]); len += sprintf(page + len, "\nDCHAN:\n"); len += sprintf(page + len, "\n"); spin_unlock_irqrestore(&xpd->lock, flags); @@ -1446,7 +1651,7 @@ static int handle_register_command(xpd_t *xpd, char *cmdline) BUG_ON(!priv); priv->requested_reply = regcmd; if(print_dbg) - dump_reg_cmd("BRI", ®cmd); + dump_reg_cmd("BRI", ®cmd, 1); ret = CALL_PROTO(BRI, REGISTER_REQUEST, xpd->xbus, xpd, REG_FIELD(®cmd, chipsel), writing, -- cgit v1.2.3