From bbdb7ec96737aee49feaa3d908438fc90fd27eea Mon Sep 17 00:00:00 2001 From: tzafrir Date: Thu, 16 Aug 2007 21:45:13 +0000 Subject: xpp rev. 4515: * BRI improvement: an 'nt_keepalive' parameter to xpd_bri forces a BRI_NT to retry a connection indefinitely (this is our default). When false it revert to the behaviour in changeset:4415 ("Bezeq like") * Improvement in DBG macros. The print_dbg parameter is now set of flags to debug. They are defined in zap_debug.h * Don't use Astribanks connected to USB1 interfaces Unless the user set the option usb1=1 for xpp_usb (r4504). * And some more documentation... * Include some of our variables in the default zaptel sample file. Merged revisions 2860 via svnmerge from https://origsvn.digium.com/svn/zaptel/branches/1.2 Merged revisions 2866 via svnmerge from https://origsvn.digium.com/svn/zaptel/branches/1.4 git-svn-id: http://svn.digium.com/svn/zaptel/trunk@2867 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- xpp/.version | 2 +- xpp/ChangeLog | 12 +- xpp/README.Astribank | 214 ++++++++++++++++++++++++++---- xpp/card_bri.c | 152 ++++++++++----------- xpp/card_fxo.c | 93 +++++++------ xpp/card_fxs.c | 106 +++++++-------- xpp/card_global.c | 115 ++++++++-------- xpp/utils/genzaptelconf | 2 +- xpp/utils/zconf/Zaptel/Config/Defaults.pm | 2 +- xpp/xbus-core.c | 88 ++++++------ xpp/xbus-sysfs.c | 12 +- xpp/xpd.h | 1 + xpp/xpp_usb.c | 62 ++++++--- xpp/xpp_zap.c | 137 ++++++++++++------- xpp/xpp_zap.h | 1 + xpp/xproto.c | 30 ++--- xpp/zap_debug.h | 26 ++-- zaptel.sysconfig | 14 ++ 18 files changed, 660 insertions(+), 409 deletions(-) diff --git a/xpp/.version b/xpp/.version index 5cd7489..b57e896 100644 --- a/xpp/.version +++ b/xpp/.version @@ -1 +1 @@ -trunk-r4416 +trunk-r4515 diff --git a/xpp/ChangeLog b/xpp/ChangeLog index 9e83c29..89ef689 100644 --- a/xpp/ChangeLog +++ b/xpp/ChangeLog @@ -1,11 +1,17 @@ -Tue Aug 14 2007 Tzafrir Cohen - xpp.r4416 - * Marked with no. 4416, to note that major changes after 4415 were - note merged yet. +Thu Aug 16 2007 Tzafrir Cohen - xpp.r4515 + * Don't use Astribanks connected to USB1 interfaces + Unless the user set the option usb1=1 for xpp_usb (r4504). * Demote the messages about PCM in non-PCM from notice to debug (r4501). * Fix sample BRI zapata.conf: NT instead of TE (r4498). * Disable FXS hardware DTMF detection by default (r4492). * Extra Zaptel PCI IDs (from Philipp Kempgen) (r4466). +Thu Aug 2 2007 Oron Peled - xpp.r4464 + * BRI improvement: an 'nt_keepalive' parameter to xpd_bri forces + a BRI_NT to retry a connection indefinitely (this is our default). + When false it revert to the behaviour in changeset:4415 ("Bezeq like") + * Improvement in DBG macros. The print_dbg parameter is now set of + flags to debug. They are defined in zap_debug.h Thu Jul 30 2007 Oron Peled - xpp.r4415 * Show Astribank 6+2 as 6/2 channels and not 8/8 channels. - Added as a "subtype" to the device type (r4391). diff --git a/xpp/README.Astribank b/xpp/README.Astribank index 18c5bbe..270ab39 100644 --- a/xpp/README.Astribank +++ b/xpp/README.Astribank @@ -323,6 +323,11 @@ Astribank 8 ^^^^^^^^^^^ fxoks=1-14 +Astribank 6FXS/2FXO +^^^^^^^^^^^^^^^^^^^^^^^ + fxoks=1-12 + fxsks=13-14 + Astribank 16: 8FXS/8FXO ^^^^^^^^^^^^^^^^^^^^^^^ fxoks=1-14 @@ -355,9 +360,9 @@ Astribank 8 signalling=fxo_ks ; The real analog ports: context=from-internal - ; echocancel=yes + echocancel=yes ; echocancelwhenbriged=yes - ; echotraining=9 + ; echotraining=no channel => 1-8 ; output ports: @@ -368,16 +373,42 @@ Astribank 8 context=astbank-input channel => 11-14 immediate=no - + +Astribank 6FXS/2FXO +^^^^^^^^^^^^^^^^^^^^^^^ + [channels] + signalling=fxo_ks + ; The real analog ports: + context=from-internal + echocancel=yes + ; echocancelwhenbriged=yes + ; echotraining=no + channel => 1-6 + + ; output ports: + context=astbank-output + channel => 7-8 + ; input ports: + immediate=yes + context=astbank-input + channel => 9-12 + immediate=no + + ; FXO ports + signalling=fxs_ks + context=from-pstn + callerid=asreceived + channel => 13-14 + Astribank 16: 8FXS/8FXO ^^^^^^^^^^^^^^^^^^^^^^^ [channels] signalling=fxo_ks ; The real analog ports: context=from-internal - ; echocancel=yes + echocancel=yes ; echocancelwhenbriged=yes - ; echotraining=9 + ; echotraining=no channel => 1-8 ; output ports: @@ -607,36 +638,165 @@ Useful Module Parameters Compile-time defaults of all modules can be shown as part of the description line for the parameter in the output of modinfo. -zap_autoreg: (xpp) -Register spans automatically (1) or not (0). Default: 1. -Unsetting this could be useful if you have several Astribanks and you -want to set their registration order manually using zt_registration in -the /proc interface. +zap_autoreg (xpp):: + Register spans automatically (1) or not (0). Default: 1. + Unsetting this could be useful if you have several Astribanks and you + want to set their registration order manually using zt_registration in + the /proc interface. -initdir: (xpp) -This is the directory containing the initialization scripts. -The default is /usr/share/zaptel . -Setting this value could be useful if that location is inconvenient for you. +initdir (xpp):: + This is the directory containing the initialization scripts. + The default is /usr/share/zaptel . + Setting this value could be useful if that location is inconvenient for you. -print_dbg: (all modules) +print_dbg (all modules):: It will make the driver print tons of debugging messages. Can be sometime even handy, but overly-verbose in the case of xpp_usb. Can be safely set/unset at run-time using /sys/modules . -vmwineon: (xpd_fxs) -Enable (1) or disable (0) sending voicemail message waiting indication -to phones with a neon lamp. Disabled by default as it requires extra -work of the driver even without such a phone and may potentially have -some strange sideeffects with some phones. +The value is a bitmask of several values. The value of 0 thus means "no +debug". The different bits are (as defined in xpp/zap_debug.h) - + + * 1: GENERAL - General debug comments. + * 2: PCM - PCM-related messages. Tend to flood logs. + * 4: LEDS - Anything related to blinking leds. When they appear, there + are many of them. + * 8: SYNC - Synchronization messages. Annoy as they happen regularily. + * 16: SIGNAL - Zaptel signalling and such. + * 32: PROC - procfs interface. + * 64: REGS - Reading and writing to regiaters. Tends to flood logs. + +Thus: + + echo 33 >/sys/modules/xpp/parameters/print_dbg + +sets the module xpp to print general debugging messages (1) and procfs +debuggingmessages (32). + +vmwineon (xpd_fxs):: + Enable (1) or disable (0) sending voicemail message waiting indication + to phones with a neon lamp. Disabled by default as it requires extra + work of the driver even without such a phone and may potentially have + some strange sideeffects with some phones. + +usb1 (xpp_usb):: + Enable (1) or disable (0) support of USB1 devices. Disabled by default. + + + + + USB1 devices are not well-tested. It seems that they don't work at all + for Astribank BRI. Generally they should work with the current code, but + we expect quality issues. Hence we would like to make it very clear that + you if you have a USB1 port (rather than a USB2 one, as recommended) you + will have to take an action to enable the device. + +poll intervals (various):: + There are various values which the driver occasionally polls the device + for. For instance ,the parameter poll_battery_interval for xpd_fxo + to poll the battery (if the telco is actually connected). + + + + + The value of those parameters is typically a number in milliseconds or 0 + to disable. Under normal operation there should be no reason to play + with such parameters. + +dtmf_detection (xpd_fxs):: + enable (1) or disable (0) support of DTMF detection by the Astribank. + Disabled by defualt and curently buggy. On some earlier versions (4372 - + 4415) it was enabled by default, and disabling it there may help. + + +TROUBLSHOOTING +-------------- +The following commands provide useful input for debugging: + +* USB level listing: one of the following: + + zaptel_hardware + + lsusb | grep e4e4 + + - Look for the USB product ID (the second number after e4e4). + - If you see *11x2* (e.g: 1152)- the FPGA firmware has been loaded. + Move on. + zaptel_hardware will also show you some more details if the driver + is loaded. lsusb will just list the device. + - If it shows something as product ID *11x0* - the USB firmware is not + loaded. Maybe you need fxload. Or maybe just unplug and replug the + device. + - If it shows a product ID of *11x1* - only the USB firmware is loaded + and not the FPGA firmware is loaded. If this is still the case after + a while - either the firmware loading has failed or you don't have + fpga_load - make sure you have libusb-dev(el) installed when + building Zaptel. + - It should list all of your Astribank devices. If it doesn't (for + more than a temporary while it takes for the initial firmware + loading) - Check that the Astribank is indeed connected. + +* Are Astribank spans registered? + + zt_registration + + - This should give useful results after the drivers have identified + and initialized your devices. + - It should list all Astribank XPDs. for each of them it should write + "on" or "off". If it is "off", the span has not been registered with + Zaptel and thus cannot yet be used. + - Registration is normally done as part of `/etc/init.d/zaptel start` . + To run it manually use the command: `zt_registration on` . + - Recall that we do not register Astribank spans automaitcally to give + you full control on the order of Zaptel spans. See the module + parameter **zap_autoreg** above to change that. + +* Zaptel-level listing: + + lszaptel + + cat /proc/zaptel/* + + - Those two are almost the same. lszaptel sorts more correctly if you + have more than 10 spans, and formats the output slightly nicer. + - Here you can see if your Zaptel spans and channels were loaded, if + they were configired by ztcfg and if they are in use (typically by + Asterisk). + - The fact that a file for a span is show whos that it has been + registered with Zaptel. A n example non-configured channel + (Astribank FXS): + + 42 FXS + + - When a channel has been configured with *ztcfg* (that applies + /etc/zaptel.conf), you will see an extra column for the signalling + of the channel. The same channel after it has been configured: + + 42 FXS FXOKS + + - If a program (which is typically asterisk uses it, you'll see: + + 42 FXS FXOKS (In use) + +* Information from Asterisk + + asterisk -rx 'zap show channels' + + - If you get the error connecting to asterisk.ctl: Asterisk is not + running. Maybe it has failed to load. This may be due to + misconfigured zapata.conf or whatever reason. Check + /var/log/asterisk/messages or /var/log/asterisk/full . + - If you get the error that "there is no such command": chan_zap.so is + not loaded. This can be one of two cases: + - chan_zap.so is not even built. To see that it is available run: + + ls -l /usr/lib/asterisk/modules/chan_zap.so -poll intervals: (various) -There are various values which the driver occasionally polls the device -for. For instance ,the parameter poll_battery_interval for xpd_fxo -to poll the battery (if the telco is actually connected). + - Your Asterisk has chan_zap.so but it is not loaded. Try loading + it: + + asterisk -rx 'load module chan_zap.so' -The value of those parameters is typically a number in milliseconds or 0 -to disable. Under normal operation there should be no reason to play -with such parameters. + - You see only "pseudo": in this case you have not configured any + channels. If you have configured channels in zapata.conf, you may + need to restart asterisk (or: `unload chan_zap.so` and + `load chan_zap.so`) to apply those changes. NOTE: XPP here does not stand for X Printing Panel, XML Pull Parser, diff --git a/xpp/card_bri.c b/xpp/card_bri.c index a2d4539..ce7b0c7 100644 --- a/xpp/card_bri.c +++ b/xpp/card_bri.c @@ -42,6 +42,7 @@ 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)"); +DEF_PARM_BOOL(nt_keepalive, 1, 0644, "Force BRI_NT to keep trying connection"); #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"); @@ -262,7 +263,7 @@ static void dump_hex_buf(xpd_t *xpd, char *msg, byte *buf, size_t len) debug_buf[0] = '\0'; for(i = 0; i < len && n < DEBUG_BUF_SIZE; i++) n += snprintf(&debug_buf[n], DEBUG_BUF_SIZE - n, "%02X ", buf[i]); - XPD_DBG(xpd, "%s[0..%d]: %s%s\n", msg, len-1, debug_buf, + XPD_DBG(GENERAL, xpd, "%s[0..%d]: %s%s\n", msg, len-1, debug_buf, (n >= DEBUG_BUF_SIZE)?"...":""); } @@ -310,7 +311,7 @@ static void layer1_state(xpd_t *xpd, bool up) if(priv->layer1_up == up) return; priv->layer1_up = up; - XPD_DBG(xpd, "STATE CHANGE: Layer1 %s\n", (up)?"UP":"DOWN"); + XPD_DBG(SIGNAL, xpd, "STATE CHANGE: Layer1 %s\n", (up)?"UP":"DOWN"); } static void dchan_state(xpd_t *xpd, bool up) @@ -323,10 +324,10 @@ static void dchan_state(xpd_t *xpd, bool up) if(priv->dchan_alive == up) return; if(up) { - XPD_DBG(xpd, "STATE CHANGE: D-Channel RUNNING\n"); + XPD_DBG(SIGNAL, xpd, "STATE CHANGE: D-Channel RUNNING\n"); priv->dchan_alive = 1; } else { - XPD_DBG(xpd, "STATE CHANGE: D-Channel STOPPED\n"); + XPD_DBG(SIGNAL, xpd, "STATE CHANGE: D-Channel STOPPED\n"); priv->dchan_rx_counter = priv->dchan_tx_counter = priv->dchan_rx_drops = 0; priv->dchan_alive = 0; priv->dchan_alive_ticks = 0; @@ -342,27 +343,27 @@ static void xpd_activation(xpd_t *xpd, bool on) priv = xpd->priv; BUG_ON(!priv); xbus = xpd->xbus; - XPD_DBG(xpd, "%s\n", (on)?"ON":"OFF"); + XPD_DBG(SIGNAL, xpd, "%s\n", (on)?"ON":"OFF"); switch(xpd->type) { case XPD_TYPE_BRI_TE: if(on) { - XPD_DBG(xpd, "HFC_L1_ACTIVATE_TE\n"); + XPD_DBG(SIGNAL, xpd, "HFC_L1_ACTIVATE_TE\n"); set_bit(HFC_L1_ACTIVATING, &priv->l1_flags); write_state_register(xpd, STA_ACTIVATE); priv->t3 = HFC_TIMER_T3; } else { - XPD_DBG(xpd, "HFC_L1_FORCE_DEACTIVATE_TE\n"); + XPD_DBG(SIGNAL, xpd, "HFC_L1_FORCE_DEACTIVATE_TE\n"); write_state_register(xpd, STA_DEACTIVATE); } break; case XPD_TYPE_BRI_NT: if(on) { - XPD_DBG(xpd, "HFC_L1_ACTIVATE_NT\n"); + XPD_DBG(SIGNAL, xpd, "HFC_L1_ACTIVATE_NT\n"); priv->t1 = TIMER_T1_MAX; set_bit(HFC_L1_ACTIVATING, &priv->l1_flags); write_state_register(xpd, STA_ACTIVATE | V_SU_SET_G2_G3); } else { - XPD_DBG(xpd, "HFC_L1_DEACTIVATE_NT\n"); + XPD_DBG(SIGNAL, xpd, "HFC_L1_DEACTIVATE_NT\n"); write_state_register(xpd, STA_DEACTIVATE); } break; @@ -408,7 +409,7 @@ static int rx_dchan(xpd_t *xpd, reg_cmd_t *regcmd) static int rate_limit; if((rate_limit++ % 1000) == 0) - XPD_DBG(xpd, "D-Chan unused\n"); + XPD_DBG(SIGNAL, xpd, "D-Chan unused\n"); dchan->bytes2receive = 0; dchan->bytes2transmit = 0; goto out; @@ -489,7 +490,7 @@ static int send_bri_multibyte(xpd_t *xpd, byte *buf, int len, bool eoftx) if(len > 0) { memcpy(REG_XDATA(reg_cmd), (byte *)buf, len); } else { - XPD_DBG(xpd, "Magic Packet (eoftx=%d)\n", eoftx); + XPD_DBG(REGS, xpd, "Magic Packet (eoftx=%d)\n", eoftx); } #ifdef XPP_DEBUGFS xbus_log(xbus, xpd, 1, reg_cmd, sizeof(reg_cmd_t)); /* 1 = TX */ @@ -523,7 +524,7 @@ static int tx_dchan(xpd_t *xpd) /* timer expired ? */ if (--priv->t3 == 0) { if ((rate_limit % 1003) >= 5) - XPD_DBG(xpd, "T3 expired\n"); + XPD_DBG(SIGNAL, xpd, "T3 expired\n"); priv->t3 = HFC_TIMER_OFF; clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags); xpd_activation(xpd, 0); /* Deactivate TE */ @@ -533,7 +534,7 @@ static int tx_dchan(xpd_t *xpd) /* timer expired ? */ if (--priv->t4 == 0) { if ((rate_limit % 1003) >= 5) - XPD_DBG(xpd, "T4 expired\n"); + XPD_DBG(SIGNAL, xpd, "T4 expired\n"); priv->t4 = HFC_TIMER_OFF; } } @@ -555,7 +556,7 @@ static int tx_dchan(xpd_t *xpd) return -EINVAL; } if(!test_bit(HFC_L1_ACTIVATED, &priv->l1_flags) && !test_bit(HFC_L1_ACTIVATING, &priv->l1_flags)) { - XPD_DBG(xpd, "Kick D-Channel transmiter\n"); + XPD_DBG(SIGNAL, xpd, "Want to transmit: Kick D-Channel transmiter\n"); xpd_activation(xpd, 1); return 0; } @@ -581,7 +582,7 @@ static xpd_t *BRI_card_new(xbus_t *xbus, int unit, int subunit, const xproto_tab xpd_t *xpd = NULL; int channels = min(3, CHANNELS_PERXPD); - XBUS_DBG(xbus, "\n"); + XBUS_DBG(GENERAL, xbus, "\n"); xpd = xpd_alloc(sizeof(struct BRI_priv_data), proto_table, channels); if(!xpd) return NULL; @@ -597,15 +598,15 @@ static void clean_proc(xbus_t *xbus, xpd_t *xpd) BUG_ON(!xpd); priv = xpd->priv; - XPD_DBG(xpd, "\n"); + XPD_DBG(PROC, xpd, "\n"); #ifdef CONFIG_PROC_FS if(priv->regfile) { - XPD_DBG(xpd, "Removing registers file\n"); + XPD_DBG(PROC, xpd, "Removing registers file\n"); priv->regfile->data = NULL; remove_proc_entry(PROC_REGISTER_FNAME, xpd->proc_xpd_dir); } if(priv->bri_info) { - XPD_DBG(xpd, "Removing xpd BRI_INFO file\n"); + XPD_DBG(PROC, xpd, "Removing xpd BRI_INFO file\n"); remove_proc_entry(PROC_BRI_INFO_FNAME, xpd->proc_xpd_dir); } #endif @@ -617,10 +618,10 @@ static int BRI_card_init(xbus_t *xbus, xpd_t *xpd) int ret = 0; BUG_ON(!xpd); - XPD_DBG(xpd, "\n"); + XPD_DBG(GENERAL, xpd, "\n"); priv = xpd->priv; #ifdef CONFIG_PROC_FS - XPD_DBG(xpd, "Creating BRI_INFO file\n"); + XPD_DBG(PROC, xpd, "Creating BRI_INFO file\n"); priv->bri_info = create_proc_read_entry(PROC_BRI_INFO_FNAME, 0444, xpd->proc_xpd_dir, proc_bri_info_read, xpd); if(!priv->bri_info) { XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_BRI_INFO_FNAME); @@ -628,7 +629,7 @@ static int BRI_card_init(xbus_t *xbus, xpd_t *xpd) goto err; } priv->bri_info->owner = THIS_MODULE; - XPD_DBG(xpd, "Creating registers file\n"); + XPD_DBG(PROC, xpd, "Creating registers file\n"); priv->regfile = create_proc_entry(PROC_REGISTER_FNAME, 0644, xpd->proc_xpd_dir); if(!priv->regfile) { XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_REGISTER_FNAME); @@ -648,7 +649,7 @@ static int BRI_card_init(xbus_t *xbus, xpd_t *xpd) * Force HOST sync *before* sending PCM */ CALL_PROTO(GLOBAL, SYNC_SOURCE, xbus, NULL, SYNC_MODE_HOST, 0); - XPD_DBG(xpd, "done\n"); + XPD_DBG(PROC, xpd, "done\n"); priv->initialized = 1; return 0; err: @@ -663,7 +664,7 @@ static int BRI_card_remove(xbus_t *xbus, xpd_t *xpd) BUG_ON(!xpd); priv = xpd->priv; - XPD_DBG(xpd, "\n"); + XPD_DBG(GENERAL, xpd, "\n"); clean_proc(xbus, xpd); return 0; } @@ -681,7 +682,7 @@ static int BRI_card_zaptel_preregistration(xpd_t *xpd, bool on) xbus = xpd->xbus; priv = xpd->priv; BUG_ON(!xbus); - XPD_DBG(xpd, "%s\n", (on)?"on":"off"); + XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off"); if(!on) { /* Nothing to do yet */ return 0; @@ -692,7 +693,7 @@ static int BRI_card_zaptel_preregistration(xpd_t *xpd, bool on) for_each_line(xpd, i) { struct zt_chan *cur_chan = &xpd->chans[i]; - XPD_DBG(xpd, "setting BRI channel %d\n", i); + XPD_DBG(GENERAL, xpd, "setting BRI channel %d\n", 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); @@ -756,13 +757,13 @@ static int BRI_card_zaptel_postregistration(xpd_t *xpd, bool on) xbus = xpd->xbus; priv = xpd->priv; BUG_ON(!xbus); - XPD_DBG(xpd, "%s\n", (on)?"on":"off"); + XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off"); return(0); } int BRI_card_hooksig(xbus_t *xbus, xpd_t *xpd, int pos, zt_txsig_t txsig) { - LINE_DBG(xpd, pos, "%s\n", txsig2str(txsig)); + LINE_DBG(SIGNAL, xpd, pos, "%s\n", txsig2str(txsig)); return 0; } @@ -847,9 +848,16 @@ static int BRI_card_tick(xbus_t *xbus, xpd_t *xpd) if(!priv->initialized) return 0; if(poll_interval != 0 && (priv->tick_counter % poll_interval) == 0) { - // XPD_DBG(xpd, "%d\n", priv->tick_counter); + // XPD_DBG(GENERAL, xpd, "%d\n", priv->tick_counter); priv->poll_counter++; CALL_PROTO(BRI, REGISTER_REQUEST, xbus, xpd, 0, 0, 0, A_SU_RD_STA, 0, 0, 0); + + if(IS_NT(xpd) && nt_keepalive && + !test_bit(HFC_L1_ACTIVATED, &priv->l1_flags) && + !test_bit(HFC_L1_ACTIVATING, &priv->l1_flags)) { + XPD_DBG(SIGNAL, xpd, "Kick NT D-Channel\n"); + xpd_activation(xpd, 1); + } } /* Detect D-Channel disconnect heuristic */ priv->dchan_notx_ticks++; @@ -876,10 +884,10 @@ static int BRI_card_tick(xbus_t *xbus, xpd_t *xpd) handle_leds(xbus, xpd); tx_dchan(xpd); /* Detect T1 timer expiry on NT */ - if(IS_NT(xpd)) { + if(IS_NT(xpd) && !nt_keepalive) { if (priv->t1 > HFC_TIMER_OFF) { if (--priv->t1 == 0) { - XPD_DBG(xpd, "T1 Expired. Kick NT\n"); + XPD_DBG(SIGNAL, xpd, "T1 Expired. Deactivate NT\n"); priv->t1 = HFC_TIMER_OFF; clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags); write_state_register(xpd, STA_DEACTIVATE); @@ -930,7 +938,7 @@ static int bri_spanconfig(struct zt_span *span, struct zt_lineconfig *lc) /* E1's can enable CRC checking */ if (lc->lineconfig & ZT_CONFIG_CRC4) crcstr = "CRC4"; - XPD_DBG(xpd, "[%s]: span=%d (%s) lbo=%d lineconfig=%s/%s/%s (0x%X) sync=%d\n", + XPD_DBG(GENERAL, xpd, "[%s]: span=%d (%s) lbo=%d lineconfig=%s/%s/%s (0x%X) sync=%d\n", IS_NT(xpd)?"NT":"TE", lc->span, lc->name, @@ -952,7 +960,7 @@ static int bri_spanconfig(struct zt_span *span, struct zt_lineconfig *lc) */ static int bri_chanconfig(struct zt_chan *chan, int sigtype) { - DBG("channel %d (%s) -> %s\n", chan->channo, chan->name, sig2str(sigtype)); + DBG(GENERAL, "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?) @@ -972,10 +980,10 @@ static int bri_startup(struct zt_span *span) priv = xpd->priv; BUG_ON(!priv); if(!xpd->xbus->hardware_exists) { - XPD_DBG(xpd, "Startup called by zaptel. No Hardware. Ignored\n"); + XPD_DBG(GENERAL, xpd, "Startup called by zaptel. No Hardware. Ignored\n"); return -ENODEV; } - XPD_DBG(xpd, "STARTUP\n"); + XPD_DBG(GENERAL, xpd, "STARTUP\n"); // Turn on all channels CALL_XMETHOD(XPD_STATE, xpd->xbus, xpd, 1); write_state_register(xpd, 0); /* Enable L1 state machine */ @@ -1007,10 +1015,10 @@ static int bri_shutdown(struct zt_span *span) priv = xpd->priv; BUG_ON(!priv); if(!xpd->xbus->hardware_exists) { - XPD_DBG(xpd, "Shutdown called by zaptel. No Hardware. Ignored\n"); + XPD_DBG(GENERAL, xpd, "Shutdown called by zaptel. No Hardware. Ignored\n"); return -ENODEV; } - XPD_DBG(xpd, "SHUTDOWN\n"); + XPD_DBG(GENERAL, xpd, "SHUTDOWN\n"); // Turn off all channels CALL_XMETHOD(XPD_STATE, xpd->xbus, xpd, 0); if(IS_NT(xpd)) @@ -1118,16 +1126,14 @@ static void BRI_card_pcm_tospan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack) reg_cmd_t *reg_cmd; if(!xbus) { - DBG("NO XBUS\n"); + DBG(GENERAL, "NO XBUS\n"); return -EINVAL; } XFRAME_NEW(xframe, pack, xbus, BRI, REGISTER_REQUEST, xpd->xbus_idx); -#if 0 - LINE_DBG(xpd, chipsel, "%c%c R%02X S%02X %02X %02X\n", + LINE_DBG(REGS, xpd, chipsel, "%c%c R%02X S%02X %02X %02X\n", (writing)?'W':'R', (do_subreg)?'S':'D', regnum, subreg, data_low, data_high); -#endif reg_cmd = &RPACKET_FIELD(pack, BRI, REGISTER_REQUEST, reg_cmd); reg_cmd->bytes = sizeof(*reg_cmd) - 1; // do not count the 'bytes' field REG_FIELD(reg_cmd, chipsel) = chipsel; @@ -1144,7 +1150,7 @@ static void BRI_card_pcm_tospan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack) /* 0x0F */ HOSTCMD(BRI, XPD_STATE, bool on) { BUG_ON(!xpd); - XPD_DBG(xpd, "%s\n", (on)?"ON":"OFF"); + XPD_DBG(GENERAL, xpd, "%s\n", (on)?"ON":"OFF"); xpd_activation(xpd, on); return 0; } @@ -1172,11 +1178,9 @@ static void BRI_card_pcm_tospan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack) BUG_ON(!xbus); priv = xpd->priv; BUG_ON(!priv); -#if 0 - XPD_DBG(xpd, "%s -> %d\n", + XPD_DBG(LEDS, xpd, "%s -> %d\n", (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; @@ -1191,7 +1195,7 @@ static int write_state_register(xpd_t *xpd, byte value) { int ret; - XPD_DBG(xpd, "value = 0x%02X\n", value); + XPD_DBG(REGS, xpd, "value = 0x%02X\n", value); ret = CALL_PROTO(BRI, REGISTER_REQUEST, xpd->xbus, xpd, 0, /* chipsel */ 1, /* writing */ @@ -1250,32 +1254,32 @@ static void su_new_state(xpd_t *xpd, byte reg_x30) } if (priv->state_register.bits.v_su_sta == new_state.bits.v_su_sta) return; /* same same */ - DBG("%02X ---> %02X\n", priv->state_register.reg, reg_x30); - XPD_DBG(xpd, "%s%i\n", IS_NT(xpd)?"G":"F", new_state.bits.v_su_sta); + DBG(SIGNAL, "%02X ---> %02X\n", priv->state_register.reg, reg_x30); + XPD_DBG(SIGNAL, xpd, "%s%i\n", IS_NT(xpd)?"G":"F", new_state.bits.v_su_sta); 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)) { - XPD_DBG(xpd, "Disable T3 ?\n"); + XPD_DBG(SIGNAL, xpd, "Disable T3 ?\n"); priv->t3 = HFC_TIMER_OFF; } switch (new_state.bits.v_su_sta) { case ST_TE_DEACTIVATED: /* F3 */ - XPD_DBG(xpd, "State ST_TE_DEACTIVATED (F3)\n"); + XPD_DBG(SIGNAL, xpd, "State ST_TE_DEACTIVATED (F3)\n"); if (test_and_clear_bit(HFC_L1_ACTIVATED, &priv->l1_flags)) priv->t4 = HFC_TIMER_T4; break; case ST_TE_SIGWAIT: /* F4 */ - XPD_DBG(xpd, "State ST_TE_SIGWAIT (F4)\n"); + XPD_DBG(SIGNAL, xpd, "State ST_TE_SIGWAIT (F4)\n"); break; case ST_TE_IDENT: /* F5 */ - XPD_DBG(xpd, "State ST_TE_IDENT (F5)\n"); + XPD_DBG(SIGNAL, xpd, "State ST_TE_IDENT (F5)\n"); break; case ST_TE_SYNCED: /* F6 */ - XPD_DBG(xpd, "State ST_TE_SYNCED (F6)\n"); + XPD_DBG(SIGNAL, xpd, "State ST_TE_SYNCED (F6)\n"); break; case ST_TE_ACTIVATED: /* F7 */ - XPD_DBG(xpd, "State ST_TE_ACTIVATED (F7)\n"); + XPD_DBG(SIGNAL, xpd, "State ST_TE_ACTIVATED (F7)\n"); if (priv->t4 > HFC_TIMER_OFF) priv->t4 = HFC_TIMER_OFF; clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags); @@ -1284,7 +1288,7 @@ static void su_new_state(xpd_t *xpd, byte reg_x30) break; case ST_TE_LOST_FRAMING: /* F8 */ - XPD_DBG(xpd, "State ST_TE_LOST_FRAMING (F8)\n"); + XPD_DBG(SIGNAL, xpd, "State ST_TE_LOST_FRAMING (F8)\n"); priv->t4 = HFC_TIMER_OFF; break; default: @@ -1295,22 +1299,22 @@ static void su_new_state(xpd_t *xpd, byte reg_x30) } else if(IS_NT(xpd)) { switch (new_state.bits.v_su_sta) { case ST_NT_DEACTIVATED: /* G1 */ - XPD_DBG(xpd, "State ST_NT_DEACTIVATED (G1)\n"); + XPD_DBG(SIGNAL, xpd, "State ST_NT_DEACTIVATED (G1)\n"); clear_bit(HFC_L1_ACTIVATED, &priv->l1_flags); priv->t1 = HFC_TIMER_OFF; break; case ST_NT_ACTIVATING: /* G2 */ - XPD_DBG(xpd, "State ST_NT_ACTIVATING (G2)\n"); + XPD_DBG(SIGNAL, xpd, "State ST_NT_ACTIVATING (G2)\n"); xpd_activation(xpd, 1); break; case ST_NT_ACTIVATED: /* G3 */ - XPD_DBG(xpd, "State ST_NT_ACTIVATED (G3)\n"); + XPD_DBG(SIGNAL, xpd, "State ST_NT_ACTIVATED (G3)\n"); clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags); set_bit(HFC_L1_ACTIVATED, &priv->l1_flags); priv->t1 = HFC_TIMER_OFF; break; case ST_NT_DEACTIVTING: /* G4 */ - XPD_DBG(xpd, "State ST_NT_DEACTIVTING (G4)\n"); + XPD_DBG(SIGNAL, xpd, "State ST_NT_DEACTIVTING (G4)\n"); priv->t1 = HFC_TIMER_OFF; break; default: @@ -1338,21 +1342,17 @@ HANDLER_DEF(BRI, REGISTER_REPLY) spin_lock_irqsave(&xpd->lock, flags); priv = xpd->priv; BUG_ON(!priv); -#if 0 if(REG_FIELD(info, do_subreg)) { - XPD_DBG(xpd, "REGISTER_REPLY: RS %02X %02X %02X\n", + XPD_DBG(REGS, xpd, "REGISTER_REPLY: RS %02X %02X %02X\n", REG_FIELD(info, regnum), REG_FIELD(info, subreg), REG_FIELD(info, data_low)); } else { if (REG_FIELD(info, regnum) != A_SU_RD_STA) - XPD_DBG(xpd, "REGISTER_REPLY: RD %02X %02X\n", + XPD_DBG(REGS, xpd, "REGISTER_REPLY: RD %02X %02X\n", REG_FIELD(info, regnum), REG_FIELD(info, data_low)); } -#endif if(info->multibyte) { -#if 0 - XPD_DBG(xpd, "Got Multibyte: %d bytes, eoframe: %d\n", + XPD_DBG(REGS, xpd, "Got Multibyte: %d bytes, eoframe: %d\n", info->bytes, info->eoframe); -#endif ret = rx_dchan(xpd, info); if (ret < 0) { priv->dchan_rx_drops++; @@ -1437,7 +1437,7 @@ static bool bri_packet_is_valid(xpacket_t *pack) { const xproto_entry_t *xe_nt = NULL; const xproto_entry_t *xe_te = NULL; - // DBG("\n"); + // DBG(GENERAL, "\n"); xe_nt = xproto_card_entry(&PROTO_TABLE(BRI_NT), pack->opcode); xe_te = xproto_card_entry(&PROTO_TABLE(BRI_TE), pack->opcode); return xe_nt != NULL || xe_te != NULL; @@ -1445,7 +1445,7 @@ static bool bri_packet_is_valid(xpacket_t *pack) static void bri_packet_dump(const char *msg, xpacket_t *pack) { - DBG("%s\n", msg); + DBG(GENERAL, "%s\n", msg); } /*------------------------- REGISTER Handling --------------------------*/ @@ -1456,7 +1456,7 @@ static int proc_bri_info_read(char *page, char **start, off_t off, int count, in xpd_t *xpd = data; struct BRI_priv_data *priv; - DBG("\n"); + DBG(PROC, "\n"); if(!xpd) return -ENODEV; spin_lock_irqsave(&xpd->lock, flags); @@ -1543,6 +1543,10 @@ static int handle_register_command(xpd_t *xpd, char *cmdline) struct BRI_priv_data *priv; byte buf[MAX_PROC_WRITE]; + BUG_ON(!xpd); + xbus = xpd->xbus; + priv = xpd->priv; + BUG_ON(!priv); if((p = strchr(cmdline, '#')) != NULL) /* Truncate comments */ *p = '\0'; if((p = strchr(cmdline, ';')) != NULL) /* Truncate comments */ @@ -1558,7 +1562,7 @@ static int handle_register_command(xpd_t *xpd, char *cmdline) &op, ®_type, ®_num, &subreg, &data, &xdata1, &xdata2); - // DBG("'%s': %d %c%c %02X %02X %02X\n", cmdline, chipsel, op, reg_type, reg_num, subreg, data); + XPD_DBG(PROC, xpd, "'%s': %d %c%c %02X %02X %02X\n", cmdline, chipsel, op, reg_type, reg_num, subreg, data); if(elements < 3) { // At least: chipsel, op, reg_type, reg_num ERR("Not enough arguments: (%d args) '%s'\n", elements, cmdline); return -EINVAL; @@ -1623,14 +1627,10 @@ static int handle_register_command(xpd_t *xpd, char *cmdline) regcmd.bytes = sizeof(regcmd) - 1; REG_FIELD(®cmd, read_request) = writing; REG_FIELD(®cmd, data_high) = 0; - BUG_ON(!xpd); - xbus = xpd->xbus; if(!down_read_trylock(&xbus->in_use)) { - XBUS_DBG(xbus, "Dropped packet. Is in_use\n"); + XBUS_DBG(GENERAL, xbus, "Dropped packet. Is in_use\n"); return -EBUSY; } - priv = xpd->priv; - BUG_ON(!priv); priv->requested_reply = regcmd; if(print_dbg) dump_reg_cmd("BRI", ®cmd, 1); @@ -1720,7 +1720,7 @@ static int proc_xpd_register_read(char *page, char **start, off_t off, int count int __init card_bri_startup(void) { - DBG("\n"); + DBG(GENERAL, "\n"); INFO("revision %s\n", XPP_VERSION); xproto_register(&PROTO_TABLE(BRI_NT)); @@ -1730,7 +1730,7 @@ int __init card_bri_startup(void) void __exit card_bri_cleanup(void) { - DBG("\n"); + DBG(GENERAL, "\n"); xproto_unregister(&PROTO_TABLE(BRI_NT)); xproto_unregister(&PROTO_TABLE(BRI_TE)); } diff --git a/xpp/card_fxo.c b/xpp/card_fxo.c index e568885..2063433 100644 --- a/xpp/card_fxo.c +++ b/xpp/card_fxo.c @@ -156,7 +156,7 @@ static int do_led(xpd_t *xpd, lineno_t chan, byte which, bool on) BIT_CLR(priv->ledstate[which], chan); } } - LINE_DBG(xpd, chan, "LED: which=%d -- %s\n", which, (on) ? "on" : "off"); + LINE_DBG(LEDS, xpd, chan, "LED: which=%d -- %s\n", which, (on) ? "on" : "off"); ret = DAA_DIRECT_REQUEST(xbus, xpd, chan, DAA_WRITE, 0x20, on); out: return ret; @@ -184,7 +184,7 @@ static void handle_fxo_leds(xpd_t *xpd) mod_value = DEFAULT_LED_PERIOD; /* safety value */ // led state is toggled if((timer_count % mod_value) == 0) { - LINE_DBG(xpd, i, "ledstate=%s\n", (IS_SET(priv->ledstate[color], i))?"ON":"OFF"); + LINE_DBG(LEDS, xpd, i, "ledstate=%s\n", (IS_SET(priv->ledstate[color], i))?"ON":"OFF"); if(!IS_SET(priv->ledstate[color], i)) { do_led(xpd, i, color, 1); } else { @@ -230,13 +230,13 @@ static void mark_ring(xpd_t *xpd, lineno_t pos, bool on, bool update_zap) BUG_ON(!priv); atomic_set(&priv->ring_debounce[pos], 0); /* Stop debouncing */ if(on && !xpd->ringing[pos]) { - LINE_DBG(xpd, pos, "START\n"); + LINE_DBG(SIGNAL, xpd, pos, "START\n"); xpd->ringing[pos] = 1; MARK_BLINK(priv, pos, LED_GREEN, LED_BLINK_RING); if(update_zap) update_zap_ring(xpd, pos, on); } else if(!on && xpd->ringing[pos]) { - LINE_DBG(xpd, pos, "STOP\n"); + LINE_DBG(SIGNAL, xpd, pos, "STOP\n"); xpd->ringing[pos] = 0; if(IS_BLINKING(priv, pos, LED_GREEN)) MARK_BLINK(priv, pos, LED_GREEN, 0); @@ -259,12 +259,12 @@ static int do_sethook(xpd_t *xpd, int pos, bool to_offhook) priv = xpd->priv; BUG_ON(!priv); if(!IS_SET(priv->battery, pos)) { - LINE_DBG(xpd, pos, "WARNING: called while battery is off\n"); + LINE_DBG(SIGNAL, xpd, pos, "WARNING: called while battery is off\n"); } spin_lock_irqsave(&xpd->lock, flags); mark_ring(xpd, pos, 0, 0); // No more rings value = (to_offhook) ? 0x09 : 0x08; /* Bit 3 is for CID */ - LINE_DBG(xpd, pos, "SETHOOK: value=0x%02X %s\n", value, (to_offhook)?"OFFHOOK":"ONHOOK"); + LINE_DBG(SIGNAL, xpd, pos, "SETHOOK: value=0x%02X %s\n", value, (to_offhook)?"OFFHOOK":"ONHOOK"); if(to_offhook) MARK_ON(priv, pos, LED_GREEN); else @@ -312,23 +312,23 @@ static void clean_proc(xbus_t *xbus, xpd_t *xpd) BUG_ON(!xpd); priv = xpd->priv; - XPD_DBG(xpd, "\n"); + XPD_DBG(PROC, xpd, "\n"); #ifdef CONFIG_PROC_FS if(priv->regfile) { - XPD_DBG(xpd, "Removing xpd DAA file\n"); + XPD_DBG(PROC, xpd, "Removing xpd DAA file\n"); remove_proc_entry(PROC_REGISTER_FNAME, xpd->proc_xpd_dir); priv->regfile->data = NULL; } #ifdef WITH_METERING if(priv->meteringfile) { - XPD_DBG(xpd, "Removing xpd metering tone file\n"); + XPD_DBG(PROC, xpd, "Removing xpd metering tone file\n"); priv->meteringfile->data = NULL; remove_proc_entry(PROC_METERING_FNAME, xpd->proc_xpd_dir); priv->meteringfile = NULL; } #endif if(priv->fxo_info) { - XPD_DBG(xpd, "Removing xpd FXO_INFO file\n"); + XPD_DBG(PROC, xpd, "Removing xpd FXO_INFO file\n"); remove_proc_entry(PROC_FXO_INFO_FNAME, xpd->proc_xpd_dir); priv->fxo_info = NULL; } @@ -344,7 +344,7 @@ static int FXO_card_init(xbus_t *xbus, xpd_t *xpd) BUG_ON(!xpd); priv = xpd->priv; #ifdef CONFIG_PROC_FS - XPD_DBG(xpd, "Creating FXO_INFO file\n"); + XPD_DBG(PROC, xpd, "Creating FXO_INFO file\n"); priv->fxo_info = create_proc_read_entry(PROC_FXO_INFO_FNAME, 0444, xpd->proc_xpd_dir, proc_fxo_info_read, xpd); if(!priv->fxo_info) { XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_FXO_INFO_FNAME); @@ -353,7 +353,7 @@ static int FXO_card_init(xbus_t *xbus, xpd_t *xpd) } priv->fxo_info->owner = THIS_MODULE; #ifdef WITH_METERING - XPD_DBG(xpd, "Creating Metering tone file\n"); + XPD_DBG(PROC, xpd, "Creating Metering tone file\n"); priv->meteringfile = create_proc_read_entry(PROC_METERING_FNAME, 0444, xpd->proc_xpd_dir, proc_xpd_metering_read, xpd); if(!priv->meteringfile) { @@ -363,7 +363,7 @@ static int FXO_card_init(xbus_t *xbus, xpd_t *xpd) } priv->meteringfile->owner = THIS_MODULE; #endif - XPD_DBG(xpd, "Creating DAAs file\n"); + XPD_DBG(PROC, xpd, "Creating DAAs file\n"); priv->regfile = create_proc_entry(PROC_REGISTER_FNAME, 0644, xpd->proc_xpd_dir); if(!priv->regfile) { XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_REGISTER_FNAME); @@ -382,7 +382,7 @@ static int FXO_card_init(xbus_t *xbus, xpd_t *xpd) for_each_line(xpd, i) { do_sethook(xpd, i, 0); } - XPD_DBG(xpd, "done\n"); + XPD_DBG(GENERAL, xpd, "done\n"); for_each_line(xpd, i) { do_led(xpd, i, LED_GREEN, 0); } @@ -408,7 +408,7 @@ static int FXO_card_remove(xbus_t *xbus, xpd_t *xpd) BUG_ON(!xpd); priv = xpd->priv; - XPD_DBG(xpd, "\n"); + XPD_DBG(GENERAL, xpd, "\n"); clean_proc(xbus, xpd); return 0; } @@ -424,11 +424,11 @@ static int FXO_card_zaptel_preregistration(xpd_t *xpd, bool on) BUG_ON(!xbus); priv = xpd->priv; BUG_ON(!priv); - XPD_DBG(xpd, "%s\n", (on)?"ON":"OFF"); + XPD_DBG(GENERAL, xpd, "%s\n", (on)?"ON":"OFF"); for_each_line(xpd, i) { struct zt_chan *cur_chan = &xpd->chans[i]; - XPD_DBG(xpd, "setting FXO channel %d\n", i); + XPD_DBG(GENERAL, xpd, "setting FXO channel %d\n", i); snprintf(cur_chan->name, MAX_CHANNAME, "XPP_FXO/%02d/%1d%1d/%d", xbus->num, xpd->addr.unit, xpd->addr.subunit, i); cur_chan->chanpos = i + 1; @@ -453,7 +453,7 @@ static int FXO_card_zaptel_postregistration(xpd_t *xpd, bool on) BUG_ON(!xbus); priv = xpd->priv; BUG_ON(!priv); - XPD_DBG(xpd, "%s\n", (on)?"ON":"OFF"); + XPD_DBG(GENERAL, xpd, "%s\n", (on)?"ON":"OFF"); for_each_line(xpd, i) { MARK_OFF(priv, i, LED_GREEN); msleep(2); @@ -469,7 +469,7 @@ int FXO_card_hooksig(xbus_t *xbus, xpd_t *xpd, int pos, zt_txsig_t txsig) priv = xpd->priv; BUG_ON(!priv); - LINE_DBG(xpd, pos, "%s\n", txsig2str(txsig)); + LINE_DBG(SIGNAL, xpd, pos, "%s\n", txsig2str(txsig)); BUG_ON(xpd->direction != TO_PSTN); /* XXX Enable hooksig for FXO XXX */ switch(txsig) { @@ -595,13 +595,13 @@ static int FXO_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long a BUG_ON(!xpd); switch (cmd) { case WCTDM_SET_ECHOTUNE: - XPD_DBG(xpd, "-- Setting echo registers: \n"); + XPD_DBG(GENERAL, xpd, "-- Setting echo registers: \n"); /* first off: check if this span is fxs. If not: -EINVALID */ if (copy_from_user(&echotune_data, (void __user *)arg, sizeof(echotune_data))) return -EFAULT; for (i = 0; i < ARRAY_SIZE(echotune_regs); i++) { - XPD_DBG(xpd, "Reg=0x%02X, data=0x%02X\n", echotune_regs[i], echotune_data[i]); + XPD_DBG(REGS, xpd, "Reg=0x%02X, data=0x%02X\n", echotune_regs[i], echotune_data[i]); ret = DAA_DIRECT_REQUEST(xpd->xbus, xpd, pos, DAA_WRITE, echotune_regs[i], echotune_data[i]); if (ret < 0) { LINE_NOTICE(xpd, pos, "Couldn't write %0x02X to register %0x02X\n", @@ -611,10 +611,10 @@ static int FXO_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long a msleep(1); } - XPD_DBG(xpd, "-- Set echo registers successfully\n"); + XPD_DBG(GENERAL, xpd, "-- Set echo registers successfully\n"); break; default: - LINE_DBG(xpd, pos, "Unknown command 0x%X.\n", cmd); + LINE_DBG(GENERAL, xpd, pos, "Unknown command 0x%X.\n", cmd); return -ENOTTY; } return 0; @@ -630,16 +630,14 @@ static int FXO_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long a reg_cmd_t *reg_cmd; if(!xbus) { - DBG("NO XBUS\n"); + DBG(REGS, "NO XBUS\n"); return -EINVAL; } XFRAME_NEW(xframe, pack, xbus, GLOBAL, REGISTER_REQUEST, xpd->xbus_idx); -#if 0 - LINE_DBG(xpd, chisel, "%c%c R%02X S%02X %02X %02X\n", + LINE_DBG(REGS, xpd, chipsel, "%c%c R%02X S%02X %02X %02X\n", (writing)?'W':'R', (do_subreg)?'S':'D', regnum, subreg, data_low, data_high); -#endif reg_cmd = &RPACKET_FIELD(pack, GLOBAL, REGISTER_REQUEST, reg_cmd); reg_cmd->bytes = sizeof(*reg_cmd) - 1; // do not count the 'bytes' field REG_FIELD(reg_cmd, chipsel) = chipsel; @@ -662,7 +660,7 @@ static /* 0x0F */ HOSTCMD(FXO, XPD_STATE, bool on) BUG_ON(!xpd); priv = xpd->priv; BUG_ON(!priv); - XPD_DBG(xpd, "%s\n", (on) ? "on" : "off"); + XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off"); return ret; } @@ -670,7 +668,7 @@ static /* 0x0F */ HOSTCMD(FXO, RING, lineno_t chan, bool on) { BUG_ON(!xbus); BUG_ON(!xpd); - LINE_DBG(xpd, chan, "%s\n", (on) ? "on" : "off"); + LINE_DBG(SIGNAL, xpd, chan, "%s\n", (on) ? "on" : "off"); return DAA_DIRECT_REQUEST(xbus, xpd, chan, DAA_WRITE, 0x40, (on)?0x04:0x01); } @@ -695,14 +693,14 @@ HANDLER_DEF(FXO, SIG_CHANGED) } priv = xpd->priv; BUG_ON(!priv); - XPD_DBG(xpd, "(PSTN) sig_toggles=0x%04X sig_status=0x%04X\n", sig_toggles, sig_status); + XPD_DBG(SIGNAL, xpd, "(PSTN) sig_toggles=0x%04X sig_status=0x%04X\n", sig_toggles, sig_status); spin_lock_irqsave(&xpd->lock, flags); for_each_line(xpd, i) { int debounce; if(IS_SET(sig_toggles, i)) { if(!IS_SET(priv->battery, i)) { - LINE_DBG(xpd, i, "SIG_CHANGED while battery is off.\n"); + LINE_DBG(SIGNAL, xpd, i, "SIG_CHANGED while battery is off.\n"); // FIXME: allow dialing without battery polling... // continue; } @@ -735,7 +733,7 @@ static void update_battery_status(xpd_t *xpd, byte data_low, lineno_t chipsel) * Check for battery voltage fluctuations */ if(IS_SET(priv->battery, chipsel) && priv->battery_debounce[chipsel]++ > BAT_DEBOUNCE) { - LINE_DBG(xpd, chipsel, "BATTERY OFF voltage=%d\n", bat); + LINE_DBG(SIGNAL, xpd, chipsel, "BATTERY OFF voltage=%d\n", bat); BIT_CLR(priv->battery, chipsel); if(SPAN_REGISTERED(xpd)) zt_qevent_lock(&xpd->chans[chipsel], ZT_EVENT_ALARM); @@ -744,7 +742,7 @@ static void update_battery_status(xpd_t *xpd, byte data_low, lineno_t chipsel) } else { priv->battery_debounce[chipsel] = 0; if(!IS_SET(priv->battery, chipsel)) { - LINE_DBG(xpd, chipsel, "BATTERY ON voltage=%d\n", bat); + LINE_DBG(SIGNAL, xpd, chipsel, "BATTERY ON voltage=%d\n", bat); BIT_SET(priv->battery, chipsel); if(SPAN_REGISTERED(xpd)) zt_qevent_lock(&xpd->chans[chipsel], ZT_EVENT_NOALARM); @@ -770,7 +768,7 @@ static void update_battery_status(xpd_t *xpd, byte data_low, lineno_t chipsel) BIT_CLR(priv->polarity, chipsel); priv->polarity_counter[chipsel] = 0; /* Inform Zaptel */ - LINE_DBG(xpd, chipsel, "Send ZT_EVENT_POLARITY\n"); + LINE_DBG(GENERAL, xpd, chipsel, "Send ZT_EVENT_POLARITY\n"); zt_qevent_lock(&xpd->chans[chipsel], ZT_EVENT_POLARITY); #if 0 /* @@ -799,7 +797,7 @@ static void update_power_denial(xpd_t *xpd, byte data_low, lineno_t chipsel) /* Current dropped */ priv->current_counter[chipsel]++; if (priv->current_counter[chipsel] * poll_battery_interval >= POWER_DENIAL_TIME) { - LINE_DBG(xpd, chipsel, "Power Denial Hangup\n"); + LINE_DBG(SIGNAL, xpd, chipsel, "Power Denial Hangup\n"); priv->current_counter[chipsel] = 0; do_sethook(xpd, chipsel, 0); update_line_status(xpd, chipsel, 0); @@ -821,7 +819,7 @@ static void update_metering_state(xpd_t *xpd, byte data_low, lineno_t chipsel) priv = xpd->priv; BUG_ON(!priv); old_metering_tone = IS_SET(priv->metering_tone_state, chipsel); - LINE_DBG(xpd, chipsel, "METERING: %s [dL=0x%X] (%d)\n", + LINE_DBG(SIGNAL, xpd, chipsel, "METERING: %s [dL=0x%X] (%d)\n", (metering_tone) ? "ON" : "OFF", data_low, priv->metering_count[chipsel]); if(metering_tone && !old_metering_tone) { @@ -864,12 +862,11 @@ HANDLER_DEF(FXO, DAA_REPLY) break; #endif } -#if 0 - XPD_DBG(xpd, "DAA_REPLY: %s reg_num=0x%X, dataL=0x%X dataH=0x%X\n", - (info->size == 3)?"I":"D", - info->reg_num, info->data_low, info->data_high); -#endif - + LINE_DBG(REGS, xpd, chipsel, "DAA_REPLY: %c reg_num=0x%X, dataL=0x%X dataH=0x%X\n", + ((info->bytes == 3)?'I':'D'), + REG_FIELD(info, regnum), + REG_FIELD(info, data_low), + REG_FIELD(info, data_high)); /* Update /proc info only if reply relate to the last slic read request */ if( REG_FIELD(&xpd->requested_reply, regnum) == REG_FIELD(info, regnum) && @@ -915,14 +912,14 @@ static bool fxo_packet_is_valid(xpacket_t *pack) { const xproto_entry_t *xe; - //DBG("\n"); + //DBG(GENERAL, "\n"); xe = xproto_card_entry(&PROTO_TABLE(FXO), pack->opcode); return xe != NULL; } static void fxo_packet_dump(const char *msg, xpacket_t *pack) { - DBG("%s\n", msg); + DBG(GENERAL, "%s\n", msg); } /*------------------------- DAA Handling --------------------------*/ @@ -1014,6 +1011,8 @@ static int handle_register_command(xpd_t *xpd, char *cmdline) xbus_t *xbus; int ret; + BUG_ON(!xpd); + xbus = xpd->xbus; if((p = strchr(cmdline, '#')) != NULL) /* Truncate comments */ *p = '\0'; if((p = strchr(cmdline, ';')) != NULL) /* Truncate comments */ @@ -1027,7 +1026,7 @@ static int handle_register_command(xpd_t *xpd, char *cmdline) &chipsel, &op, ®_type, ®_num, &data_low); - // DBG("'%s': %d %c%c %02X %02X %02X\n", cmdline, chipsel, op, reg_type, reg_num, data_low); + XPD_DBG(PROC, xpd, "'%s': %d %c%c %02X %02X\n", cmdline, chipsel, op, reg_type, reg_num, data_low); if(elements < 4) { // At least: chipsel, op, reg_type, reg_num ERR("Not enough arguments: (%d args) '%s'\n", elements, cmdline); return -EINVAL; @@ -1071,10 +1070,8 @@ static int handle_register_command(xpd_t *xpd, char *cmdline) REG_FIELD(®cmd, data_low) = data_low; REG_FIELD(®cmd, data_high) = 0; REG_FIELD(®cmd, read_request) = writing; - BUG_ON(!xpd); - xbus = xpd->xbus; if(!down_read_trylock(&xbus->in_use)) { - XBUS_DBG(xbus, "Dropped packet. Is in_use\n"); + XBUS_DBG(GENERAL, xbus, "Dropped packet. Is in_use\n"); return -EBUSY; } xpd->requested_reply = regcmd; diff --git a/xpp/card_fxs.c b/xpp/card_fxs.c index fbbcab4..67cff65 100644 --- a/xpp/card_fxs.c +++ b/xpp/card_fxs.c @@ -152,7 +152,7 @@ static int linefeed_control(xbus_t *xbus, xpd_t *xpd, lineno_t chan, enum fxs_st struct FXS_priv_data *priv; priv = xpd->priv; - LINE_DBG(xpd, chan, "value=0x%02X\n", value); + LINE_DBG(SIGNAL, xpd, chan, "value=0x%02X\n", value); priv->lasttxhook[chan] = value; return SLIC_DIRECT_REQUEST(xbus, xpd, chan, SLIC_WRITE, 0x40, value); } @@ -163,7 +163,7 @@ static int do_chan_power(xbus_t *xbus, xpd_t *xpd, lineno_t chan, bool on) BUG_ON(!xbus); BUG_ON(!xpd); - LINE_DBG(xpd, chan, "%s\n", (on) ? "up" : "down"); + LINE_DBG(SIGNAL, xpd, chan, "%s\n", (on) ? "up" : "down"); return SLIC_DIRECT_REQUEST(xbus, xpd, chan, SLIC_WRITE, 0x42, value); } @@ -222,7 +222,7 @@ static int do_led(xpd_t *xpd, lineno_t chan, byte which, bool on) BIT_CLR(priv->ledstate[which], chan); } } - LINE_DBG(xpd, chan, "LED: which=%d -- %s\n", which, (on) ? "on" : "off"); + LINE_DBG(LEDS, xpd, chan, "LED: which=%d -- %s\n", which, (on) ? "on" : "off"); value = BIT(2) | BIT(3); value |= ((BIT(5) | BIT(6) | BIT(7)) & ~led_register_mask[which]); if(on) @@ -254,7 +254,7 @@ static void handle_fxs_leds(xpd_t *xpd) mod_value = DEFAULT_LED_PERIOD; /* safety value */ // led state is toggled if((timer_count % mod_value) == 0) { - LINE_DBG(xpd, i, "ledstate=%s\n", (IS_SET(priv->ledstate[color], i))?"ON":"OFF"); + LINE_DBG(LEDS, xpd, i, "ledstate=%s\n", (IS_SET(priv->ledstate[color], i))?"ON":"OFF"); if(!IS_SET(priv->ledstate[color], i)) { do_led(xpd, i, color, 1); } else { @@ -290,7 +290,7 @@ static int metering_gen(xpd_t *xpd, lineno_t chan, bool on) { byte value = (on) ? 0x94 : 0x00; - LINE_DBG(xpd, chan, "METERING Generate: %s\n", (on)?"ON":"OFF"); + LINE_DBG(SIGNAL, xpd, chan, "METERING Generate: %s\n", (on)?"ON":"OFF"); return SLIC_DIRECT_REQUEST(xpd->xbus, xpd, chan, SLIC_WRITE, 0x23, value); } #endif @@ -314,7 +314,7 @@ static xpd_t *FXS_card_new(xbus_t *xbus, int unit, int subunit, const xproto_tab if(!xpd) return NULL; if(unit == 0) { - XBUS_DBG(xbus, "First XPD detected. Initialize digital outputs/inputs\n"); + XBUS_DBG(GENERAL, xbus, "First XPD detected. Initialize digital outputs/inputs\n"); xpd->digital_outputs = BITMASK(LINES_DIGI_OUT) << regular_channels; xpd->digital_inputs = BITMASK(LINES_DIGI_INP) << (regular_channels + LINES_DIGI_OUT); } @@ -332,21 +332,21 @@ static void clean_proc(xbus_t *xbus, xpd_t *xpd) priv = xpd->priv; #ifdef CONFIG_PROC_FS if(priv->regfile) { - XPD_DBG(xpd, "Removing xpd SLIC file\n"); + XPD_DBG(PROC, xpd, "Removing xpd SLIC file\n"); priv->regfile->data = NULL; remove_proc_entry(PROC_REGISTER_FNAME, xpd->proc_xpd_dir); priv->regfile = NULL; } #ifdef WITH_METERING if(priv->meteringfile) { - XPD_DBG(xpd, "Removing xpd metering tone file\n"); + XPD_DBG(PROC, xpd, "Removing xpd metering tone file\n"); priv->meteringfile->data = NULL; remove_proc_entry(PROC_METERING_FNAME, xpd->proc_xpd_dir); priv->meteringfile = NULL; } #endif if(priv->fxs_info) { - XPD_DBG(xpd, "Removing xpd FXS_INFO file\n"); + XPD_DBG(PROC, xpd, "Removing xpd FXS_INFO file\n"); remove_proc_entry(PROC_FXS_INFO_FNAME, xpd->proc_xpd_dir); priv->fxs_info = NULL; } @@ -362,7 +362,7 @@ static int FXS_card_init(xbus_t *xbus, xpd_t *xpd) BUG_ON(!xpd); priv = xpd->priv; #ifdef CONFIG_PROC_FS - XPD_DBG(xpd, "Creating FXS_INFO file\n"); + XPD_DBG(PROC, xpd, "Creating FXS_INFO file\n"); priv->fxs_info = create_proc_read_entry(PROC_FXS_INFO_FNAME, 0444, xpd->proc_xpd_dir, proc_fxs_info_read, xpd); if(!priv->fxs_info) { XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_FXS_INFO_FNAME); @@ -371,7 +371,7 @@ static int FXS_card_init(xbus_t *xbus, xpd_t *xpd) } priv->fxs_info->owner = THIS_MODULE; #ifdef WITH_METERING - XPD_DBG(xpd, "Creating Metering tone file\n"); + XPD_DBG(PROC, xpd, "Creating Metering tone file\n"); priv->meteringfile = create_proc_entry(PROC_METERING_FNAME, 0200, xpd->proc_xpd_dir); if(!priv->meteringfile) { XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_METERING_FNAME); @@ -383,7 +383,7 @@ static int FXS_card_init(xbus_t *xbus, xpd_t *xpd) priv->meteringfile->read_proc = NULL; priv->meteringfile->data = xpd; #endif - XPD_DBG(xpd, "Creating SLICs file\n"); + XPD_DBG(PROC, xpd, "Creating SLICs file\n"); priv->regfile = create_proc_entry(PROC_REGISTER_FNAME, 0644, xpd->proc_xpd_dir); if(!priv->regfile) { XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_REGISTER_FNAME); @@ -408,7 +408,7 @@ static int FXS_card_init(xbus_t *xbus, xpd_t *xpd) ret = SLIC_DIRECT_REQUEST(xbus, xpd, ALL_CHANS, SLIC_WRITE, 0x22, 0x00); /* Ringing Oscilator Control */ if(ret < 0) goto err; - XPD_DBG(xpd, "done\n"); + XPD_DBG(GENERAL, xpd, "done\n"); for_each_line(xpd, i) { do_led(xpd, i, LED_GREEN, 0); do_led(xpd, i, LED_RED, 0); @@ -436,7 +436,7 @@ static int FXS_card_remove(xbus_t *xbus, xpd_t *xpd) BUG_ON(!xpd); priv = xpd->priv; - XPD_DBG(xpd, "\n"); + XPD_DBG(GENERAL, xpd, "\n"); clean_proc(xbus, xpd); return 0; } @@ -452,11 +452,11 @@ static int FXS_card_zaptel_preregistration(xpd_t *xpd, bool on) BUG_ON(!xbus); priv = xpd->priv; BUG_ON(!priv); - XPD_DBG(xpd, "%s\n", (on)?"on":"off"); + XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off"); for_each_line(xpd, i) { struct zt_chan *cur_chan = &xpd->chans[i]; - XPD_DBG(xpd, "setting FXS channel %d\n", i); + XPD_DBG(GENERAL, xpd, "setting FXS channel %d\n", i); if(IS_SET(xpd->digital_outputs, i)) { snprintf(cur_chan->name, MAX_CHANNAME, "XPP_OUT/%02d/%1d%1d/%d", xbus->num, xpd->addr.unit, xpd->addr.subunit, i); @@ -489,7 +489,7 @@ static int FXS_card_zaptel_postregistration(xpd_t *xpd, bool on) BUG_ON(!xbus); priv = xpd->priv; BUG_ON(!priv); - XPD_DBG(xpd, "%s\n", (on)?"on":"off"); + XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off"); for_each_line(xpd, i) { MARK_OFF(priv, i, LED_GREEN); msleep(2); @@ -507,11 +507,11 @@ int FXS_card_hooksig(xbus_t *xbus, xpd_t *xpd, int pos, zt_txsig_t txsig) struct zt_chan *chan = NULL; enum fxs_state txhook; - LINE_DBG(xpd, pos, "%s\n", txsig2str(txsig)); + LINE_DBG(SIGNAL, xpd, pos, "%s\n", txsig2str(txsig)); priv = xpd->priv; BUG_ON(xpd->direction != TO_PHONE); if (IS_SET(xpd->digital_inputs, pos)) { - LINE_DBG(xpd, pos, "Ignoring signal sent to digital input line\n"); + LINE_DBG(SIGNAL, xpd, pos, "Ignoring signal sent to digital input line\n"); return 0; } if(SPAN_REGISTERED(xpd)) @@ -523,7 +523,7 @@ int FXS_card_hooksig(xbus_t *xbus, xpd_t *xpd, int pos, zt_txsig_t txsig) BIT_CLR(priv->search_fsk_pattern, pos); pcm_recompute(xpd, xpd->offhook | xpd->cid_on); if(IS_SET(xpd->digital_outputs, pos)) { - LINE_DBG(xpd, pos, "digital output OFF\n"); + LINE_DBG(SIGNAL, xpd, pos, "digital output OFF\n"); ret = CALL_XMETHOD(RELAY_OUT, xpd->xbus, xpd, pos-8, 0); return ret; } @@ -531,7 +531,7 @@ int FXS_card_hooksig(xbus_t *xbus, xpd_t *xpd, int pos, zt_txsig_t txsig) /* * Restore state after KEWL hangup. */ - LINE_DBG(xpd, pos, "KEWL STOP\n"); + LINE_DBG(SIGNAL, xpd, pos, "KEWL STOP\n"); linefeed_control(xbus, xpd, pos, FXS_LINE_POL_ACTIVE); if(IS_SET(xpd->offhook, pos)) MARK_ON(priv, pos, LED_GREEN); @@ -580,14 +580,14 @@ int FXS_card_hooksig(xbus_t *xbus, xpd_t *xpd, int pos, zt_txsig_t txsig) BIT_CLR(priv->search_fsk_pattern, pos); pcm_recompute(xpd, xpd->offhook | xpd->cid_on); if(IS_SET(xpd->digital_outputs, pos)) { - LINE_DBG(xpd, pos, "%s digital output ON\n", txsig2str(txsig)); + LINE_DBG(SIGNAL, xpd, pos, "%s digital output ON\n", txsig2str(txsig)); ret = CALL_XMETHOD(RELAY_OUT, xpd->xbus, xpd, pos-8, 1); return ret; } ret = CALL_XMETHOD(RING, xbus, xpd, pos, 1); // RING on break; case ZT_TXSIG_KEWL: - LINE_DBG(xpd, pos, "KEWL START\n"); + LINE_DBG(SIGNAL, xpd, pos, "KEWL START\n"); linefeed_control(xbus, xpd, pos, FXS_LINE_OPEN); MARK_OFF(priv, pos, LED_GREEN); break; @@ -625,7 +625,7 @@ static int FXS_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long a case ZT_ONHOOKTRANSFER: if (get_user(val, (int __user *)arg)) return -EFAULT; - LINE_DBG(xpd, pos, "ZT_ONHOOKTRANSFER (%d millis)\n", val); + LINE_DBG(SIGNAL, xpd, pos, "ZT_ONHOOKTRANSFER (%d millis)\n", val); BUG_ON(pos == ALL_CHANS); if (IS_SET(xpd->digital_inputs | xpd->digital_outputs, pos)) return 0; /* Nothing to do */ @@ -638,7 +638,7 @@ static int FXS_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long a case ZT_TONEDETECT: if (get_user(val, (int __user *)arg)) return -EFAULT; - LINE_DBG(xpd, pos, "ZT_TONEDETECT: %s %s (dtmf_detection=%s)\n", + LINE_DBG(SIGNAL, xpd, pos, "ZT_TONEDETECT: %s %s (dtmf_detection=%s)\n", (val & ZT_TONEDETECT_ON) ? "ON" : "OFF", (val & ZT_TONEDETECT_MUTE) ? "MUTE" : "NO-MUTE", (dtmf_detection ? "YES" : "NO")); @@ -670,7 +670,7 @@ static int set_vm_led_mode(xbus_t *xbus, xpd_t *xpd, int pos, int on) BUG_ON(!xbus); BUG_ON(!xpd); - LINE_DBG(xpd, pos, "%s%s\n", (on)?"ON":"OFF", (vmwineon)?"":" (Ignored)"); + LINE_DBG(SIGNAL, xpd, pos, "%s%s\n", (on)?"ON":"OFF", (vmwineon)?"":" (Ignored)"); if (!vmwineon) return 0; if (on) { @@ -712,7 +712,7 @@ static void start_stop_vm_led(xbus_t *xbus, xpd_t *xpd, lineno_t pos) return; priv = xpd->priv; on = IS_SET(xpd->msg_waiting, pos); - LINE_DBG(xpd, pos, "%s\n", (on)?"ON":"OFF"); + LINE_DBG(SIGNAL, xpd, pos, "%s\n", (on)?"ON":"OFF"); set_vm_led_mode(xbus, xpd, pos, on); do_chan_power(xbus, xpd, pos, on); linefeed_control(xbus, xpd, pos, (on) ? FXS_LINE_RING : priv->idletxhookstate[pos]); @@ -726,7 +726,7 @@ static int FXS_card_open(xpd_t *xpd, lineno_t chan) BUG_ON(!xpd); priv = xpd->priv; is_offhook = IS_SET(xpd->offhook, chan); - LINE_DBG(xpd, chan, "(is %shook)\n", (is_offhook)?"off":"on"); + LINE_DBG(GENERAL, xpd, chan, "(is %shook)\n", (is_offhook)?"off":"on"); /* * Delegate updating zaptel to FXS_card_tick(): * The problem is that zt_hooksig() is spinlocking the channel and @@ -742,7 +742,7 @@ static int FXS_card_close(xpd_t *xpd, lineno_t chan) struct FXS_priv_data *priv; BUG_ON(!xpd); - LINE_DBG(xpd, chan, "\n"); + LINE_DBG(GENERAL, xpd, chan, "\n"); priv = xpd->priv; priv->idletxhookstate[chan] = FXS_LINE_POL_ACTIVE; return 0; @@ -851,7 +851,7 @@ static void detect_vmwi(xpd_t *xpd) if(writechunk[0] != 0x7F && writechunk[0] != 0) { int j; - LINE_DBG(xpd, pos, "MSG:"); + LINE_DBG(GENERAL, xpd, pos, "MSG:"); for(j = 0; j < ZT_CHUNKSIZE; j++) { if(print_dbg) printk(" %02X", writechunk[j]); @@ -865,11 +865,11 @@ static void detect_vmwi(xpd_t *xpd) else if(unlikely(IS_SET(priv->found_fsk_pattern, i))) { BIT_CLR(priv->found_fsk_pattern, i); if(unlikely(mem_equal(writechunk, FSK_ON_PATTERN, ZT_CHUNKSIZE))) { - LINE_DBG(xpd, i, "MSG WAITING ON\n"); + LINE_DBG(SIGNAL, xpd, i, "MSG WAITING ON\n"); BIT_SET(xpd->msg_waiting, i); start_stop_vm_led(xbus, xpd, i); } else if(unlikely(mem_equal(writechunk, FSK_OFF_PATTERN, ZT_CHUNKSIZE))) { - LINE_DBG(xpd, i, "MSG WAITING OFF\n"); + LINE_DBG(SIGNAL, xpd, i, "MSG WAITING OFF\n"); BIT_CLR(xpd->msg_waiting, i); start_stop_vm_led(xbus, xpd, i); } else { @@ -940,16 +940,14 @@ static int FXS_card_tick(xbus_t *xbus, xpd_t *xpd) reg_cmd_t *reg_cmd; if(!xbus) { - DBG("NO XBUS\n"); + DBG(GENERAL, "NO XBUS\n"); return -EINVAL; } XFRAME_NEW(xframe, pack, xbus, GLOBAL, REGISTER_REQUEST, xpd->xbus_idx); -#if 0 - LINE_DBG(xpd, chipsel, "%c%c R%02X S%02X %02X %02X\n", + LINE_DBG(REGS, xpd, chipsel, "%c%c R%02X S%02X %02X %02X\n", (writing)?'W':'R', (do_subreg)?'S':'D', regnum, subreg, data_low, data_high); -#endif reg_cmd = &RPACKET_FIELD(pack, GLOBAL, REGISTER_REQUEST, reg_cmd); reg_cmd->bytes = sizeof(*reg_cmd) - 1; // do not count the 'bytes' field REG_FIELD(reg_cmd, chipsel) = chipsel; @@ -974,7 +972,7 @@ static /* 0x0F */ HOSTCMD(FXS, XPD_STATE, bool on) BUG_ON(!xpd); priv = xpd->priv; spin_lock_irqsave(&xpd->lock, flags); - XPD_DBG(xpd, "%s\n", (on)?"on":"off"); + XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off"); for_each_line(xpd, i) linefeed_control(xbus, xpd, i, value); if(on) { @@ -994,7 +992,7 @@ static /* 0x0F */ HOSTCMD(FXS, RING, lineno_t chan, bool on) BUG_ON(!xbus); BUG_ON(!xpd); - LINE_DBG(xpd, chan, "%s\n", (on)?"on":"off"); + LINE_DBG(SIGNAL, xpd, chan, "%s\n", (on)?"on":"off"); priv = xpd->priv; set_vm_led_mode(xbus, xpd, chan, 0); do_chan_power(xbus, xpd, chan, on); // Power up (for ring) @@ -1015,7 +1013,7 @@ static /* 0x0F */ HOSTCMD(FXS, RELAY_OUT, byte which, bool on) BUG_ON(!xbus); BUG_ON(!xpd); - XPD_DBG(xpd, "RELAY_OUT: which=%d -- %s\n", which, (on) ? "on" : "off"); + XPD_DBG(SIGNAL, xpd, "RELAY_OUT: which=%d -- %s\n", which, (on) ? "on" : "off"); which = which % ARRAY_SIZE(relay_channels); value = BIT(2) | BIT(3); value |= ((BIT(5) | BIT(6) | BIT(7)) & ~led_register_mask[OUTPUT_RELAY]); @@ -1037,7 +1035,7 @@ HANDLER_DEF(FXS, SIG_CHANGED) BUG_ON(!xpd); BUG_ON(xpd->direction != TO_PHONE); priv = xpd->priv; - XPD_DBG(xpd, "(PHONE) sig_toggles=0x%04X sig_status=0x%04X\n", sig_toggles, sig_status); + XPD_DBG(SIGNAL, xpd, "(PHONE) sig_toggles=0x%04X sig_status=0x%04X\n", sig_toggles, sig_status); #if 0 Is this needed? for_each_line(xpd, i) { @@ -1057,11 +1055,11 @@ HANDLER_DEF(FXS, SIG_CHANGED) #endif MARK_BLINK(priv, i, LED_GREEN, 0); if(IS_SET(sig_status, i)) { - LINE_DBG(xpd, i, "OFFHOOK\n"); + LINE_DBG(SIGNAL, xpd, i, "OFFHOOK\n"); MARK_ON(priv, i, LED_GREEN); update_line_status(xpd, i, 1); } else { - LINE_DBG(xpd, i, "ONHOOK\n"); + LINE_DBG(SIGNAL, xpd, i, "ONHOOK\n"); MARK_OFF(priv, i, LED_GREEN); update_line_status(xpd, i, 0); } @@ -1089,10 +1087,10 @@ static void process_digital_inputs(xpd_t *xpd, const reg_cmd_t *info) BIT_SET(lines, newchanno); xpd->ringing[newchanno] = 0; // Stop ringing. No leds for digital inputs. if(offhook && !IS_SET(xpd->offhook, newchanno)) { // OFFHOOK - LINE_DBG(xpd, newchanno, "OFFHOOK\n"); + LINE_DBG(SIGNAL, xpd, newchanno, "OFFHOOK\n"); update_line_status(xpd, newchanno, 1); } else if(!offhook && IS_SET(xpd->offhook, newchanno)) { // ONHOOK - LINE_DBG(xpd, newchanno, "ONHOOK\n"); + LINE_DBG(SIGNAL, xpd, newchanno, "ONHOOK\n"); update_line_status(xpd, newchanno, 0); } } @@ -1124,12 +1122,12 @@ void process_dtmf(xpd_t *xpd, const reg_cmd_t *info) for_each_line(xpd, i) { if(IS_SET(lines, i)) { if(on && !IS_SET(priv->dtmf_keypressed, i)) { - LINE_DBG(xpd, i, "DTMF digit %2d PRESSED (%d)\n", digit, val); + LINE_DBG(SIGNAL, xpd, i, "DTMF digit %2d PRESSED (%d)\n", digit, val); BIT_SET(priv->dtmf_keypressed, i); if(dtmf_detection) zt_qevent_lock(&xpd->chans[i], ZT_EVENT_DTMFDOWN | digit); } else if(!on && IS_SET(priv->dtmf_keypressed, i)) { - LINE_DBG(xpd, i, "DTMF digit %2d RELEASED\n", digit); + LINE_DBG(SIGNAL, xpd, i, "DTMF digit %2d RELEASED\n", digit); BIT_CLR(priv->dtmf_keypressed, i); if(dtmf_detection) zt_qevent_lock(&xpd->chans[i], ZT_EVENT_DTMFUP | digit); @@ -1156,11 +1154,9 @@ HANDLER_DEF(FXS, REGISTER_REPLY) BUG_ON(!priv); indirect = (REG_FIELD(info, regnum) == 0x1E); regnum = (indirect) ? REG_FIELD(info, subreg) : REG_FIELD(info, regnum); -#if 0 - XPD_DBG(xpd, "REGISTER_REPLY: %s reg_num=0x%X, dataL=0x%X dataH=0x%X\n", + XPD_DBG(REGS, xpd, "REGISTER_REPLY: %s reg_num=0x%X, dataL=0x%X dataH=0x%X\n", (indirect)?"I":"D", regnum, REG_FIELD(info, data_low), REG_FIELD(info, data_high)); -#endif if(!SPAN_REGISTERED(xpd)) goto out; /* @@ -1217,14 +1213,14 @@ static bool fxs_packet_is_valid(xpacket_t *pack) { const xproto_entry_t *xe; - // DBG("\n"); + // DBG(GENERAL, "\n"); xe = xproto_card_entry(&PROTO_TABLE(FXS), pack->opcode); return xe != NULL; } static void fxs_packet_dump(const char *msg, xpacket_t *pack) { - DBG("%s\n", msg); + DBG(GENERAL, "%s\n", msg); } /*------------------------- SLIC Handling --------------------------*/ @@ -1331,6 +1327,8 @@ static int handle_register_command(xpd_t *xpd, char *cmdline) xbus_t *xbus; int ret; + BUG_ON(!xpd); + xbus = xpd->xbus; if((p = strchr(cmdline, '#')) != NULL) /* Truncate comments */ *p = '\0'; if((p = strchr(cmdline, ';')) != NULL) /* Truncate comments */ @@ -1345,7 +1343,7 @@ static int handle_register_command(xpd_t *xpd, char *cmdline) &op, ®_type, ®_num, &data_low, &data_high); - // DBG("'%s': %d %c%c %02X %02X %02X\n", cmdline, chipsel, op, reg_type, reg_num, data_low, data_high); + XPD_DBG(REGS, xpd, "'%s': %d %c%c %02X %02X %02X\n", cmdline, chipsel, op, reg_type, reg_num, data_low, data_high); if(elements < 4) { // At least: chipsel, op, reg_type, reg_num ERR("Not enough arguments: (%d args) '%s'\n", elements, cmdline); return -EINVAL; @@ -1396,10 +1394,8 @@ static int handle_register_command(xpd_t *xpd, char *cmdline) REG_FIELD(®cmd, data_low) = data_low; REG_FIELD(®cmd, data_high) = data_high; REG_FIELD(®cmd, read_request) = writing; - BUG_ON(!xpd); - xbus = xpd->xbus; if(!down_read_trylock(&xbus->in_use)) { - XBUS_DBG(xbus, "Dropped packet. Is in_use\n"); + XBUS_DBG(GENERAL, xbus, "Dropped packet. Is in_use\n"); return -EBUSY; } xpd->requested_reply = regcmd; diff --git a/xpp/card_global.c b/xpp/card_global.c index 24d716d..3aece9c 100644 --- a/xpp/card_global.c +++ b/xpp/card_global.c @@ -50,11 +50,11 @@ static void global_packet_dump(const char *msg, xpacket_t *pack); xpacket_t *pack; if(!xbus) { - DBG("NO XBUS\n"); + DBG(GENERAL, "NO XBUS\n"); return -EINVAL; } XFRAME_NEW(xframe, pack, xbus, GLOBAL, DESC_REQ, xpd_num); - DBG("%s to %1d%1d\n", xbus->busname, XBUS_UNIT(xpd_num), XBUS_SUBUNIT(xpd_num)); + XBUS_DBG(GENERAL, xbus, "to %1d%1d\n", XBUS_UNIT(xpd_num), XBUS_SUBUNIT(xpd_num)); ret = send_cmd_frame(xbus, xframe); XBUS_COUNTER(xbus, DESC_REQ)++; return ret; @@ -69,7 +69,7 @@ static void global_packet_dump(const char *msg, xpacket_t *pack); xpacket_t *pack; BUG_ON(!xbus); - DBG("%s: mode=0x%X drift=%d\n", xbus->busname, mode, drift); + XBUS_DBG(SYNC, xbus, "mode=0x%X drift=%d\n", mode, drift); XFRAME_NEW(xframe, pack, xbus, GLOBAL, SYNC_SOURCE, 0); RPACKET_FIELD(pack, GLOBAL, SYNC_SOURCE, sync_mode) = mode; RPACKET_FIELD(pack, GLOBAL, SYNC_SOURCE, drift) = drift; @@ -83,7 +83,7 @@ static void global_packet_dump(const char *msg, xpacket_t *pack); xpacket_t *pack; BUG_ON(!xbus); - DBG("%s\n", xbus->busname); + XBUS_DBG(SYNC, xbus, "\n"); XFRAME_NEW(xframe, pack, xbus, GLOBAL, RESET_SYNC_COUNTERS, 0); RPACKET_FIELD(pack, GLOBAL, RESET_SYNC_COUNTERS, mask) = 0x10; send_cmd_frame(xbus, xframe); @@ -94,33 +94,35 @@ static void global_packet_dump(const char *msg, xpacket_t *pack); HANDLER_DEF(GLOBAL, NULL_REPLY) { - DBG("got len=%d\n", pack->datalen); + XBUS_DBG(GENERAL, xbus, "got len=%d\n", pack->datalen); return 0; } HANDLER_DEF(GLOBAL, DEV_DESC) { - byte rev = RPACKET_FIELD(pack, GLOBAL, DEV_DESC, rev); - byte type = RPACKET_FIELD(pack, GLOBAL, DEV_DESC, type); - xpp_line_t line_status = RPACKET_FIELD(pack, GLOBAL, DEV_DESC, line_status); - xpd_addr_t xpd_addr = RPACKET_FIELD(pack, GLOBAL, DEV_DESC, addr); struct card_desc_struct *card_desc; BUG_ON(!xbus); if((card_desc = kmalloc(sizeof(struct card_desc_struct), GFP_ATOMIC)) == NULL) { - ERR("%s: Card description allocation failed.\n", __FUNCTION__); + XBUS_ERR(xbus, "Card description allocation failed.\n"); return -ENOMEM; } memset(card_desc, 0, sizeof(struct card_desc_struct)); card_desc->magic = CARD_DESC_MAGIC; INIT_LIST_HEAD(&card_desc->card_list); card_desc->xbus = xbus; - card_desc->type = type; - card_desc->rev = rev; - card_desc->xpd_addr = xpd_addr; - card_desc->line_status = line_status; - DBG("%s: XPD=%d%d type=%d rev=%d line_status=0x%04X\n", - xbus->busname, xpd_addr.unit, xpd_addr.subunit, type, rev, line_status); + card_desc->type = RPACKET_FIELD(pack, GLOBAL, DEV_DESC, type); + card_desc->subtype = RPACKET_FIELD(pack, GLOBAL, DEV_DESC, subtype); + card_desc->rev = RPACKET_FIELD(pack, GLOBAL, DEV_DESC, rev); + card_desc->xpd_addr = RPACKET_FIELD(pack, GLOBAL, DEV_DESC, addr); + card_desc->line_status = RPACKET_FIELD(pack, GLOBAL, DEV_DESC, line_status); + XBUS_DBG(GENERAL, xbus, "XPD=%d%d type=%d.%d rev=%d line_status=0x%04X\n", + card_desc->xpd_addr.unit, + card_desc->xpd_addr.subunit, + card_desc->type, + card_desc->subtype, + card_desc->rev, + card_desc->line_status); xbus_poller_notify(xbus, card_desc); return 0; } @@ -133,24 +135,39 @@ HANDLER_DEF(GLOBAL, PCM_READ) unsigned long usec_diff; BUG_ON(!xbus); - do_gettimeofday(&now); - sec_diff = now.tv_sec - xbus->last_rx_sync.tv_sec; - usec_diff = sec_diff * 1000000 + (now.tv_usec - xbus->last_rx_sync.tv_usec); - if(unlikely(abs(sec_diff) > 2)) { - DBG("%s: PCM RX timing restart (sec_diff=%ld)\n", - xbus->busname, sec_diff); - } else { - if(abs(usec_diff - 1000) > TICK_TOLERANCE) { - if(print_dbg && printk_ratelimit()) - DBG("%s: Bad PCM RX timing: usec_diff=%ld.\n", - xbus->busname, usec_diff); + /* + * FIXME: + * Only calculate PCM statistics for unit==0, otherwise the data + * of the PCM packets in the same xframe would clobber each other. + * + * This is just a workaround, since the true solution is to handle + * each PCM frame separately (once the firmware guarantee that PCM + * frames contain only PCM packets). + * + * On PRI we must fix this since the PCM is transmitted in two frames + * and the following workaround only accounts for the first one. + */ + if(addr.unit == 0) { + do_gettimeofday(&now); + sec_diff = now.tv_sec - xbus->last_rx_sync.tv_sec; + usec_diff = sec_diff * 1000000 + (now.tv_usec - xbus->last_rx_sync.tv_usec); + if(unlikely(abs(sec_diff) > 2)) { + XBUS_DBG(SYNC, xbus, "PCM RX timing restart (sec_diff=%ld)\n", sec_diff); + } else { + if(abs(usec_diff - 1000) > TICK_TOLERANCE) { + static int rate_limit; + + if((rate_limit++ % 5003) == 0) + XBUS_DBG(SYNC, xbus, "Bad PCM RX timing(%d): usec_diff=%ld.\n", + rate_limit, usec_diff); + } + if(usec_diff > xbus->max_rx_sync) + xbus->max_rx_sync = usec_diff; + if(usec_diff < xbus->min_rx_sync) + xbus->min_rx_sync = usec_diff; } - if(usec_diff > xbus->max_rx_sync) - xbus->max_rx_sync = usec_diff; - if(usec_diff < xbus->min_rx_sync) - xbus->min_rx_sync = usec_diff; + xbus->last_rx_sync = now; } - xbus->last_rx_sync = now; if(!xpd) { #if 0 notify_bad_xpd(__FUNCTION__, xbus, pack->addr, cmd->name); @@ -182,8 +199,7 @@ HANDLER_DEF(GLOBAL, SYNC_REPLY) notify_bad_xpd(__FUNCTION__, xbus, pack->addr, cmd->name); return -EPROTO; } - DBG("%s/%s: mode=0x%X drift=%d\n", xpd->xbus->busname, xpd->xpdname, - mode, drift); + XPD_DBG(GENERAL, xpd, "mode=0x%X drift=%d\n", mode, drift); dump_packet("SYNC_REPLY", pack, print_dbg); xbus->sync_adjustment = (signed char)drift; return 0; @@ -246,14 +262,14 @@ static bool global_packet_is_valid(xpacket_t *pack) { const xproto_entry_t *xe; - //DBG("\n"); + //DBG(GENERAL, "\n"); xe = xproto_global_entry(pack->opcode); return xe != NULL; } static void global_packet_dump(const char *msg, xpacket_t *pack) { - DBG("%s\n", msg); + DBG(GENERAL, "%s\n", msg); } static bool pcm_valid(xpd_t *xpd, xpacket_t *pack) @@ -279,8 +295,7 @@ static bool pcm_valid(xpd_t *xpd, xpacket_t *pack) XPD_COUNTER(xpd, RECV_ERRORS)++; if((rate_limit++ % 1000) <= 10) { - ERR("%s/%s: BAD PCM REPLY: pack->datalen=%d (should be %d), count=%d\n", - xpd->xbus->busname, xpd->xpdname, + XPD_ERR(xpd, "BAD PCM REPLY: pack->datalen=%d (should be %d), count=%d\n", pack->datalen, good_len, count); dump_packet("BAD PCM REPLY", pack, 1); } @@ -289,7 +304,7 @@ static bool pcm_valid(xpd_t *xpd, xpacket_t *pack) return 1; } -#define MAX_ENV_STR 20 +#define MAX_ENV_STR 40 #define MAX_PATH_STR 60 int run_initialize_registers(xpd_t *xpd) @@ -322,7 +337,7 @@ int run_initialize_registers(xpd_t *xpd) BUG_ON(!xpd); xbus = xpd->xbus; if(!initdir || !initdir[0]) { - NOTICE("%s/%s: Missing initdir parameter\n", xbus->busname, xpd->xpdname); + XPD_NOTICE(xpd, "Missing initdir parameter\n"); return -EINVAL; } snprintf(busstr, MAX_ENV_STR, "XPD_BUS=%s", xbus->busname); @@ -334,35 +349,31 @@ int run_initialize_registers(xpd_t *xpd) snprintf(connectorstr, MAX_ENV_STR, "XBUS_CONNECTOR=%s", xbus->busdesc); if(snprintf(init_card, MAX_PATH_STR, "%s/init_card_%d_%d", initdir, xpd->type, xpd->revision) > MAX_PATH_STR) { - NOTICE("%s/%s: Cannot initialize. pathname is longer than %d characters.\n", - xbus->busname, xpd->xpdname, MAX_PATH_STR); + XPD_NOTICE(xpd, "Cannot initialize. pathname is longer than %d characters.\n", MAX_PATH_STR); return -E2BIG; } if(!down_read_trylock(&xbus->in_use)) { - ERR("Skipped register initialization. %s is going down\n", xbus->busname); + XBUS_ERR(xbus, "Skipped register initialization. XBUS is going down\n"); return -ENODEV; } - DBG("%s/%s: running '%s' for type=%d revision=%d\n", - xbus->busname, xpd->xpdname, init_card, xpd->type, xpd->revision); + XPD_DBG(GENERAL, xpd, "running '%s' for type=%d revision=%d\n", + init_card, xpd->type, xpd->revision); ret = call_usermodehelper(init_card, argv, envp, 1); /* * Carefully report results */ if(ret == 0) - DBG("%s/%s: '%s' finished OK\n", xbus->busname, xpd->xpdname, init_card); + XPD_DBG(GENERAL, xpd, "'%s' finished OK\n", init_card); else if(ret < 0) { - ERR("%s/%s: Failed running '%s' (errno %d)\n", - xbus->busname, xpd->xpdname, init_card, ret); + XPD_ERR(xpd, "Failed running '%s' (errno %d)\n", init_card, ret); } else { byte exitval = ((unsigned)ret >> 8) & 0xFF; byte sigval = ret & 0xFF; if(!exitval) { - ERR("%s/%s: '%s' killed by signal %d\n", - xbus->busname, xpd->xpdname, init_card, sigval); + XPD_ERR(xpd, "'%s' killed by signal %d\n", init_card, sigval); } else { - ERR("%s/%s: '%s' aborted with exitval %d\n", - xbus->busname, xpd->xpdname, init_card, exitval); + XPD_ERR(xpd, "'%s' aborted with exitval %d\n", init_card, exitval); } ret = -EINVAL; } diff --git a/xpp/utils/genzaptelconf b/xpp/utils/genzaptelconf index cf32fcd..930c308 100755 --- a/xpp/utils/genzaptelconf +++ b/xpp/utils/genzaptelconf @@ -39,7 +39,7 @@ rcsid='$Id$' lc_country=us # set to: ls, ks or gs for (Loopstart, Kewlstart and GroundStart) # on FXS channels (FXO signalling). -fxs_default_start=ls +fxs_default_start=ks base_exten=6000 # If set: no context changes are made in zapata-channels.conf #context_manual=yes diff --git a/xpp/utils/zconf/Zaptel/Config/Defaults.pm b/xpp/utils/zconf/Zaptel/Config/Defaults.pm index 90b49ab..05f4db3 100644 --- a/xpp/utils/zconf/Zaptel/Config/Defaults.pm +++ b/xpp/utils/zconf/Zaptel/Config/Defaults.pm @@ -14,7 +14,7 @@ use strict; sub do_source($@) { my $file = shift; my @vars = @_; - my @output = `env -i sh -ec '. $file; export @vars; env'`; + my @output = `env -i sh -ec '. $file; export @vars; for i in @vars; do eval echo \$i=\\\$\$i; done'`; die "$0: Sourcing '$file' exited with $?" if $?; my %vars; diff --git a/xpp/xbus-core.c b/xpp/xbus-core.c index b15ab4c..f88e2cd 100644 --- a/xpp/xbus-core.c +++ b/xpp/xbus-core.c @@ -119,7 +119,7 @@ int xbus_log(xbus_t *xbus, xpd_t *xpd, int direction, const void *buf, unsigned spin_lock_irqsave(&d->lock, flags); if (sizeof(struct log_header) + len > DEBUGFS_BUFSIZ - (d->tail - d->head)) { ret = -ENOSPC; - XPD_DBG(xpd, "Dropping debugfs data of len %lu, free space is %lu\n", sizeof(struct log_header) + len, + XPD_DBG(GENERAL, xpd, "Dropping debugfs data of len %lu, free space is %lu\n", sizeof(struct log_header) + len, DEBUGFS_BUFSIZ - (d->tail - d->head)); goto out; } @@ -167,7 +167,7 @@ static int debugfs_open(struct inode *inode, struct file *file) struct log_global_header gheader; BUG_ON(!xbus); - XBUS_DBG(xbus, "\n"); + XBUS_DBG(GENERAL, xbus, "\n"); if (xbus->debugfs_data) return -EBUSY; d = kmalloc(sizeof(struct debugfs_data), GFP_KERNEL); @@ -196,7 +196,7 @@ static ssize_t debugfs_read(struct file *file, char __user *buf, size_t nbytes, BUG_ON(!d); BUG_ON(!d->xbus); - XBUS_DBG(d->xbus, "\n"); + XBUS_DBG(GENERAL, d->xbus, "\n"); while (d->head == d->tail) { if (wait_event_interruptible(d->queue, d->head != d->tail)) return -EAGAIN; @@ -222,7 +222,7 @@ static int debugfs_release(struct inode *inode, struct file *file) BUG_ON(!d); BUG_ON(!d->xbus); - XBUS_DBG(d->xbus, "\n"); + XBUS_DBG(GENERAL, d->xbus, "\n"); d->xbus->debugfs_data = NULL; kfree(d); module_put(THIS_MODULE); @@ -271,7 +271,7 @@ xpacket_t *xframe_next_packet(xframe_t *frm, int len) int newlen = atomic_read(&frm->frame_len); newlen += len; -// DBG("len=%d, newlen=%d, frm->frame_len=%d\n", len, newlen, XFRAME_LEN(frm)); +// DBG(GENERAL, "len=%d, newlen=%d, frm->frame_len=%d\n", len, newlen, XFRAME_LEN(frm)); if (newlen > XFRAME_DATASIZE) { return NULL; } @@ -287,7 +287,7 @@ static void do_hexdump(const char msg[], byte *data, uint16_t len) int print_dbg = 1; for(i = 0; i < len; i++) - DBG("%s: %3d> %02X\n", msg, i, data[i]); + DBG(GENERAL, "%s: %3d> %02X\n", msg, i, data[i]); } void dump_xframe(const char msg[], const xbus_t *xbus, const xframe_t *xframe) @@ -345,9 +345,9 @@ void dump_xframe(const char msg[], const xbus_t *xbus, const xframe_t *xframe) do_print = 1; if(do_print) { if(num == 1) - XBUS_DBG(xbus, "%s: frame_len=%d.\n", + XBUS_DBG(GENERAL, xbus, "%s: frame_len=%d.\n", msg, frame_len); - XBUS_DBG(xbus, " %3d. DATALEN=%d OP=0x%02X XPD-%d%d (pos=%d)\n", + XBUS_DBG(GENERAL, xbus, " %3d. DATALEN=%d OP=0x%02X XPD-%d%d (pos=%d)\n", num, pack->datalen, pack->opcode, pack->addr.unit, pack->addr.subunit, pos); dump_packet(" ", pack, print_dbg); @@ -371,16 +371,16 @@ int xframe_send(xbus_t *xbus, xframe_t *xframe) int ret = -ENODEV; if(!xframe) { - DBG("null xframe\n"); + DBG(GENERAL, "null xframe\n"); return -EINVAL; } if(!xbus) { - DBG("null xbus\n"); + DBG(GENERAL, "null xbus\n"); ret = -EINVAL; goto error; } if (!xbus->hardware_exists) { - XBUS_DBG(xbus, "Dropped a xframe -- NO HARDWARE."); + XBUS_DBG(GENERAL, xbus, "Dropped a xframe -- NO HARDWARE."); ret = -ENODEV; goto error; } @@ -389,7 +389,7 @@ int xframe_send(xbus_t *xbus, xframe_t *xframe) XBUS_COUNTER(xbus, TX_BYTES) += XFRAME_LEN(xframe); up_read(&xbus->in_use); } else { - XBUS_DBG(xbus, "Dropped xframe. Is in_use\n"); + XBUS_DBG(GENERAL, xbus, "Dropped xframe. Is in_use\n"); } return ret; @@ -528,7 +528,7 @@ static void xbus_poll(void *data) } msleep(2); /* roundtrip for older polls */ spin_lock_irqsave(&xbus->lock, flags); - XBUS_DBG(xbus, "\n"); + XBUS_DBG(GENERAL, xbus, "\n"); poller->is_polling = 1; /* @@ -537,7 +537,7 @@ static void xbus_poll(void *data) for(id = 0; id < MAX_XPDS; id++) { if(!xbus->hardware_exists) break; - // XBUS_DBG(xbus, "Polling slot %d\n", id); + // XBUS_DBG(GENERAL, xbus, "Polling slot %d\n", id); spin_unlock_irqrestore(&xbus->lock, flags); ret = CALL_PROTO(GLOBAL, DESC_REQ, xbus, NULL, id); spin_lock_irqsave(&xbus->lock, flags); @@ -550,7 +550,7 @@ static void xbus_poll(void *data) /* * Wait for replies */ - XBUS_DBG(xbus, "Polled %d XPD's. Waiting for replies max %d jiffies\n", MAX_XPDS, poll_timeout); + XBUS_DBG(GENERAL, xbus, "Polled %d XPD's. Waiting for replies max %d jiffies\n", MAX_XPDS, poll_timeout); ret = wait_event_interruptible_timeout(poller->wait_for_polls, atomic_read(&poller->count_poll_answers) >= MAX_XPDS, poll_timeout); if(ret == 0) { XBUS_ERR(xbus, "Poll timeout. Continuing anyway.\n"); @@ -561,7 +561,7 @@ static void xbus_poll(void *data) XBUS_ERR(xbus, "Poll interrupted %d\n", ret); goto out; } else - XBUS_DBG(xbus, "Poll finished in %d jiffies.\n", poll_timeout - ret); + XBUS_DBG(GENERAL, xbus, "Poll finished in %d jiffies.\n", poll_timeout - ret); /* * Build removals/additions lists */ @@ -669,11 +669,11 @@ static void poller_destroy(struct xbus_poller *poller) if(!poller) return; if(poller->xbus) { - XBUS_DBG(poller->xbus, "detach poller\n"); + XBUS_DBG(GENERAL, poller->xbus, "detach poller\n"); poller->xbus->poller = NULL; } if (poller->wq) { - XBUS_DBG(poller->xbus, "destroy workqueue\n"); + XBUS_DBG(GENERAL, poller->xbus, "destroy workqueue\n"); flush_workqueue(poller->wq); destroy_workqueue(poller->wq); poller->wq = NULL; @@ -692,7 +692,7 @@ static struct xbus_poller *poller_new(xbus_t *xbus) BUG_ON(xbus->busname[0] == '\0'); /* No name? */ BUG_ON(xbus->poller); /* Hmmm... overrun pollers? */ - XBUS_DBG(xbus, "\n"); + XBUS_DBG(GENERAL, xbus, "\n"); poller = kmalloc(sizeof(*poller), GFP_KERNEL); if(!poller) goto err; @@ -756,7 +756,7 @@ void xbus_activate(xbus_t *xbus) BUG_ON(!ops->xframe_send); BUG_ON(!ops->xframe_new || !ops->xframe_free); xbus->hardware_exists = 1; - XBUS_DBG(xbus, "Activating\n"); + XBUS_DBG(GENERAL, xbus, "Activating\n"); /* Poll it */ poller_dispatch(xbus); } @@ -766,7 +766,7 @@ void xbus_disconnect(xbus_t *xbus) int i; BUG_ON(!xbus); - XBUS_DBG(xbus, "\n"); + XBUS_DBG(GENERAL, xbus, "\n"); xbus->hardware_exists = 0; for(i = 0; i < MAX_XPDS; i++) { xpd_t *xpd = xpd_of(xbus, i); @@ -778,7 +778,7 @@ void xbus_disconnect(xbus_t *xbus) } xpd_disconnect(xpd); } - XBUS_DBG(xbus, "Deactivated\n"); + XBUS_DBG(GENERAL, xbus, "Deactivated\n"); if(xbus->open_counter == 0) { xbus_remove(xbus); } @@ -829,33 +829,33 @@ static void xbus_free(xbus_t *xbus) #ifdef XPP_DEBUGFS if(xbus->debugfs_dir) { if(xbus->debugfs_file) { - XBUS_DBG(xbus, "Removing debugfs file\n"); + XBUS_DBG(GENERAL, xbus, "Removing debugfs file\n"); debugfs_remove(xbus->debugfs_file); } - XBUS_DBG(xbus, "Removing debugfs directory\n"); + XBUS_DBG(GENERAL, xbus, "Removing debugfs directory\n"); debugfs_remove(xbus->debugfs_dir); } #endif #ifdef CONFIG_PROC_FS if(xbus->proc_xbus_dir) { if(xbus->proc_xbus_summary) { - XBUS_DBG(xbus, "Removing proc '%s'\n", PROC_XBUS_SUMMARY); + XBUS_DBG(PROC, xbus, "Removing proc '%s'\n", PROC_XBUS_SUMMARY); remove_proc_entry(PROC_XBUS_SUMMARY, xbus->proc_xbus_dir); xbus->proc_xbus_summary = NULL; } if(xbus->proc_xbus_waitfor_xpds) { - XBUS_DBG(xbus, "Removing proc '%s'\n", PROC_XBUS_WAITFOR_XPDS); + XBUS_DBG(PROC, xbus, "Removing proc '%s'\n", PROC_XBUS_WAITFOR_XPDS); remove_proc_entry(PROC_XBUS_WAITFOR_XPDS, xbus->proc_xbus_dir); xbus->proc_xbus_waitfor_xpds = NULL; } #ifdef PROTOCOL_DEBUG if(xbus->proc_xbus_command) { - XBUS_DBG(xbus, "Removing proc '%s'\n", PROC_XBUS_COMMAND); + XBUS_DBG(PROC, xbus, "Removing proc '%s'\n", PROC_XBUS_COMMAND); remove_proc_entry(PROC_XBUS_COMMAND, xbus->proc_xbus_dir); xbus->proc_xbus_command = NULL; } #endif - XBUS_DBG(xbus, "Removing proc directory\n"); + XBUS_DBG(PROC, xbus, "Removing proc directory\n"); remove_proc_entry(xbus->busname, xpp_proc_toplevel); xbus->proc_xbus_dir = NULL; } @@ -894,7 +894,7 @@ xbus_t *xbus_new(xbus_ops_t *ops) init_rwsem(&xbus->in_use); xbus_reset_counters(xbus); #ifdef CONFIG_PROC_FS - XBUS_DBG(xbus, "Creating xbus proc directory\n"); + XBUS_DBG(PROC, xbus, "Creating xbus proc directory\n"); xbus->proc_xbus_dir = proc_mkdir(xbus->busname, xpp_proc_toplevel); if(!xbus->proc_xbus_dir) { XBUS_ERR(xbus, "Failed to create proc directory\n"); @@ -966,10 +966,10 @@ void xbus_remove(xbus_t *xbus) BUG_ON(!xbus); if(!xbus_of(xbus->num)) { - DBG("XBUS #%d was already removed. Skip.\n", xbus->num); + DBG(GENERAL, "XBUS #%d was already removed. Skip.\n", xbus->num); return; } - XBUS_DBG(xbus, "\n"); + XBUS_DBG(GENERAL, xbus, "\n"); /* Block until no one use */ down_write(&xbus->in_use); @@ -984,7 +984,7 @@ void xbus_remove(xbus_t *xbus) XBUS_ERR(xbus, "BUG: xpd->xbus_idx=%d != i=%d\n", xpd->xbus_idx, i); continue; } - XBUS_DBG(xbus, " Removing xpd #%d\n", i); + XBUS_DBG(GENERAL, xbus, " Removing xpd #%d\n", i); xpd_remove(xpd); } xbus->xpds[i] = NULL; @@ -1003,7 +1003,7 @@ void xbus_reset_counters(xbus_t *xbus) { int i; - XBUS_DBG(xbus, "Reseting counters\n"); + XBUS_DBG(GENERAL, xbus, "Reseting counters\n"); for(i = 0; i < XBUS_COUNTER_MAX; i++) { xbus->counters[i] = 0; } @@ -1081,7 +1081,7 @@ static int xbus_read_waitfor_xpds(char *page, char **start, off_t off, int count if(!xbus) goto out; poller = xbus->poller; - XBUS_DBG(xbus, "Waiting for card initialization of %d XPD's max %d seconds\n", MAX_XPDS, INITIALIZATION_TIMEOUT/HZ); + XBUS_DBG(GENERAL, xbus, "Waiting for card initialization of %d XPD's max %d seconds\n", MAX_XPDS, INITIALIZATION_TIMEOUT/HZ); /* * xbus_poll sets count_xpds_to_initialize only when polling is finished. * To prevent race conditions we test both: @@ -1099,7 +1099,7 @@ static int xbus_read_waitfor_xpds(char *page, char **start, off_t off, int count XBUS_ERR(xbus, "Card Initialization Interrupted %d\n", ret); return ret; } - XBUS_DBG(xbus, "Finished initialization of %d XPD's in %d seconds.\n", MAX_XPDS, (INITIALIZATION_TIMEOUT - ret)/HZ); + XBUS_DBG(GENERAL, xbus, "Finished initialization of %d XPD's in %d seconds.\n", MAX_XPDS, (INITIALIZATION_TIMEOUT - ret)/HZ); spin_lock_irqsave(&xbus->lock, flags); len += sprintf(page + len, "XPDS_READY: %s: %d/%d\n", xbus->busname, @@ -1147,8 +1147,8 @@ static int proc_xbus_command_write(struct file *file, const char __user *buffer, if(!(*p)) break; if(!isxdigit(*p)) { - ERR("%s: %s: bad hex value ASCII='0x%X' at position %d\n", - __FUNCTION__, xbus->busname, *p, p - buf); + XBUS_ERR(xbus, "%s: bad hex value ASCII='0x%X' at position %ld\n", + __FUNCTION__, *p, (long)(p - buf)); return -EINVAL; } hexdigit[0] = *p++; @@ -1157,12 +1157,12 @@ static int proc_xbus_command_write(struct file *file, const char __user *buffer, if(isxdigit(*p)) hexdigit[1] = *p++; if(sscanf(hexdigit, "%2X", &val) != 1) { - ERR("%s: %s: bad hex value '%s' at position %d\n", - __FUNCTION__, xbus->busname, hexdigit, p - buf); + XBUS_ERR(xbus, "%s: bad hex value '%s' at position %ld\n", + __FUNCTION__, hexdigit, (long)(p - buf)); return -EINVAL; } *q++ = val; - // XBUS_DBG(xbus, "'%s' val=%d\n", hexdigit, val); + // XBUS_DBG(GENERAL, xbus, "'%s' val=%d\n", hexdigit, val); } xframe = xbus->ops->xframe_new(xbus, GFP_KERNEL); if(!xframe) @@ -1246,20 +1246,20 @@ static void xbus_core_cleanup(void) { #ifdef XPP_DEBUGFS if(debugfs_root) { - DBG("Removing xpp from debugfs\n"); + DBG(GENERAL, "Removing xpp from debugfs\n"); debugfs_remove(debugfs_root); } #endif #ifdef CONFIG_PROC_FS if(proc_xbuses) { - DBG("Removing " PROC_XBUSES " from proc\n"); + DBG(PROC, "Removing " PROC_XBUSES " from proc\n"); remove_proc_entry(PROC_XBUSES, xpp_proc_toplevel); proc_xbuses = NULL; } #endif #ifdef CONFIG_PROC_FS if(proc_commands) { - DBG("Removing %s from proc\n", PROC_CMDS); + DBG(PROC, "Removing %s from proc\n", PROC_CMDS); remove_proc_entry(PROC_CMDS, xpp_proc_toplevel); proc_commands = NULL; } @@ -1305,7 +1305,7 @@ int __init xbus_core_init(void) proc_xbuses->owner = THIS_MODULE; #endif #ifdef XPP_DEBUGFS - DBG("Creating debugfs xpp root\n"); + DBG(GENERAL, "Creating debugfs xpp root\n"); debugfs_root = debugfs_create_dir("xpp", NULL); if(!debugfs_root) { ERR("Failed to create debugfs root\n"); diff --git a/xpp/xbus-sysfs.c b/xpp/xbus-sysfs.c index f444b50..d94c14d 100644 --- a/xpp/xbus-sysfs.c +++ b/xpp/xbus-sysfs.c @@ -68,7 +68,7 @@ extern int print_dbg; /*--------- Sysfs Bus handling ----*/ static int xpp_bus_match(struct device *dev, struct device_driver *driver) { - DBG("dev->bus_id = %s, driver->name = %s\n", dev->bus_id, driver->name); + DBG(GENERAL, "dev->bus_id = %s, driver->name = %s\n", dev->bus_id, driver->name); return 1; } @@ -106,7 +106,7 @@ static int xpp_bus_uevent(struct device *dev, char **envp, int num_envp, char *b if(!dev) return -ENODEV; xbus = dev_to_xbus(dev); - DBG("bus_id=%s xbus=%s\n", dev->bus_id, xbus->busname); + DBG(GENERAL, "bus_id=%s xbus=%s\n", dev->bus_id, xbus->busname); XBUS_ADD_UEVENT_VAR("XBUS_NUM=%02d", xbus->num); XBUS_ADD_UEVENT_VAR("XBUS_NAME=%s", xbus->busname); envp[i] = NULL; @@ -116,7 +116,7 @@ static int xpp_bus_uevent(struct device *dev, char **envp, int num_envp, char *b static void xpp_bus_release(struct device *dev) { - DBG("\n"); + DBG(GENERAL, "\n"); } static void xpp_dev_release(struct device *dev) @@ -125,7 +125,7 @@ static void xpp_dev_release(struct device *dev) BUG_ON(!dev); xbus = dev_to_xbus(dev); - XBUS_DBG(xbus, "\n"); + XBUS_DBG(GENERAL, xbus, "\n"); } static struct bus_type xpp_bus_type = { @@ -213,7 +213,7 @@ void xbus_sysfs_remove(xbus_t *xbus) struct device *astribank; BUG_ON(!xbus); - XBUS_DBG(xbus, "\n"); + XBUS_DBG(GENERAL, xbus, "\n"); astribank = &xbus->astribank; BUG_ON(!astribank); device_remove_file(&xbus->astribank, &dev_attr_status); @@ -229,7 +229,7 @@ int xbus_sysfs_create(xbus_t *xbus) BUG_ON(!xbus); astribank = &xbus->astribank; BUG_ON(!astribank); - XBUS_DBG(xbus, "\n"); + XBUS_DBG(GENERAL, xbus, "\n"); device_initialize(astribank); astribank->bus = &xpp_bus_type; astribank->parent = &xpp_bus; diff --git a/xpp/xpd.h b/xpp/xpd.h index 85d4b16..ca2d357 100644 --- a/xpp/xpd.h +++ b/xpp/xpd.h @@ -310,6 +310,7 @@ struct xpd { xpp_line_t digital_outputs; /* 0 - no, 1 - yes */ xpp_line_t digital_inputs; /* 0 - no, 1 - yes */ xpp_line_t digital_signalling; /* PRI/BRI signalling channels */ + uint timing_priority; /* from 'span' directives in zapata.conf */ /* maintained by card drivers */ uint pcm_len; /* allocation length of PCM packet (dynamic) */ diff --git a/xpp/xpp_usb.c b/xpp/xpp_usb.c index b5ed7e3..c147285 100644 --- a/xpp/xpp_usb.c +++ b/xpp/xpp_usb.c @@ -50,6 +50,7 @@ static const char rcsid[] = "$Id$"; DEF_PARM(int, print_dbg, 0, 0644, "Print DBG statements"); /* must be before zap_debug.h */ +DEF_PARM(int, usb1, 0, 0644, "Allow using USB 1.1 interfaces"); #include "zap_debug.h" @@ -326,7 +327,7 @@ freepack: static void xpp_urb_delete(struct urb *urb) { BUG_ON(!urb); - // DBG("%s: (%d) %p %X", __FUNCTION__, urb->transfer_buffer_length, urb->transfer_buffer, urb->transfer_dma); + // DBG(GENERAL, "%s: (%d) %p %X", __FUNCTION__, urb->transfer_buffer_length, urb->transfer_buffer, urb->transfer_dma); usb_buffer_free (urb->dev, urb->transfer_buffer_length, urb->transfer_buffer, urb->transfer_dma); @@ -364,7 +365,7 @@ static struct urb *xpp_urb_new(xusb_t *xusb, enum xusb_dir dir, size_t size) */ urb->transfer_flags = (URB_NO_TRANSFER_DMA_MAP | URB_ASYNC_UNLINK); buffer = usb_buffer_alloc(udev, size, GFP_ATOMIC, &urb->transfer_dma); - // DBG("(%d) %p / %x", size, buffer, urb->transfer_dma); + // DBG(GENERAL, "(%d) %p / %x", size, buffer, urb->transfer_dma); if (!buffer) { err("Couldn't allocate buffer"); usb_free_urb(urb); @@ -455,6 +456,29 @@ static struct usb_class_driver xusb_class = { .minor_base = USB_SKEL_MINOR_BASE, }; +/* + * Check that an endpoint's wMaxPacketSize attribute is 512. This + * indicates that it is a USB2's high speed end point. + * + * If it is 64, it means we have a USB1 controller. By default we do not + * support it and just fail the probe of the device. However if the user + * has set usb1=1, we continue and just put a notice. + */ +int is_usb1_endpoint_size(int ep_addr, int max_packet_size, const char *type) +{ + if(max_packet_size >= sizeof(xpacket_t)) + return 0; + + if(usb1) { + NOTICE("USB1 endpoint detected: USB %s endpoint 0x%X support only wMaxPacketSize=%d.\n", + type, ep_addr, max_packet_size); + return 0; + } + NOTICE("USB1 endpoint detected. Device disabled. To enable: usb1=1, and read docs. (%s, endpoint %d, size %d).\n", + type, ep_addr, max_packet_size); + return 1; +} + /* * set up the endpoint information * check out the endpoints @@ -469,7 +493,7 @@ static int set_endpoints(xusb_t *xusb, struct usb_interface *interface, struct x int i; iface_desc = &interface->altsetting[0]; - DBG("Found interface. Endpoints: %d\n", iface_desc->desc.bNumEndpoints); + DBG(GENERAL, "Found interface. Endpoints: %d\n", iface_desc->desc.bNumEndpoints); #define BULK_ENDPOINT(ep) (((ep)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK) @@ -478,15 +502,14 @@ static int set_endpoints(xusb_t *xusb, struct usb_interface *interface, struct x ep_addr = endpoint->bEndpointAddress; if(!BULK_ENDPOINT(endpoint)) { - DBG("endpoint 0x%x is not bulk: mbAttributes=0x%X\n", + DBG(GENERAL, "endpoint 0x%x is not bulk: mbAttributes=0x%X\n", ep_addr, endpoint->bmAttributes); continue; } if(usb_pipein(ep_addr)) { // Input if(ep_addr == model_info->in.ep_addr) { - if(endpoint->wMaxPacketSize < sizeof(xframe_t)) { - NOTICE("USB input endpoint 0x%X support only wMaxPacketSize=%d (need USB-2)\n", ep_addr, endpoint->wMaxPacketSize); - } + if (is_usb1_endpoint_size(ep_addr, endpoint->wMaxPacketSize, "input")) + return 0; xusb_ep = &xusb->endpoints[XUSB_RECV]; xusb_ep->ep_addr = ep_addr; xusb_ep->max_size = endpoint->wMaxPacketSize; @@ -494,9 +517,8 @@ static int set_endpoints(xusb_t *xusb, struct usb_interface *interface, struct x } } else { // Output if(ep_addr == model_info->out.ep_addr) { - if(endpoint->wMaxPacketSize < sizeof(xframe_t)) { - NOTICE("USB output endpoint 0x%X support only wMaxPacketSize=%d (need USB-2)\n", ep_addr, endpoint->wMaxPacketSize); - } + if (is_usb1_endpoint_size(ep_addr, endpoint->wMaxPacketSize, "output")) + return 0; xusb_ep = &xusb->endpoints[XUSB_SEND]; xusb_ep->ep_addr = ep_addr; xusb_ep->max_size = endpoint->wMaxPacketSize; @@ -508,7 +530,7 @@ static int set_endpoints(xusb_t *xusb, struct usb_interface *interface, struct x ERR("Couldn't find bulk-in or bulk-out endpoints\n"); return 0; } - DBG("in=0x%02X out=0x%02X\n", xusb->endpoints[XUSB_RECV].ep_addr, xusb->endpoints[XUSB_SEND].ep_addr); + DBG(GENERAL, "in=0x%02X out=0x%02X\n", xusb->endpoints[XUSB_RECV].ep_addr, xusb->endpoints[XUSB_SEND].ep_addr); return 1; } @@ -621,13 +643,13 @@ static int xusb_probe(struct usb_interface *interface, const struct usb_device_i snprintf(xbus->busdesc, XBUS_DESCLEN, "%s", path); } - DBG("GOT XPP USB BUS #%d: %s (type=%d)\n", i, xbus->busdesc, xbus->bus_type); + DBG(GENERAL, "GOT XPP USB BUS #%d: %s (type=%d)\n", i, xbus->busdesc, xbus->bus_type); xusb_array[i] = xusb; #ifdef CONFIG_PROC_FS - DBG("Creating proc entry " PROC_USBXPP_SUMMARY " in bus proc dir.\n"); + DBG(PROC, "Creating proc entry " PROC_USBXPP_SUMMARY " in bus proc dir.\n"); procsummary = create_proc_read_entry(PROC_USBXPP_SUMMARY, 0444, xbus->proc_xbus_dir, xusb_read_proc, xusb); if (!procsummary) { @@ -659,7 +681,7 @@ probe_failed: } if(xbus) { if(procsummary) { - XBUS_DBG(xbus, "Remove proc_entry: " PROC_USBXPP_SUMMARY "\n"); + XBUS_DBG(PROC, xbus, "Remove proc_entry: " PROC_USBXPP_SUMMARY "\n"); remove_proc_entry(PROC_USBXPP_SUMMARY, xbus->proc_xbus_dir); procsummary = NULL; } @@ -686,7 +708,7 @@ static void xusb_disconnect(struct usb_interface *interface) int minor; int i; - DBG("CALLED\n"); + DBG(GENERAL, "CALLED\n"); /* prevent races with open() */ down (&disconnect_sem); @@ -704,7 +726,7 @@ static void xusb_disconnect(struct usb_interface *interface) #ifdef CONFIG_PROC_FS if(xbus->proc_xbus_dir) { - XBUS_DBG(xbus, "Remove proc_entry: " PROC_USBXPP_SUMMARY "\n"); + XBUS_DBG(GENERAL, xbus, "Remove proc_entry: " PROC_USBXPP_SUMMARY "\n"); remove_proc_entry(PROC_USBXPP_SUMMARY, xbus->proc_xbus_dir); } #endif @@ -726,7 +748,7 @@ static void xusb_disconnect(struct usb_interface *interface) xpp_urb_delete(xusb->read_urb); up (&xusb->sem); - DBG("Semaphore released\n"); + DBG(GENERAL, "Semaphore released\n"); kfree(xusb); @@ -761,7 +783,7 @@ static void xpp_send_callback(USB_PASS_CB(urb)) if (urb->status && !(urb->status == -ENOENT || urb->status == -ECONNRESET)) { static int rate_limit; if((rate_limit++ % 1000) < 10) - DBG("nonzero read bulk status received: %d\n", urb->status); + DBG(GENERAL, "nonzero read bulk status received: %d\n", urb->status); XUSB_COUNTER(xusb, TX_ERRORS)++; } xpp_urb_delete(urb); @@ -792,7 +814,7 @@ static void xpp_receive_callback(USB_PASS_CB(urb)) } //flip_parport_bit(7); if (urb->status) { - DBG("nonzero read bulk status received: %d\n", urb->status); + DBG(GENERAL, "nonzero read bulk status received: %d\n", urb->status); XUSB_COUNTER(xusb, RX_ERRORS)++; /* Free old URB, allocate a fresh one */ if(xusb->read_urb) @@ -872,7 +894,7 @@ int __init xpp_usb_init(void) void __exit xpp_usb_cleanup(void) { - DBG("\n"); + DBG(GENERAL, "\n"); /* deregister this driver with the USB subsystem */ usb_deregister(&xusb_driver); } diff --git a/xpp/xpp_zap.c b/xpp/xpp_zap.c index 77f3437..1fc7b37 100644 --- a/xpp/xpp_zap.c +++ b/xpp/xpp_zap.c @@ -168,7 +168,7 @@ static void external_sync(xbus_t *the_xbus) { int i; - DBG("%s\n", (the_xbus) ? the_xbus->busname : "HOST"); + DBG(SYNC, "%s\n", (the_xbus) ? the_xbus->busname : "HOST"); // Shut all down for(i = 0; i < MAX_BUSES; i++) { xbus_t *xbus = xbus_of(i); @@ -185,7 +185,7 @@ static void external_sync(xbus_t *the_xbus) /* * Change sync_master. May block. Cannot be called from atomic context */ -static void sync_master_is(xbus_t *xbus) +static void sync_master_is(const char *msg, xbus_t *xbus) { xpd_t *xpd = (xbus)? xpd_of(xbus, 0) : NULL; @@ -193,7 +193,8 @@ static void sync_master_is(xbus_t *xbus) XBUS_NOTICE(xbus, "Cannot set sync master (has no XPD #0).\n"); xbus = NULL; /* Fallback to HOST */ } - DBG("SYNC MASTER CHANGING: %s => %s\n", + DBG(SYNC, "SYNC MASTER CHANGING(%s): %s => %s\n", + msg, (sync_master) ? sync_master->xbus->busname : "HOST", (xbus) ? xbus->busname : "HOST"); /* First stop all generators */ @@ -216,6 +217,41 @@ static void sync_master_is(xbus_t *xbus) } } +void elect_syncer(const char *msg) +{ + int i; + int j; + uint timing_priority = 0; + xpd_t *best_xpd = NULL; + + for(i = 0; i < MAX_BUSES; i++) { + xbus_t *xbus = xbus_of(i); + if(!xbus) + continue; + if (!xbus->hardware_exists) + continue; + for(j = 0; j < MAX_XPDS; j++) { + xpd_t *xpd = xpd_of(xbus, j); + + if(!xpd) + continue; + if(SPAN_REGISTERED(xpd)) { + if(xpd->timing_priority > timing_priority) { + timing_priority = xpd->timing_priority; + best_xpd = xpd; + } + } + } + } + if(!best_xpd) { + INFO("%s: elected HOST\n", msg); + sync_master_is(msg, NULL); + } else if(!sync_master || (timing_priority > sync_master->timing_priority)) { + XPD_INFO(best_xpd, "%s: elected with priority %d\n", msg, timing_priority); + sync_master_is(msg, best_xpd->xbus); + } +} + static inline void send_pcm_frame(xbus_t *xbus, xframe_t *xframe) { unsigned long flags; @@ -230,7 +266,7 @@ static inline void send_pcm_frame(xbus_t *xbus, xframe_t *xframe) sec_diff = now.tv_sec - xbus->last_tx_sync.tv_sec; usec_diff = sec_diff * 1000000 + (now.tv_usec - xbus->last_tx_sync.tv_usec); if(unlikely(abs(sec_diff) > 2)) { - XBUS_DBG(xbus, "PCM TX timing restart (sec_diff=%ld)\n", sec_diff); + XBUS_DBG(SYNC, xbus, "PCM TX timing restart (sec_diff=%ld)\n", sec_diff); xbus->last_tx_sync = now; goto dropit; } @@ -238,7 +274,7 @@ static inline void send_pcm_frame(xbus_t *xbus, xframe_t *xframe) static int rate_limit; if((rate_limit++ % 5003) == 0) - XBUS_DBG(xbus, "Bad PCM TX timing(%d): usec_diff=%ld.\n", + XBUS_DBG(SYNC, xbus, "Bad PCM TX timing(%d): usec_diff=%ld.\n", rate_limit, usec_diff); } if(usec_diff > xbus->max_tx_sync) @@ -435,7 +471,7 @@ void xpp_tick(unsigned long param) if (!xbus->hardware_exists) continue; if(!down_read_trylock(&xbus->in_use)) { - XBUS_DBG(xbus, "Dropped packet. Is in_use\n"); + XBUS_DBG(GENERAL, xbus, "Dropped packet. Is in_use\n"); continue; } /* Reset sync LEDs once in a while */ @@ -460,7 +496,7 @@ void got_sync_from(xpd_t *xpd) static int rate_limit; if((rate_limit++ % 1003) == 0) - XPD_DBG(xpd, "is not SYNC master. Go away! (%d)\n", rate_limit); + XPD_DBG(SYNC, xpd, "is not SYNC master. Go away! (%d)\n", rate_limit); return; } atomic_inc(&missed_ticks); @@ -488,7 +524,7 @@ static void send_drift(int drift) msg = "up"; else msg = "down"; - XBUS_DBG(xbus, "DRIFT adjust %s (%d) (last update %ld seconds ago)\n", + XBUS_DBG(SYNC, xbus, "DRIFT adjust %s (%d) (last update %ld seconds ago)\n", msg, drift, now.tv_sec - xbus->pll_updated_at); CALL_PROTO(GLOBAL, SYNC_SOURCE, xbus, NULL, SYNC_MODE_PLL, drift); xbus->pll_updated_at = now.tv_sec; @@ -534,7 +570,7 @@ int zaptel_sync_tick(struct zt_span *span, int is_master) static int rate_limit; if((rate_limit++ % 1003) == 0) - DBG("Big lag of Xpp ticks relative to zaptel ticks: %ld\n", usec_lag_curr); + DBG(SYNC, "Big lag of Xpp ticks relative to zaptel ticks: %ld\n", usec_lag_curr); } sigma_lag += usec_lag_curr; if((zaptel_tick_count % SYNC_ADJ_INTERVAL) == 0) { @@ -569,25 +605,25 @@ static void xpd_free(xpd_t *xpd) xbus = xpd->xbus; if(!xbus) return; - XPD_DBG(xpd, "\n"); + XPD_DBG(GENERAL, xpd, "\n"); #ifdef CONFIG_PROC_FS if(xpd->proc_xpd_dir) { if(xpd->proc_xpd_summary) { - XPD_DBG(xpd, "Removing proc '%s'\n", PROC_XPD_SUMMARY); + XPD_DBG(PROC, xpd, "Removing proc '%s'\n", PROC_XPD_SUMMARY); remove_proc_entry(PROC_XPD_SUMMARY, xpd->proc_xpd_dir); xpd->proc_xpd_summary = NULL; } if(xpd->proc_xpd_ztregister) { - XPD_DBG(xpd, "Removing proc '%s'\n", PROC_XPD_ZTREGISTER); + XPD_DBG(PROC, xpd, "Removing proc '%s'\n", PROC_XPD_ZTREGISTER); remove_proc_entry(PROC_XPD_ZTREGISTER, xpd->proc_xpd_dir); xpd->proc_xpd_ztregister = NULL; } if(xpd->proc_xpd_blink) { - XPD_DBG(xpd, "Removing proc '%s'\n", PROC_XPD_BLINK); + XPD_DBG(PROC, xpd, "Removing proc '%s'\n", PROC_XPD_BLINK); remove_proc_entry(PROC_XPD_BLINK, xpd->proc_xpd_dir); xpd->proc_xpd_blink = NULL; } - XPD_DBG(xpd, "Removing proc directory\n"); + XPD_DBG(PROC, xpd, "Removing proc directory\n"); remove_proc_entry(xpd->xpdname, xbus->proc_xbus_dir); xpd->proc_xpd_dir = NULL; } @@ -687,7 +723,7 @@ void card_detected(struct card_desc_struct *card_desc) if(!xpd) { XBUS_NOTICE(xbus, "card_new(%d,%d,%d,%d,%d) failed. Ignored.\n", unit, subunit, proto_table->type, subtype, rev); - xproto_put(xpd->xproto); + xproto_put(proto_table); goto err; } xpd->addr = card_desc->xpd_addr; @@ -707,7 +743,7 @@ void card_detected(struct card_desc_struct *card_desc) } xbus_register_xpd(xbus, xpd); #ifdef CONFIG_PROC_FS - XPD_DBG(xpd, "Creating proc directory\n"); + XPD_DBG(PROC, xpd, "Creating proc directory\n"); xpd->proc_xpd_dir = proc_mkdir(xpd->xpdname, xbus->proc_xbus_dir); if(!xpd->proc_xpd_dir) { XPD_ERR(xpd, "Failed to create proc directory\n"); @@ -904,7 +940,7 @@ xpd_t *xpd_alloc(size_t privsize, const xproto_table_t *proto_table, int channel size_t alloc_size = sizeof(xpd_t) + privsize; int type = proto_table->type; - DBG("type=%d channels=%d\n", type, channels); + DBG(GENERAL, "type=%d channels=%d\n", type, channels); if(channels > CHANNELS_PERXPD) { ERR("%s: type=%d: too many channels %d\n", __FUNCTION__, type, channels); @@ -973,11 +1009,13 @@ void xpd_disconnect(xpd_t *xpd) BUG_ON(!xpd); // TODO: elect a new sync master - if(sync_master == xpd) - sync_master_is(NULL); + if(sync_master == xpd) { + sync_master_is("DISCONNECT", NULL); + elect_syncer("DISCONNECT"); + } spin_lock_irqsave(&xpd->lock, flags); - XPD_DBG(xpd, "(%p)\n", xpd->xproto); + XPD_DBG(GENERAL, xpd, "(%p)\n", xpd->xproto); if(!xpd->card_present) /* Multiple reports */ goto out; xpd->card_present = 0; @@ -986,7 +1024,7 @@ void xpd_disconnect(xpd_t *xpd) update_xpd_status(xpd, ZT_ALARM_NOTOPEN); /* TODO: Should this be done before releasing the spinlock? */ - XPD_DBG(xpd, "Queuing ZT_EVENT_REMOVED on all channels to ask user to release them\n"); + XPD_DBG(GENERAL, xpd, "Queuing ZT_EVENT_REMOVED on all channels to ask user to release them\n"); for (i=0; ispan.channels; i++) zt_qevent_lock(&xpd->chans[i],ZT_EVENT_REMOVED); } @@ -1026,7 +1064,7 @@ void update_xpd_status(xpd_t *xpd, int alarm_flag) return; span->alarms = alarm_flag; zt_alarm_notify(span); - XPD_DBG(xpd, "Update XPD alarms: %s -> %02X\n", xpd->span.name, alarm_flag); + XPD_DBG(GENERAL, xpd, "Update XPD alarms: %s -> %02X\n", xpd->span.name, alarm_flag); } void update_line_status(xpd_t *xpd, int pos, bool to_offhook) @@ -1047,7 +1085,7 @@ void update_line_status(xpd_t *xpd, int pos, bool to_offhook) * it may call back into our xpp_hooksig() and cause * a nested spinlock scenario */ - LINE_DBG(xpd, pos, "rxsig=%s\n", (rxsig == ZT_RXSIG_ONHOOK) ? "ONHOOK" : "OFFHOOK"); + LINE_DBG(GENERAL, xpd, pos, "rxsig=%s\n", (rxsig == ZT_RXSIG_ONHOOK) ? "ONHOOK" : "OFFHOOK"); if(SPAN_REGISTERED(xpd)) zt_hooksig(&xpd->chans[pos], rxsig); } @@ -1130,23 +1168,23 @@ static int proc_sync_write(struct file *file, const char __user *buffer, unsigne int xpd_num; xbus_t *xbus; - // DBG("%s: count=%ld\n", __FUNCTION__, count); + // DBG(SYNC, "%s: count=%ld\n", __FUNCTION__, count); if(count >= MAX_PROC_WRITE) return -EINVAL; if(copy_from_user(buf, buffer, count)) return -EFAULT; buf[count] = '\0'; if(strncmp("HOST", buf, 4) == 0) { - sync_master_is(NULL); + sync_master_is("PROC", NULL); } else if(sscanf(buf, "SYNC=%d", &xbus_num) == 1) { - DBG("SYNC=%d\n", xbus_num); + DBG(SYNC, "SYNC=%d\n", xbus_num); if((xbus = xbus_of(xbus_num)) == NULL) { ERR("No bus %d exists\n", xbus_num); return -ENXIO; } - sync_master_is(xbus); + sync_master_is("PROC", xbus); } else if(sscanf(buf, "QUERY=%d", &xbus_num) == 1) { - DBG("QUERY=%d\n", xbus_num); + DBG(SYNC, "QUERY=%d\n", xbus_num); if((xbus = xbus_of(xbus_num)) == NULL) { ERR("No bus %d exists\n", xbus_num); return -ENXIO; @@ -1163,7 +1201,7 @@ static int proc_sync_write(struct file *file, const char __user *buffer, unsigne ERR("No bus %d exists\n", xbus_num); return -ENXIO; } - sync_master_is(xbus); + sync_master_is("PROC", xbus); } else { ERR("%s: cannot parse '%s'\n", __FUNCTION__, buf); count = -EINVAL; @@ -1209,7 +1247,7 @@ static int proc_xpd_ztregister_write(struct file *file, const char __user *buffe ret = sscanf(buf, "%d", &zt_reg); if(ret != 1) return -EINVAL; - XPD_DBG(xpd, "%s\n", (zt_reg) ? "register" : "unregister"); + XPD_DBG(GENERAL, xpd, "%s\n", (zt_reg) ? "register" : "unregister"); if(zt_reg) ret = zaptel_register_xpd(xpd); else @@ -1255,7 +1293,7 @@ static int proc_xpd_blink_write(struct file *file, const char __user *buffer, un ret = sscanf(buf, "%d", &blink); if(ret != 1) return -EINVAL; - XPD_DBG(xpd, "%s\n", (blink) ? "blink" : "unblink"); + XPD_DBG(GENERAL, xpd, "%s\n", (blink) ? "blink" : "unblink"); xpd->blink_mode = blink; return count; } @@ -1377,7 +1415,7 @@ static void xpp_receiveprep(xpd_t *xpd) spin_lock_irqsave(&xpd->lock, flags); // if((xpd->timer_count % 1000) == 0) - // XPD_DBG(xpd, "%d\n", xpd->timer_count); + // XPD_DBG(GENERAL, xpd, "%d\n", xpd->timer_count); if (xpd->timer_count & 1) { /* First part */ @@ -1426,7 +1464,7 @@ int xpp_open(struct zt_chan *chan) atomic_inc(&xpd->open_counter); if(IS_SET(xpd->digital_signalling, pos)) /* D-chan offhook */ BIT_SET(xpd->offhook, pos); - DBG("chan=%d (open_counter=%d)\n", pos, xbus->open_counter); + DBG(GENERAL, "chan=%d (open_counter=%d)\n", pos, xbus->open_counter); spin_unlock_irqrestore(&xbus->lock, flags); if(xpd->xops->card_open) xpd->xops->card_open(xpd, pos); @@ -1451,9 +1489,9 @@ int xpp_close(struct zt_chan *chan) spin_unlock_irqrestore(&xbus->lock, flags); if(xpd->xops->card_close) xpd->xops->card_close(xpd, pos); - DBG("chan=%d (open_counter=%d, should_remove=%d)\n", pos, xbus->open_counter, should_remove); + DBG(GENERAL, "chan=%d (open_counter=%d, should_remove=%d)\n", pos, xbus->open_counter, should_remove); if(should_remove) { - XBUS_DBG(xbus, "Going to remove\n"); + XBUS_DBG(GENERAL, xbus, "Going to remove\n"); xbus_remove(xbus); } return 0; @@ -1473,11 +1511,11 @@ int xpp_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long arg) if (ret != -ENOTTY) return ret; } - DBG("ENOTTY: chan=%d cmd=0x%x\n", pos, cmd); - DBG(" IOC_TYPE=0x%02X\n", _IOC_TYPE(cmd)); - DBG(" IOC_DIR=0x%02X\n", _IOC_DIR(cmd)); - DBG(" IOC_NR=0x%02X\n", _IOC_NR(cmd)); - DBG(" IOC_SIZE=0x%02X\n", _IOC_SIZE(cmd)); + DBG(GENERAL, "ENOTTY: chan=%d cmd=0x%x\n", pos, cmd); + DBG(GENERAL, " IOC_TYPE=0x%02X\n", _IOC_TYPE(cmd)); + DBG(GENERAL, " IOC_DIR=0x%02X\n", _IOC_DIR(cmd)); + DBG(GENERAL, " IOC_NR=0x%02X\n", _IOC_NR(cmd)); + DBG(GENERAL, " IOC_SIZE=0x%02X\n", _IOC_SIZE(cmd)); return -ENOTTY; } return 0; @@ -1492,7 +1530,7 @@ static int xpp_hooksig(struct zt_chan *chan, zt_txsig_t txsig) BUG_ON(!xpd); xbus = xpd->xbus; BUG_ON(!xbus); - DBG("Setting %s to %s (%d)\n", chan->name, txsig2str(txsig), txsig); + DBG(GENERAL, "Setting %s to %s (%d)\n", chan->name, txsig2str(txsig), txsig); return CALL_XMETHOD(card_hooksig, xbus, xpd, pos, txsig); } @@ -1510,7 +1548,7 @@ int xpp_maint(struct zt_span *span, int cmd) #endif BUG_ON(!xpd); - DBG("span->mainttimer=%d\n", span->mainttimer); + DBG(GENERAL, "span->mainttimer=%d\n", span->mainttimer); switch(cmd) { case ZT_MAINT_NONE: printk("XXX Turn off local and remote loops XXX\n"); @@ -1596,7 +1634,7 @@ static int xpp_watchdog(struct zt_span *span, int cause) static int rate_limit = 0; if((rate_limit++ % 1000) == 0) - DBG("\n"); + DBG(GENERAL, "\n"); return 0; } #endif @@ -1624,8 +1662,6 @@ static int zaptel_unregister_xpd(xpd_t *xpd) spin_unlock_irqrestore(&xpd->lock, flags); return -EIDRM; } - if(sync_master == xpd) - sync_master_is(NULL); // FIXME: it's better to elect a new prince update_xpd_status(xpd, ZT_ALARM_NOTOPEN); if(atomic_read(&xpd->open_counter)) { XPD_NOTICE(xpd, "Busy (open_counter=%d). Skipping.\n", atomic_read(&xpd->open_counter)); @@ -1662,7 +1698,7 @@ static int zaptel_register_xpd(xpd_t *xpd) return -EEXIST; } cn = xpd->channels; - XPD_DBG(xpd, "Initializing span: %d channels.\n", cn); + XPD_DBG(GENERAL, xpd, "Initializing span: %d channels.\n", cn); memset(xpd->chans, 0, sizeof(struct zt_chan)*cn); memset(&xpd->span, 0, sizeof(struct zt_span)); @@ -1691,7 +1727,7 @@ static int zaptel_register_xpd(xpd_t *xpd) snprintf(xpd->span.desc, MAX_SPANDESC, "Xorcom XPD #%02d/%1d%1d: %s", xbus->num, xpd->addr.unit, xpd->addr.subunit, xpd->type_name); - XPD_DBG(xpd, "Registering span '%s'\n", xpd->span.desc); + XPD_DBG(GENERAL, xpd, "Registering span '%s'\n", xpd->span.desc); xpd->xops->card_zaptel_preregistration(xpd, 1); if(zt_register(&xpd->span, prefmaster)) { XPD_ERR(xpd, "Failed to zt_register span\n"); @@ -1743,10 +1779,10 @@ static void do_cleanup(void) del_timer_sync(&xpp_timer); tasklet_kill(&tasklet_tick); #ifdef CONFIG_PROC_FS - DBG("Removing '%s' from proc\n", PROC_SYNC); + DBG(GENERAL, "Removing '%s' from proc\n", PROC_SYNC); remove_proc_entry(PROC_SYNC, xpp_proc_toplevel); if(xpp_proc_toplevel) { - DBG("Removing '%s' from proc\n", PROC_DIR); + DBG(GENERAL, "Removing '%s' from proc\n", PROC_DIR); remove_proc_entry(PROC_DIR, NULL); xpp_proc_toplevel = NULL; } @@ -1806,7 +1842,7 @@ int __init xpp_zap_init(void) /* Only timer init. We add it only *after* zt_register */ init_timer(&xpp_timer); - sync_master_is(NULL); /* Internal ticking */ + sync_master_is("INIT", NULL); /* Internal ticking */ return 0; err: do_cleanup(); @@ -1833,6 +1869,7 @@ EXPORT_SYMBOL(xpp_open); EXPORT_SYMBOL(xpp_close); EXPORT_SYMBOL(xpp_ioctl); EXPORT_SYMBOL(xpp_maint); +EXPORT_SYMBOL(elect_syncer); MODULE_DESCRIPTION("XPP Zaptel Driver"); MODULE_AUTHOR("Oron Peled "); diff --git a/xpp/xpp_zap.h b/xpp/xpp_zap.h index 9a3c9fd..1b6d183 100644 --- a/xpp/xpp_zap.h +++ b/xpp/xpp_zap.h @@ -25,6 +25,7 @@ #include "xpd.h" #include "xproto.h" +void elect_syncer(const char *msg); void xpd_disconnect(xpd_t *xpd); void card_detected(struct card_desc_struct *card_desc); xpd_t *xpd_alloc(size_t privsize, const xproto_table_t *proto_table, int channels); diff --git a/xpp/xproto.c b/xpp/xproto.c index 4796ed3..c512479 100644 --- a/xpp/xproto.c +++ b/xpp/xproto.c @@ -55,7 +55,7 @@ const xproto_entry_t *xproto_card_entry(const xproto_table_t *table, byte opcode { const xproto_entry_t *xe; - //DBG("\n"); + //DBG(GENERAL, "\n"); xe = &table->entries[opcode]; return (xe->handler != NULL) ? xe : NULL; } @@ -65,7 +65,7 @@ const xproto_entry_t *xproto_global_entry(byte opcode) const xproto_entry_t *xe; xe = xproto_card_entry(&PROTO_TABLE(GLOBAL), opcode); - //DBG("opcode=0x%X xe=%p\n", opcode, xe); + //DBG(GENERAL, "opcode=0x%X xe=%p\n", opcode, xe); return xe; } @@ -99,7 +99,7 @@ const xproto_table_t *xproto_get(xpd_type_t cardtype) } if(xtable) { BUG_ON(!xtable->owner); - DBG("%s refcount was %d\n", xtable->name, module_refcount(xtable->owner)); + DBG(GENERAL, "%s refcount was %d\n", xtable->name, module_refcount(xtable->owner)); if(!try_module_get(xtable->owner)) { ERR("%s: try_module_get for %s failed.\n", __FUNCTION__, xtable->name); return NULL; @@ -111,7 +111,7 @@ const xproto_table_t *xproto_get(xpd_type_t cardtype) void xproto_put(const xproto_table_t *xtable) { BUG_ON(!xtable); - DBG("%s refcount was %d\n", xtable->name, module_refcount(xtable->owner)); + DBG(GENERAL, "%s refcount was %d\n", xtable->name, module_refcount(xtable->owner)); BUG_ON(module_refcount(xtable->owner) <= 0); module_put(xtable->owner); } @@ -120,7 +120,7 @@ xproto_handler_t xproto_card_handler(const xproto_table_t *table, byte opcode) { const xproto_entry_t *xe; - //DBG("\n"); + //DBG(GENERAL, "\n"); xe = xproto_card_entry(table, opcode); return xe->handler; } @@ -237,11 +237,11 @@ int xframe_receive(xbus_t *xbus, xframe_t *xframe) len = pack->datalen; /* Sanity checks */ if(unlikely(is_pcm && pack->opcode != XPROTO_NAME(GLOBAL,PCM_READ) && printk_ratelimit())) { - XBUS_DBG(xbus, "Non-PCM packet within a PCM xframe\n"); + XBUS_DBG(GENERAL, xbus, "Non-PCM packet within a PCM xframe\n"); dump_xframe("In PCM xframe", xbus, xframe); // goto bad_proto; } else if(unlikely(!is_pcm && pack->opcode == XPROTO_NAME(GLOBAL,PCM_READ) && printk_ratelimit())) { - XBUS_DBG(xbus, "A PCM packet within a Non-PCM xframe\n"); + XBUS_DBG(GENERAL, xbus, "A PCM packet within a Non-PCM xframe\n"); // goto bad_proto; } p += len; @@ -278,7 +278,7 @@ void dump_packet(const char *msg, xpacket_t *packet, bool print_dbg) if(!print_dbg) return; - DBG("%s: XPD=%1X-%1X (0x%X) OP=0x%02X LEN=%d", + DBG(GENERAL, "%s: XPD=%1X-%1X (0x%X) OP=0x%02X LEN=%d", msg, packet->addr.unit, packet->addr.subunit, @@ -297,8 +297,8 @@ void dump_packet(const char *msg, xpacket_t *packet, bool print_dbg) if(i >= sizeof(xpacket_t)) { if(limiter < ERR_REPORT_LIMIT) { - ERR("%s: length overflow i=%d > sizeof(xpacket_t)=%d\n", - __FUNCTION__, i+1, sizeof(xpacket_t)); + ERR("%s: length overflow i=%d > sizeof(xpacket_t)=%lu\n", + __FUNCTION__, i+1, (long)sizeof(xpacket_t)); } else if(limiter == ERR_REPORT_LIMIT) { ERR("%s: error packet #%d... squelsh reports.\n", __FUNCTION__, limiter); @@ -328,20 +328,20 @@ void dump_reg_cmd(const char msg[], const reg_cmd_t *regcmd, bool writing) action = (writing) ? 'W' : 'R'; chipsel = REG_FIELD(regcmd, chipsel) & ~0x80; if(REG_FIELD(regcmd, do_subreg)) { - DBG("%s: %d %cS %02X %02X [%02X] # data_high=%X m=%d eof=%d\n", msg, chipsel, action, + DBG(GENERAL, "%s: %d %cS %02X %02X [%02X] # data_high=%X m=%d eof=%d\n", msg, chipsel, action, REG_FIELD(regcmd, regnum), REG_FIELD(regcmd, subreg), REG_FIELD(regcmd, data_low), REG_FIELD(regcmd, data_high), regcmd->multibyte, regcmd->eoframe); } else if(REG_FIELD(regcmd, regnum) == 0x1E) { - DBG("%s: %d %cI %02X [%02X %02X] # m=%d eof=%d\n", msg, chipsel, action, + DBG(GENERAL, "%s: %d %cI %02X [%02X %02X] # m=%d eof=%d\n", msg, chipsel, action, REG_FIELD(regcmd, subreg), REG_FIELD(regcmd, data_low), REG_FIELD(regcmd, data_high), regcmd->multibyte, regcmd->eoframe); } else { - DBG("%s: %d %cD %02X [%02X] # data_high=%X m=%d eof=%d\n", msg, chipsel, action, + DBG(GENERAL, "%s: %d %cD %02X [%02X] # data_high=%X m=%d eof=%d\n", msg, chipsel, action, REG_FIELD(regcmd, regnum), REG_FIELD(regcmd, data_low), REG_FIELD(regcmd, data_high), @@ -379,7 +379,7 @@ int xproto_register(const xproto_table_t *proto_table) NOTICE("%s: Bad xproto type %d\n", __FUNCTION__, type); return -EINVAL; } - DBG("%s (%d)\n", name, type); + DBG(GENERAL, "%s (%d)\n", name, type); if(xprotocol_tables[type]) NOTICE("%s: overriding registration of %s (%d)\n", __FUNCTION__, name, type); xops = &proto_table->xops; @@ -409,7 +409,7 @@ void xproto_unregister(const xproto_table_t *proto_table) BUG_ON(!proto_table); type = proto_table->type; name = proto_table->name; - DBG("%s (%d)\n", name, type); + DBG(GENERAL, "%s (%d)\n", name, type); if(type >= XPD_TYPE_NOMODULE) { NOTICE("%s: Bad xproto type %s (%d)\n", __FUNCTION__, name, type); return; diff --git a/xpp/zap_debug.h b/xpp/zap_debug.h index a234cca..ff4b554 100644 --- a/xpp/zap_debug.h +++ b/xpp/zap_debug.h @@ -39,35 +39,41 @@ printk(KERN_ ## level "%s-%s: %s/%s/%d: " fmt, #level, \ THIS_MODULE->name, (xpd)->xbus->busname, (xpd)->xpdname, (pos), ## __VA_ARGS__) -#define DBG(fmt, ...) \ - ((void)((print_dbg) && PRINTK(DEBUG, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__))) +#define DBG(bits, fmt, ...) \ + ((void)((print_dbg & (DBG_ ## bits)) && PRINTK(DEBUG, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__))) #define INFO(fmt, ...) PRINTK(INFO, fmt, ## __VA_ARGS__) #define NOTICE(fmt, ...) PRINTK(NOTICE, fmt, ## __VA_ARGS__) #define WARNING(fmt, ...) PRINTK(WARNING, fmt, ## __VA_ARGS__) #define ERR(fmt, ...) PRINTK(ERR, fmt, ## __VA_ARGS__) -#define XBUS_DBG(xbus, fmt, ...) \ - ((void)((print_dbg) && XBUS_PRINTK(DEBUG, xbus, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__))) +#define XBUS_DBG(bits, xbus, fmt, ...) \ + ((void)((print_dbg & (DBG_ ## bits)) && XBUS_PRINTK(DEBUG, xbus, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__))) #define XBUS_INFO(xbus, fmt, ...) XBUS_PRINTK(INFO, xbus, fmt, ## __VA_ARGS__) #define XBUS_NOTICE(xbus, fmt, ...) XBUS_PRINTK(NOTICE, xbus, fmt, ## __VA_ARGS__) #define XBUS_ERR(xbus, fmt, ...) XBUS_PRINTK(ERR, xbus, fmt, ## __VA_ARGS__) -#define XPD_DBG(xpd, fmt, ...) \ - ((void)((print_dbg) && XPD_PRINTK(DEBUG, xpd, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__))) +#define XPD_DBG(bits, xpd, fmt, ...) \ + ((void)((print_dbg & (DBG_ ## bits)) && XPD_PRINTK(DEBUG, xpd, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__))) #define XPD_INFO(xpd, fmt, ...) XPD_PRINTK(INFO, xpd, fmt, ## __VA_ARGS__) #define XPD_NOTICE(xpd, fmt, ...) XPD_PRINTK(NOTICE, xpd, fmt, ## __VA_ARGS__) #define XPD_WARNING(xpd, fmt, ...) XPD_PRINTK(WARNING, xpd, fmt, ## __VA_ARGS__) #define XPD_ERR(xpd, fmt, ...) XPD_PRINTK(ERR, xpd, fmt, ## __VA_ARGS__) -#define LINE_DBG(xpd, pos, fmt, ...) \ - ((void)((print_dbg) && LINE_PRINTK(DEBUG, xpd, pos, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__))) +#define LINE_DBG(bits, xpd, pos, fmt, ...) \ + ((void)((print_dbg & (DBG_ ## bits)) && LINE_PRINTK(DEBUG, xpd, pos, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__))) #define LINE_NOTICE(xpd, pos, fmt, ...) LINE_PRINTK(NOTICE, xpd, pos, fmt, ## __VA_ARGS__) /* * Bits for print_dbg */ -#define DBG_DEFAULT 0x01 -#define DBG_PCM 0x02 +#define DBG_GENERAL BIT(0) +#define DBG_PCM BIT(1) +#define DBG_LEDS BIT(2) +#define DBG_SYNC BIT(3) +#define DBG_SIGNAL BIT(4) +#define DBG_PROC BIT(5) +#define DBG_REGS BIT(6) +#define DBG_ANY (~0) void dump_poll(int print_dbg, const char *msg, int poll); diff --git a/zaptel.sysconfig b/zaptel.sysconfig index 41872f9..c215109 100644 --- a/zaptel.sysconfig +++ b/zaptel.sysconfig @@ -31,3 +31,17 @@ MODULES="$MODULES wcusb" # S100U - Single port FXS USB Interface #MODULES="$MODULES ztdummy" # UHCI USB Zaptel Timing Only Interface #MODULES="$MODULES xpp_usb" # Xorcom Astribank Device + +# Disables Astribank hotplug firmware loading +#XPP_HOTPLUG_DISABLED=yes +# +# Disables Astribank udev hook called when an astribank is added and ready +# or removed. +#ASTRIBANK_HOOK_DISABLED=yes + +# Extensions genzaptelconf are (base + channel_number) +# base is by default 6000: +#base_exten=6000 +# +# There are a host of other variables you can set to affect +# genzaptelconf. See the beginning of the script. -- cgit v1.2.3