[zaptel-commits] tzafrir: branch 1.2 r2811 - in /branches/1.2/xpp: ./ firmwares/ utils/

SVN commits to the Zaptel project zaptel-commits at lists.digium.com
Wed Aug 1 16:33:57 CDT 2007


Author: tzafrir
Date: Wed Aug  1 16:33:56 2007
New Revision: 2811

URL: http://svn.digium.com/view/zaptel?view=rev&rev=2811
Log:
xpp.r4415:
  * Show Astribank 6+2 as 6/2 channels and not 8/8 channels.
    - Added as a "subtype" to the device type (r4391).
  * Fixed a panic in BRI span shutdown method (r4393).
  * Changes to debug macros.
  * Add proper sysfs support (r4406)
    - A bus on whuch all of the Astribanks reside.
    - Replaces useless sysfs code that existed in the module.
    - Currently used to set the sync source automatically at device
      adition / removal.
  * BRI: We do need the T1 timer in NT. If it gets into G2 state (rr4407).

Added:
    branches/1.2/xpp/utils/astribank_hook   (with props)
    branches/1.2/xpp/xbus-sysfs.c   (with props)
Modified:
    branches/1.2/xpp/.version
    branches/1.2/xpp/ChangeLog
    branches/1.2/xpp/Makefile
    branches/1.2/xpp/card_bri.c
    branches/1.2/xpp/card_fxo.c
    branches/1.2/xpp/card_fxs.c
    branches/1.2/xpp/card_global.h
    branches/1.2/xpp/firmwares/FPGA_1141.hex
    branches/1.2/xpp/firmwares/FPGA_1151.hex
    branches/1.2/xpp/firmwares/FPGA_FXS.hex
    branches/1.2/xpp/utils/Makefile
    branches/1.2/xpp/utils/xpp.rules
    branches/1.2/xpp/utils/xpp_fxloader
    branches/1.2/xpp/xbus-core.c
    branches/1.2/xpp/xbus-core.h
    branches/1.2/xpp/xpd.h
    branches/1.2/xpp/xpp_usb.c
    branches/1.2/xpp/xpp_zap.c
    branches/1.2/xpp/xpp_zap.h
    branches/1.2/xpp/xproto.c
    branches/1.2/xpp/xproto.h
    branches/1.2/xpp/zap_debug.h

Modified: branches/1.2/xpp/.version
URL: http://svn.digium.com/view/zaptel/branches/1.2/xpp/.version?view=diff&rev=2811&r1=2810&r2=2811
==============================================================================
--- branches/1.2/xpp/.version (original)
+++ branches/1.2/xpp/.version Wed Aug  1 16:33:56 2007
@@ -1,1 +1,1 @@
-trunk-r4372
+trunk-r4415

Modified: branches/1.2/xpp/ChangeLog
URL: http://svn.digium.com/view/zaptel/branches/1.2/xpp/ChangeLog?view=diff&rev=2811&r1=2810&r2=2811
==============================================================================
--- branches/1.2/xpp/ChangeLog (original)
+++ branches/1.2/xpp/ChangeLog Wed Aug  1 16:33:56 2007
@@ -1,3 +1,15 @@
+Thu Jul 30 2007 Oron Peled <oron at actcom.co.il> - xpp.r4415
+  * Show Astribank 6+2 as 6/2 channels and not 8/8 channels.
+    - Added as a "subtype" to the device type (r4391).
+  * Fixed a panic in BRI span shutdown method (r4393).
+  * Changes to debug macros.
+  * Add proper sysfs support (r4406)
+    - A bus on whuch all of the Astribanks reside.
+    - Replaces useless sysfs code that existed in the module.
+    - Currently used to set the sync source automatically at device
+      adition / removal.
+  * BRI: We do need the T1 timer in NT. If it gets into G2 state (rr4407).
+
 Thu Jul 12 2007 Oron Peled <oron at actcom.co.il> - xpp.r4372
   * Update to zaptel-1.2.18 and zaptel-1.4.3 (r4308 onward)
   * Fix a critical race with zaptel synchronization (r4362)

Modified: branches/1.2/xpp/Makefile
URL: http://svn.digium.com/view/zaptel/branches/1.2/xpp/Makefile?view=diff&rev=2811&r1=2810&r2=2811
==============================================================================
--- branches/1.2/xpp/Makefile (original)
+++ branches/1.2/xpp/Makefile Wed Aug  1 16:33:56 2007
@@ -5,7 +5,6 @@
 			-DDEBUG			\
 			-DPOLL_DIGITAL_INPUTS	\
 			-DWITH_ECHO_SUPPRESSION	\
-			-DPROTOCOL_DEBUG	\
 			-DWITH_METERING		\
 			-DDEBUG_PCMTX		\
 			-DPROTOCOL_DEBUG	\
@@ -28,7 +27,7 @@
 obj-m		+= xpd_bri.o
 endif
 
-xpp-y		+= xbus-core.o xpp_zap.o xproto.o card_global.o
+xpp-y		+= xbus-core.o xbus-sysfs.o xpp_zap.o xproto.o card_global.o
 xpd_fxs-y	+= card_fxs.o
 xpd_fxo-y	+= card_fxo.o
 xpd_bri-y	+= card_bri.o

Modified: branches/1.2/xpp/card_bri.c
URL: http://svn.digium.com/view/zaptel/branches/1.2/xpp/card_bri.c?view=diff&rev=2811&r1=2810&r2=2811
==============================================================================
--- branches/1.2/xpp/card_bri.c (original)
+++ branches/1.2/xpp/card_bri.c Wed Aug  1 16:33:56 2007
@@ -258,13 +258,12 @@
 	char	debug_buf[DEBUG_BUF_SIZE + 1];
 	int	i;
 	int	n = 0;
-	xbus_t	*xbus = xpd->xbus;
 
 	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]);
-	DBG("%s/%s: %s[0..%d]: %s%s\n", xbus->busname, xpd->xpdname, msg,
-			len-1, debug_buf, (n >= DEBUG_BUF_SIZE)?"...":"");
+	XPD_DBG(xpd, "%s[0..%d]: %s%s\n", msg, len-1, debug_buf,
+			(n >= DEBUG_BUF_SIZE)?"...":"");
 }
 
 static void dump_dchan_packet(xpd_t *xpd, bool transmit, byte *buf, int len)
@@ -292,7 +291,7 @@
 		else if(IS_SET(buf[0], 7) && IS_SET(buf[0], 6))
 			ftype = 'U';	/* Unnumbered */
 		else
-			NOTICE("Unknown frame type 0x%X\n", buf[0]);
+			XPD_NOTICE(xpd, "Unknown frame type 0x%X\n", buf[0]);
 
 		snprintf(msgbuf, MAX_PROC_WRITE, "D-Chan %s = (%c) ", direction, ftype);
 	} else {
@@ -311,8 +310,7 @@
 	if(priv->layer1_up == up)
 		return;
 	priv->layer1_up = up;
-	DBG("%s/%s: STATE CHANGE: Layer1 %s\n", xpd->xbus->busname, xpd->xpdname,
-		(up)?"UP":"DOWN");
+	XPD_DBG(xpd, "STATE CHANGE: Layer1 %s\n", (up)?"UP":"DOWN");
 }
 
 static void dchan_state(xpd_t *xpd, bool up)
@@ -325,12 +323,10 @@
 	if(priv->dchan_alive == up)
 		return;
 	if(up) {
-		DBG("%s/%s: STATE CHANGE: D-Channel RUNNING\n",
-			xpd->xbus->busname, xpd->xpdname);
+		XPD_DBG(xpd, "STATE CHANGE: D-Channel RUNNING\n");
 		priv->dchan_alive = 1;
 	} else {
-		DBG("%s/%s: STATE CHANGE: D-Channel STOPPED\n",
-			xpd->xbus->busname, xpd->xpdname);
+		XPD_DBG(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;
@@ -346,33 +342,32 @@
 	priv = xpd->priv;
 	BUG_ON(!priv);
 	xbus = xpd->xbus;
-	DBG("%s/%s: %s\n", xbus->busname, xpd->xpdname, (on)?"ON":"OFF");
+	XPD_DBG(xpd, "%s\n", (on)?"ON":"OFF");
 	switch(xpd->type) {
 		case XPD_TYPE_BRI_TE:
 			if(on) {
-				DBG("%s/%s: HFC_L1_ACTIVATE_TE\n", xbus->busname, xpd->xpdname);
+				XPD_DBG(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 {
-				DBG("%s/%s: HFC_L1_FORCE_DEACTIVATE_TE\n", xbus->busname, xpd->xpdname);
+				XPD_DBG(xpd, "HFC_L1_FORCE_DEACTIVATE_TE\n");
 				write_state_register(xpd, STA_DEACTIVATE);
 			}
 			break;
 		case XPD_TYPE_BRI_NT:
 			if(on) {
-				DBG("%s/%s: HFC_L1_ACTIVATE_NT\n", xbus->busname, xpd->xpdname);
+				XPD_DBG(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 {
-				DBG("%s/%s: HFC_L1_DEACTIVATE_NT\n", xbus->busname, xpd->xpdname);
+				XPD_DBG(xpd, "HFC_L1_DEACTIVATE_NT\n");
 				write_state_register(xpd, STA_DEACTIVATE);
 			}
 			break;
 		default:
-			ERR("%s: %s/%s: Bad xpd type %d\n", __FUNCTION__,
-					xbus->busname, xpd->xpdname, xpd->type);
+			XPD_ERR(xpd, "%s: Bad xpd type %d\n", __FUNCTION__, xpd->type);
 			BUG();
 	}
 }
@@ -413,7 +408,7 @@
 		static int rate_limit;
 
 		if((rate_limit++ % 1000) == 0)
-			DBG("%s/%s: D-Chan unused\n", xbus->busname, xpd->xpdname);
+			XPD_DBG(xpd, "D-Chan unused\n");
 		dchan->bytes2receive = 0;
 		dchan->bytes2transmit = 0;
 		goto out;
@@ -421,7 +416,7 @@
 	dchan_buf = dchan->readchunk;
 	idx = priv->dchan_r_idx;
 	if(idx + len >= DCHAN_BUFSIZE) {
-		ERR("%s/%s: D-Chan RX overflow: %d\n", xbus->busname, xpd->xpdname, idx);
+		XPD_ERR(xpd, "D-Chan RX overflow: %d\n", idx);
 		dump_hex_buf(xpd, "    current packet", src, len);
 		dump_hex_buf(xpd, "    dchan_buf", dchan_buf, idx);
 		ret = -ENOSPC;
@@ -436,15 +431,14 @@
 	if(!eoframe)
 		goto out;
 	if(idx < 4) {
-		NOTICE("%s/%s: D-Chan RX short frame (idx=%d)\n", xbus->busname, xpd->xpdname, idx);
+		XPD_NOTICE(xpd, "D-Chan RX short frame (idx=%d)\n", idx);
 		dump_hex_buf(xpd, "D-Chan RX:    current packet", src, len);
 		dump_hex_buf(xpd, "D-Chan RX:    chan_buf", dchan_buf, idx);
 		ret = -EPROTO;
 		goto drop;
 	}
 	if(dchan_buf[idx-1]) {
-		NOTICE("%s/%s: D-Chan RX Bad checksum: [%02X:%02X=%02X] (%d)\n",
-				xbus->busname, xpd->xpdname,
+		XPD_NOTICE(xpd, "D-Chan RX Bad checksum: [%02X:%02X=%02X] (%d)\n",
 				dchan_buf[idx-3], dchan_buf[idx-2], dchan_buf[idx-1], dchan_buf[idx-1]);
 		dump_hex_buf(xpd, "D-Chan RX:    current packet", src, len);
 		dump_hex_buf(xpd, "D-Chan RX:    chan_buf", dchan_buf, idx);
@@ -484,7 +478,7 @@
 	 *   eoftx==0: Stop sending us D-channel packets.
 	 */
 	if(len > MULTIBYTE_MAX_LEN) {
-		ERR("%s: len=%d is too long. dropping.\n", __FUNCTION__, len);
+		XPD_ERR(xpd, "%s: len=%d is too long. dropping.\n", __FUNCTION__, len);
 		return -EINVAL;
 	}
 	XFRAME_NEW(xframe, pack, xbus, BRI, REGISTER_REQUEST, xpd->xbus_idx);
@@ -495,7 +489,7 @@
 	if(len > 0) {
 		memcpy(REG_XDATA(reg_cmd), (byte *)buf, len);
 	} else {
-		DBG("Magic Packet (eoftx=%d)\n", eoftx);
+		XPD_DBG(xpd, "Magic Packet (eoftx=%d)\n", eoftx);
 	}
 #ifdef XPP_DEBUGFS
 	xbus_log(xbus, xpd, 1, reg_cmd, sizeof(reg_cmd_t));	/* 1 = TX */
@@ -505,7 +499,7 @@
 #endif
 	ret = send_cmd_frame(xbus, xframe);
 	if(ret < 0)
-		NOTICE("%s: %s: failed sending xframe\n", __FUNCTION__, xbus->busname);
+		XPD_NOTICE(xpd, "%s: failed sending xframe\n", __FUNCTION__);
 	return ret;
 }
 
@@ -529,7 +523,7 @@
 			/* timer expired ? */
 			if (--priv->t3 == 0) {
 				if ((rate_limit % 1003) >= 5)
-					DBG("%s/%s: T3 expired\n", xpd->xbus->busname, xpd->xpdname);
+					XPD_DBG(xpd, "T3 expired\n");
 				priv->t3 = HFC_TIMER_OFF;
 				clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags);
 				xpd_activation(xpd, 0);		/* Deactivate TE */
@@ -539,7 +533,7 @@
 			/* timer expired ? */
 			if (--priv->t4 == 0) {
 				if ((rate_limit % 1003) >= 5)
-					DBG("%s/%s: T4 expired\n", xpd->xbus->busname, xpd->xpdname);
+					XPD_DBG(xpd, "T4 expired\n");
 				priv->t4 = HFC_TIMER_OFF;
 			}
 		}
@@ -557,11 +551,11 @@
 	if(len <= 0)
 		return 0; /* Nothing to transmit on D channel */
 	if(len > MULTIBYTE_MAX_LEN) {
-		ERR("%s: len=%d. need to split. Unimplemented.\n", __FUNCTION__, len);
+		XPD_ERR(xpd, "%s: len=%d. need to split. Unimplemented.\n", __FUNCTION__, len);
 		return -EINVAL;
 	}
 	if(!test_bit(HFC_L1_ACTIVATED, &priv->l1_flags) && !test_bit(HFC_L1_ACTIVATING, &priv->l1_flags)) {
-		DBG("%s/%s: Kick D-Channel transmiter\n", xpd->xbus->busname, xpd->xpdname);
+		XPD_DBG(xpd, "Kick D-Channel transmiter\n");
 		xpd_activation(xpd, 1);
 		return 0;
 	}
@@ -573,8 +567,7 @@
 		priv->txframe_begin = 0;
 	ret = send_bri_multibyte(xpd, priv->dchan_tbuf, len, eoframe);
 	if(ret < 0)
-		NOTICE("%s/%s: %s: failed sending xframe\n",
-				__FUNCTION__, xpd->xbus->busname, xpd->xpdname);
+		XPD_NOTICE(xpd, "%s: failed sending xframe\n", __FUNCTION__);
 	if(eoframe)
 		priv->dchan_tx_counter++;
 	priv->dchan_notx_ticks = 0;
@@ -583,13 +576,12 @@
 
 /*---------------- BRI: Methods -------------------------------------------*/
 
-static xpd_t *BRI_card_new(xbus_t *xbus, int unit, int subunit, const xproto_table_t *proto_table, byte revision)
+static xpd_t *BRI_card_new(xbus_t *xbus, int unit, int subunit, const xproto_table_t *proto_table, byte subtype, byte revision)
 {
 	xpd_t		*xpd = NULL;
 	int		channels = min(3, CHANNELS_PERXPD);
 
-	DBG("\n");
-
+	XBUS_DBG(xbus, "\n");
 	xpd = xpd_alloc(sizeof(struct BRI_priv_data), proto_table, channels);
 	if(!xpd)
 		return NULL;
@@ -605,15 +597,15 @@
 
 	BUG_ON(!xpd);
 	priv = xpd->priv;
-	DBG("%s/%s\n", xbus->busname, xpd->xpdname);
+	XPD_DBG(xpd, "\n");
 #ifdef	CONFIG_PROC_FS
 	if(priv->regfile) {
-		DBG("Removing registers file for %s/%s\n", xbus->busname, xpd->xpdname);
+		XPD_DBG(xpd, "Removing registers file\n");
 		priv->regfile->data = NULL;
 		remove_proc_entry(PROC_REGISTER_FNAME, xpd->proc_xpd_dir);
 	}
 	if(priv->bri_info) {
-		DBG("Removing xpd BRI_INFO file %s/%s\n", xbus->busname, xpd->xpdname);
+		XPD_DBG(xpd, "Removing xpd BRI_INFO file\n");
 		remove_proc_entry(PROC_BRI_INFO_FNAME, xpd->proc_xpd_dir);
 	}
 #endif
@@ -624,23 +616,22 @@
 	struct BRI_priv_data	*priv;
 	int			ret = 0;
 
-	DBG("\n");
-
 	BUG_ON(!xpd);
+	XPD_DBG(xpd, "\n");
 	priv = xpd->priv;
 #ifdef	CONFIG_PROC_FS
-	DBG("Creating BRI_INFO file for %s/%s\n", xbus->busname, xpd->xpdname);
+	XPD_DBG(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) {
-		ERR("Failed to create proc '%s' for %s/%s\n", PROC_BRI_INFO_FNAME, xbus->busname, xpd->xpdname);
+		XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_BRI_INFO_FNAME);
 		ret = -ENOENT;
 		goto err;
 	}
 	priv->bri_info->owner = THIS_MODULE;
-	DBG("Creating registers file for %s/%s\n", xbus->busname, xpd->xpdname);
+	XPD_DBG(xpd, "Creating registers file\n");
 	priv->regfile = create_proc_entry(PROC_REGISTER_FNAME, 0644, xpd->proc_xpd_dir);
 	if(!priv->regfile) {
-		ERR("Failed to create proc file for registers of %s/%s\n", xbus->busname, xpd->xpdname);
+		XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_REGISTER_FNAME);
 		goto err;
 	}
 	priv->regfile->owner = THIS_MODULE;
@@ -657,13 +648,12 @@
 	 *     Force HOST sync *before* sending PCM
 	 */
 	CALL_PROTO(GLOBAL, SYNC_SOURCE, xbus, NULL, SYNC_MODE_HOST, 0);
-	DBG("done: %s/%s\n", xbus->busname, xpd->xpdname);
-
+	XPD_DBG(xpd, "done\n");
 	priv->initialized = 1;
 	return 0;
 err:
 	clean_proc(xbus, xpd);
-	ERR("%s/%s: Failed initializing registers (%d)\n", xbus->busname, xpd->xpdname, ret);
+	XPD_ERR(xpd, "Failed initializing registers (%d)\n", ret);
 	return ret;
 }
 
@@ -673,7 +663,7 @@
 
 	BUG_ON(!xpd);
 	priv = xpd->priv;
-	DBG("%s/%s\n", xbus->busname, xpd->xpdname);
+	XPD_DBG(xpd, "\n");
 	clean_proc(xbus, xpd);
 	return 0;
 }
@@ -691,7 +681,7 @@
 	xbus = xpd->xbus;
 	priv = xpd->priv;
 	BUG_ON(!xbus);
-	DBG("%s/%s: %s\n", xbus->busname, xpd->xpdname, (on)?"on":"off");
+	XPD_DBG(xpd, "%s\n", (on)?"on":"off");
 	if(!on) {
 		/* Nothing to do yet */
 		return 0;
@@ -702,7 +692,7 @@
 	for_each_line(xpd, i) {
 		struct zt_chan	*cur_chan = &xpd->chans[i];
 
-		DBG("setting BRI channel %d\n", i);
+		XPD_DBG(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);
@@ -766,13 +756,13 @@
 	xbus = xpd->xbus;
 	priv = xpd->priv;
 	BUG_ON(!xbus);
-	DBG("%s/%s: %s\n", xbus->busname, xpd->xpdname, (on)?"on":"off");
+	XPD_DBG(xpd, "%s\n", (on)?"on":"off");
 	return(0);
 }
 
 int BRI_card_hooksig(xbus_t *xbus, xpd_t *xpd, int pos, zt_txsig_t txsig)
 {
-	DBG("%s/%s/%d: %s\n", xbus->busname, xpd->xpdname, pos, txsig2str(txsig));
+	LINE_DBG(xpd, pos, "%s\n", txsig2str(txsig));
 	return 0;
 }
 
@@ -857,7 +847,7 @@
 	if(!priv->initialized)
 		return 0;
 	if(poll_interval != 0 && (priv->tick_counter % poll_interval) == 0) {
-		// DBG("%d\n", priv->tick_counter);
+		// XPD_DBG(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);
 	}
@@ -878,32 +868,24 @@
 	/* Detect Layer1 disconnect */
 	if(priv->reg30_good && priv->reg30_ticks > poll_interval * REG30_LOST) {
 		/* No reply for 1/2 a second */
-		ERR("%s/%s: Lost state tracking for %d ticks\n",
-				xbus->busname, xpd->xpdname, priv->reg30_ticks);
+		XPD_ERR(xpd, "Lost state tracking for %d ticks\n", priv->reg30_ticks);
 		priv->reg30_good = 0;
 		layer1_state(xpd, 0);
 		dchan_state(xpd, 0);
 	}
 	handle_leds(xbus, xpd);
 	tx_dchan(xpd);
-#if	0
-	/*
-		Currently not used -- do we want to shut down NT if it wasn't
-		responding? For how long?
-	*/
-
 	/* Detect T1 timer expiry on NT */
 	if(IS_NT(xpd)) {
 		if (priv->t1 > HFC_TIMER_OFF) {
 			if (--priv->t1 == 0) {
-				DBG("%s/%s: T1 Expired. Kick NT\n", xbus->busname, xpd->xpdname);
+				XPD_DBG(xpd, "T1 Expired. Kick NT\n");
 				priv->t1 = HFC_TIMER_OFF;
 				clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags);
 				write_state_register(xpd, STA_DEACTIVATE);
 			}
 		}
 	}
-#endif
 	priv->tick_counter++;
 	priv->reg30_ticks++;
 	return 0;
@@ -948,8 +930,7 @@
 	/* E1's can enable CRC checking */
 	if (lc->lineconfig & ZT_CONFIG_CRC4)
 		crcstr = "CRC4";
-	DBG("%s/%s[%s]: span=%d (%s) lbo=%d lineconfig=%s/%s/%s (0x%X) sync=%d\n",
-		xpd->xbus->busname, xpd->xpdname,
+	XPD_DBG(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,
@@ -990,7 +971,11 @@
 	BUG_ON(!xpd);
 	priv = xpd->priv;
 	BUG_ON(!priv);
-	DBG("%s/%s: STARTUP\n", xpd->xbus->busname, xpd->xpdname);
+	if(!xpd->xbus->hardware_exists) {
+		XPD_DBG(xpd, "Startup called by zaptel. No Hardware. Ignored\n");
+		return -ENODEV;
+	}
+	XPD_DBG(xpd, "STARTUP\n");
 	// Turn on all channels
 	CALL_XMETHOD(XPD_STATE, xpd->xbus, xpd, 1);
 	write_state_register(xpd, 0);	/* Enable L1 state machine */
@@ -1021,7 +1006,11 @@
 	BUG_ON(!xpd);
 	priv = xpd->priv;
 	BUG_ON(!priv);
-	DBG("%s/%s: SHUTDOWN\n", xpd->xbus->busname, xpd->xpdname);
+	if(!xpd->xbus->hardware_exists) {
+		XPD_DBG(xpd, "Shutdown called by zaptel. No Hardware. Ignored\n");
+		return -ENODEV;
+	}
+	XPD_DBG(xpd, "SHUTDOWN\n");
 	// Turn off all channels
 	CALL_XMETHOD(XPD_STATE, xpd->xbus, xpd, 0);
 	if(IS_NT(xpd))
@@ -1134,8 +1123,7 @@
 	}
 	XFRAME_NEW(xframe, pack, xbus, BRI, REGISTER_REQUEST, xpd->xbus_idx);
 #if 0
-	DBG("%s/%s/%d: %c%c R%02X S%02X %02X %02X\n",
-			xbus->busname, xpd->xpdname, chipsel,
+	LINE_DBG(xpd, chipsel, "%c%c R%02X S%02X %02X %02X\n",
 			(writing)?'W':'R',
 			(do_subreg)?'S':'D',
 			regnum, subreg, data_low, data_high);
@@ -1156,20 +1144,20 @@
 /* 0x0F */ HOSTCMD(BRI, XPD_STATE, bool on)
 {
 	BUG_ON(!xpd);
-	DBG("%s/%s: %s\n", xbus->busname, xpd->xpdname, (on)?"ON":"OFF");
+	XPD_DBG(xpd, "%s\n", (on)?"ON":"OFF");
 	xpd_activation(xpd, on);
 	return 0;
 }
 
 /* 0x0F */ HOSTCMD(BRI, RING, lineno_t chan, bool on)
 {
-	ERR("%s: Unsupported\n", __FUNCTION__);
+	XPD_ERR(xpd, "%s: Unsupported\n", __FUNCTION__);
 	return -ENOSYS;
 }
 
 /* 0x0F */ HOSTCMD(BRI, RELAY_OUT, byte which, bool on)
 {
-	ERR("%s: Unsupported\n", __FUNCTION__);
+	XPD_ERR(xpd, "%s: Unsupported\n", __FUNCTION__);
 	return -ENOSYS;
 }
 
@@ -1185,8 +1173,7 @@
 	priv = xpd->priv;
 	BUG_ON(!priv);
 #if 0
-	DBG("%s/%s: %s -> %d\n",
-		xbus->busname, xpd->xpdname,
+	XPD_DBG(xpd, "%s -> %d\n",
 		(which_led)?"RED":"GREEN",
 		to_led_state);
 #endif
@@ -1204,7 +1191,7 @@
 {
 	int	ret;
 
-	DBG("%s/%s: value = 0x%02X\n", xpd->xbus->busname, xpd->xpdname, value);
+	XPD_DBG(xpd, "value = 0x%02X\n", value);
 	ret = CALL_PROTO(BRI, REGISTER_REQUEST, xpd->xbus, xpd,
 			0,		/* chipsel	*/
 			1,		/* writing	*/
@@ -1229,8 +1216,7 @@
 	BUG_ON(!priv);
 	xbus = xpd->xbus;
 	if(!priv->initialized) {
-		ERR("%s/%s: %s called on uninitialized AB\n",
-			xbus->busname, xpd->xpdname, __FUNCTION__);
+		XPD_ERR(xpd, "%s called on uninitialized AB\n", __FUNCTION__);
 		return;
 	}
 	new_state.reg = reg_x30;
@@ -1265,33 +1251,31 @@
 	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);
-	DBG("%s/%s: %s%i\n", xbus->busname, xpd->xpdname,
-				IS_NT(xpd)?"G":"F",
-				new_state.bits.v_su_sta);
+	XPD_DBG(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)) {
-			DBG("%s/%s: Disable T3 ?\n", xbus->busname, xpd->xpdname);
+			XPD_DBG(xpd, "Disable T3 ?\n");
 			priv->t3 = HFC_TIMER_OFF;
 		}
 		switch (new_state.bits.v_su_sta) {
 			case ST_TE_DEACTIVATED:		/* F3 */
-				DBG("%s/%s: State ST_TE_DEACTIVATED (F3)\n", xbus->busname, xpd->xpdname);
+				XPD_DBG(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	*/
-				DBG("%s/%s: State ST_TE_SIGWAIT (F4)\n", xbus->busname, xpd->xpdname);
+				XPD_DBG(xpd, "State ST_TE_SIGWAIT (F4)\n");
 				break;
 			case ST_TE_IDENT:		/* F5	*/
-				DBG("%s/%s: State ST_TE_IDENT (F5)\n", xbus->busname, xpd->xpdname);
+				XPD_DBG(xpd, "State ST_TE_IDENT (F5)\n");
 				break;
 			case ST_TE_SYNCED:		/* F6	*/
-				DBG("%s/%s: State ST_TE_SYNCED (F6)\n", xbus->busname, xpd->xpdname);
+				XPD_DBG(xpd, "State ST_TE_SYNCED (F6)\n");
 				break;
 			case ST_TE_ACTIVATED:		/* F7 */
-				DBG("%s/%s: State ST_TE_ACTIVATED (F7)\n", xbus->busname, xpd->xpdname);
+				XPD_DBG(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);
@@ -1300,42 +1284,41 @@
 				break;
 
 			case ST_TE_LOST_FRAMING:	/* F8 */
-				DBG("%s/%s: State ST_TE_LOST_FRAMING (F8)\n", xbus->busname, xpd->xpdname);
+				XPD_DBG(xpd, "State ST_TE_LOST_FRAMING (F8)\n");
 				priv->t4 = HFC_TIMER_OFF;
 				break;
 			default:
-				NOTICE("%s/%s: Bad TE state: %d\n", xbus->busname, xpd->xpdname, new_state.bits.v_su_sta);
+				XPD_NOTICE(xpd, "Bad TE state: %d\n", new_state.bits.v_su_sta);
 				break;
 		}
 
 	} else if(IS_NT(xpd)) {
 		switch (new_state.bits.v_su_sta) {
 			case ST_NT_DEACTIVATED:		/* G1 */
-				DBG("%s/%s: State ST_NT_DEACTIVATED (G1)\n", xbus->busname, xpd->xpdname);
+				XPD_DBG(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 */
-				DBG("%s/%s: State ST_NT_ACTIVATING (G2)\n", xbus->busname, xpd->xpdname);
+				XPD_DBG(xpd, "State ST_NT_ACTIVATING (G2)\n");
 				xpd_activation(xpd, 1);
 				break;
 			case ST_NT_ACTIVATED:		/* G3 */
-				DBG("%s/%s: State ST_NT_ACTIVATED (G3)\n", xbus->busname, xpd->xpdname);
+				XPD_DBG(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 */
-				DBG("%s/%s: State ST_NT_DEACTIVTING (G4)\n", xbus->busname, xpd->xpdname);
+				XPD_DBG(xpd, "State ST_NT_DEACTIVTING (G4)\n");
 				priv->t1 = HFC_TIMER_OFF;
 				break;
 			default:
-				NOTICE("%s/%s: Bad NT state: %d\n", xbus->busname, xpd->xpdname, new_state.bits.v_su_sta);
+				XPD_NOTICE(xpd, "Bad NT state: %d\n", new_state.bits.v_su_sta);
 				break;
 		}
 	} else
-		ERR("%s: %s/%s: Unknown xpd type %d\n", __FUNCTION__,
-				xpd->xbus->busname, xpd->xpdname, xpd->type);
+		XPD_ERR(xpd, "%s: Unknown xpd type %d\n", __FUNCTION__, xpd->type);
 	priv->state_register.reg = new_state.reg;
 }
 
@@ -1347,9 +1330,9 @@
 	int			ret;
 
 	if(!xpd) {
-		NOTICE("%s: received %s for non-existing %s(%1d%1d)\n",
+		XBUS_NOTICE(xbus, "%s: received %s for non-existing unit (%1d%1d)\n",
 				__FUNCTION__, cmd->name,
-				xbus->busname, pack->addr.unit, pack->addr.subunit);
+				pack->addr.unit, pack->addr.subunit);
 		return -EPROTO;
 	}
 	spin_lock_irqsave(&xpd->lock, flags);
@@ -1357,25 +1340,24 @@
 	BUG_ON(!priv);
 #if 0
 	if(REG_FIELD(info, do_subreg)) {
-		DBG("REGISTER_REPLY: %s/%s: RS %02X %02X %02X\n",
-				xbus->busname, xpd->xpdname, REG_FIELD(info, regnum), REG_FIELD(info, subreg), REG_FIELD(info, data_low));
+		XPD_DBG(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)
-			DBG("REGISTER_REPLY: %s/%s: RD %02X %02X\n",
-					xbus->busname, xpd->xpdname, REG_FIELD(info, regnum), REG_FIELD(info, data_low));
+			XPD_DBG(xpd, "REGISTER_REPLY: RD %02X %02X\n",
+					REG_FIELD(info, regnum), REG_FIELD(info, data_low));
 	}
 #endif
 	if(info->multibyte) {
 #if 0
-		DBG("%s/%s: Got Multibyte: %d bytes, eoframe: %d\n",
-				xbus->busname, xpd->xpdname,
+		XPD_DBG(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++;
 			if(atomic_read(&xpd->open_counter) > 0)
-				NOTICE("%s/%s: Multibyte Drop: errno=%d\n", xbus->busname, xpd->xpdname, ret);
+				XPD_NOTICE(xpd, "Multibyte Drop: errno=%d\n", ret);
 		} 
 		goto end;
 	}
@@ -1644,7 +1626,7 @@
 	BUG_ON(!xpd);
 	xbus = xpd->xbus;
 	if(!down_read_trylock(&xbus->in_use)) {
-		DBG("Dropped packet. %s is in_use\n", xbus->busname);
+		XBUS_DBG(xbus, "Dropped packet. Is in_use\n");
 		return -EBUSY;
 	}
 	priv = xpd->priv;
@@ -1740,7 +1722,7 @@
 {
 	DBG("\n");
 
-	INFO("%s revision %s\n", THIS_MODULE->name, XPP_VERSION);
+	INFO("revision %s\n", XPP_VERSION);
 	xproto_register(&PROTO_TABLE(BRI_NT));
 	xproto_register(&PROTO_TABLE(BRI_TE));
 	return 0;

Modified: branches/1.2/xpp/card_fxo.c
URL: http://svn.digium.com/view/zaptel/branches/1.2/xpp/card_fxo.c?view=diff&rev=2811&r1=2810&r2=2811
==============================================================================
--- branches/1.2/xpp/card_fxo.c (original)
+++ branches/1.2/xpp/card_fxo.c Wed Aug  1 16:33:56 2007
@@ -156,7 +156,7 @@
 			BIT_CLR(priv->ledstate[which], chan);
 		}
 	}
-	DBG("%s/%s/%d: LED: which=%d -- %s\n", xbus->busname, xpd->xpdname, chan, which, (on) ? "on" : "off");
+	LINE_DBG(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,8 +184,7 @@
 				mod_value = DEFAULT_LED_PERIOD;		/* safety value */
 			// led state is toggled
 			if((timer_count % mod_value) == 0) {
-				DBG("%s/%s/%d: ledstate=%s\n", xpd->xbus->busname, xpd->xpdname, i,
-						(IS_SET(priv->ledstate[color], i))?"ON":"OFF");
+				LINE_DBG(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 {
@@ -213,7 +212,7 @@
 		BIT_SET(xpd->cid_on, pos);
 		rxsig = ZT_RXSIG_OFFHOOK;
 	}
-	pcm_recompute(xpd);
+	pcm_recompute(xpd, xpd->offhook | xpd->cid_on);
 	/*
 	 * We should not spinlock before calling zt_hooksig() as
 	 * it may call back into our xpp_hooksig() and cause
@@ -231,13 +230,13 @@
 	BUG_ON(!priv);
 	atomic_set(&priv->ring_debounce[pos], 0);	/* Stop debouncing */
 	if(on && !xpd->ringing[pos]) {
-		DBG("%s/%s/%d: START\n", xpd->xbus->busname, xpd->xpdname, pos);
+		LINE_DBG(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]) {
-		DBG("%s/%s/%d: STOP\n", xpd->xbus->busname, xpd->xpdname, pos);
+		LINE_DBG(xpd, pos, "STOP\n");
 		xpd->ringing[pos] = 0;
 		if(IS_BLINKING(priv, pos, LED_GREEN))
 			MARK_BLINK(priv, pos, LED_GREEN, 0);
@@ -260,12 +259,12 @@
 	priv = xpd->priv;
 	BUG_ON(!priv);
 	if(!IS_SET(priv->battery, pos)) {
-		DBG("%s/%s/%d: WARNING: called while battery is off\n", xbus->busname, xpd->xpdname, pos);
+		LINE_DBG(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 */
-	DBG("%s/%s/%d: SETHOOK: value=0x%02X %s\n", xbus->busname, xpd->xpdname, pos, value, (to_offhook)?"OFFHOOK":"ONHOOK");
+	LINE_DBG(xpd, pos, "SETHOOK: value=0x%02X %s\n", value, (to_offhook)?"OFFHOOK":"ONHOOK");
 	if(to_offhook)
 		MARK_ON(priv, pos, LED_GREEN);
 	else
@@ -289,11 +288,15 @@
 
 /*---------------- FXO: Methods -------------------------------------------*/
 
-static xpd_t *FXO_card_new(xbus_t *xbus, int unit, int subunit, const xproto_table_t *proto_table, byte revision)
+static xpd_t *FXO_card_new(xbus_t *xbus, int unit, int subunit, const xproto_table_t *proto_table, byte subtype, byte revision)
 {
 	xpd_t		*xpd = NULL;
-	int		channels = min(8, CHANNELS_PERXPD);
-
+	int		channels;
+
+	if(subtype == 2)
+		channels = min(2, CHANNELS_PERXPD);
+	else
+		channels = min(8, CHANNELS_PERXPD);
 	xpd = xpd_alloc(sizeof(struct FXO_priv_data), proto_table, channels);
 	if(!xpd)
 		return NULL;
@@ -309,23 +312,23 @@
 
 	BUG_ON(!xpd);
 	priv = xpd->priv;
-	DBG("%s/%s\n", xbus->busname, xpd->xpdname);
+	XPD_DBG(xpd, "\n");
 #ifdef	CONFIG_PROC_FS
 	if(priv->regfile) {
-		DBG("Removing xpd DAA file %s/%s\n", xbus->busname, xpd->xpdname);
+		XPD_DBG(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) {
-		DBG("Removing xpd metering tone file %s/%s\n", xbus->busname, xpd->xpdname);
+		XPD_DBG(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) {
-		DBG("Removing xpd FXO_INFO file %s/%s\n", xbus->busname, xpd->xpdname);
+		XPD_DBG(xpd, "Removing xpd FXO_INFO file\n");
 		remove_proc_entry(PROC_FXO_INFO_FNAME, xpd->proc_xpd_dir);
 		priv->fxo_info = NULL;
 	}
@@ -341,29 +344,29 @@
 	BUG_ON(!xpd);
 	priv = xpd->priv;
 #ifdef	CONFIG_PROC_FS
-	DBG("Creating FXO_INFO file for %s/%s\n", xbus->busname, xpd->xpdname);
+	XPD_DBG(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) {
-		ERR("Failed to create proc '%s' for %s/%s\n", PROC_FXO_INFO_FNAME, xbus->busname, xpd->xpdname);
+		XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_FXO_INFO_FNAME);
 		ret = -ENOENT;
 		goto err;
 	}
 	priv->fxo_info->owner = THIS_MODULE;
 #ifdef	WITH_METERING
-	DBG("Creating Metering tone file for %s/%s\n", xbus->busname, xpd->xpdname);
+	XPD_DBG(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) {
-		ERR("%s/%s: Failed to create proc file for metering tone\n", xbus->busname, xpd->xpdname);
+		XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_METERING_FNAME);
 		ret = -ENOENT;
 		goto err;
 	}
 	priv->meteringfile->owner = THIS_MODULE;
 #endif
-	DBG("Creating DAAs file for %s/%s\n", xbus->busname, xpd->xpdname);
+	XPD_DBG(xpd, "Creating DAAs file\n");
 	priv->regfile = create_proc_entry(PROC_REGISTER_FNAME, 0644, xpd->proc_xpd_dir);
 	if(!priv->regfile) {
-		ERR("Failed to create proc file for DAAs of %s/%s\n", xbus->busname, xpd->xpdname);
+		XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_REGISTER_FNAME);
 		ret = -ENOENT;
 		goto err;
 	}
@@ -379,7 +382,7 @@
 	for_each_line(xpd, i) {
 		do_sethook(xpd, i, 0);
 	}
-	DBG("done: %s/%s\n", xbus->busname, xpd->xpdname);
+	XPD_DBG(xpd, "done\n");
 	for_each_line(xpd, i) {
 		do_led(xpd, i, LED_GREEN, 0);
 	}
@@ -391,11 +394,11 @@
 		do_led(xpd, i, LED_GREEN, 0);
 		msleep(50);
 	}
-	pcm_recompute(xpd);
+	pcm_recompute(xpd, xpd->offhook | xpd->cid_on);
 	return 0;
 err:
 	clean_proc(xbus, xpd);
-	ERR("%s/%s: Failed initializing registers (%d)\n", xbus->busname, xpd->xpdname, ret);
+	XPD_ERR(xpd, "Failed initializing registers (%d)\n", ret);
 	return ret;
 }
 
@@ -405,7 +408,7 @@
 
 	BUG_ON(!xpd);
 	priv = xpd->priv;
-	DBG("%s/%s\n", xbus->busname, xpd->xpdname);
+	XPD_DBG(xpd, "\n");
 	clean_proc(xbus, xpd);
 	return 0;
 }
@@ -421,11 +424,11 @@
 	BUG_ON(!xbus);
 	priv = xpd->priv;
 	BUG_ON(!priv);
-	DBG("%s/%s (%d)\n", xbus->busname, xpd->xpdname, on);
+	XPD_DBG(xpd, "%s\n", (on)?"ON":"OFF");
 	for_each_line(xpd, i) {
 		struct zt_chan	*cur_chan = &xpd->chans[i];
 
-		DBG("setting FXO channel %d\n", i);
+		XPD_DBG(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;
@@ -450,7 +453,7 @@
 	BUG_ON(!xbus);
 	priv = xpd->priv;
 	BUG_ON(!priv);
-	DBG("%s/%s (%d)\n", xbus->busname, xpd->xpdname, on);
+	XPD_DBG(xpd, "%s\n", (on)?"ON":"OFF");
 	for_each_line(xpd, i) {
 		MARK_OFF(priv, i, LED_GREEN);
 		msleep(2);
@@ -466,7 +469,7 @@
 
 	priv = xpd->priv;
 	BUG_ON(!priv);
-	DBG("%s/%s/%d: %s\n", xbus->busname, xpd->xpdname, pos, txsig2str(txsig));
+	LINE_DBG(xpd, pos, "%s\n", txsig2str(txsig));
 	BUG_ON(xpd->direction != TO_PSTN);
 	/* XXX Enable hooksig for FXO XXX */
 	switch(txsig) {
@@ -479,10 +482,11 @@
 			do_sethook(xpd, pos, 0);
 			break;
 		default:
-			NOTICE("Can't set tx state to %s (%d)\n", txsig2str(txsig), txsig);
+			XPD_NOTICE(xpd, "Can't set tx state to %s (%d)\n",
+				txsig2str(txsig), txsig);
 			return -EINVAL;
 	}
-	pcm_recompute(xpd);
+	pcm_recompute(xpd, xpd->offhook | xpd->cid_on);
 	return 0;
 }
 
@@ -591,26 +595,26 @@
 	BUG_ON(!xpd);
 	switch (cmd) {
 		case WCTDM_SET_ECHOTUNE:
-			DBG("-- Setting echo registers: \n");
+			XPD_DBG(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++) {
-				DBG("Reg=0x%02X, data=0x%02X\n", echotune_regs[i], echotune_data[i]);
+				XPD_DBG(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) {
-					NOTICE("%s/%s/%d: Couldn't write %0x02X to register %0x02X\n",
-							xpd->xbus->busname, xpd->xpdname, pos, echotune_data[i], echotune_regs[i]);
+					LINE_NOTICE(xpd, pos, "Couldn't write %0x02X to register %0x02X\n",
+							echotune_data[i], echotune_regs[i]);
 					return ret;
 				}
 				msleep(1);
 			}
 
-			DBG("-- Set echo registers successfully\n");
+			XPD_DBG(xpd, "-- Set echo registers successfully\n");
 			break;
 		default:
-			DBG("%s/%s/%d: Unknown command 0x%X.\n", xpd->xbus->busname, xpd->xpdname, pos, cmd);
+			LINE_DBG(xpd, pos, "Unknown command 0x%X.\n", cmd);
 			return -ENOTTY;
 	}
 	return 0;
@@ -631,8 +635,7 @@
 	}
 	XFRAME_NEW(xframe, pack, xbus, GLOBAL, REGISTER_REQUEST, xpd->xbus_idx);
 #if 0
-	DBG("%s/%s/%d: %c%c R%02X S%02X %02X %02X\n",
-			xbus->busname, xpd->xpdname, chipsel,
+	LINE_DBG(xpd, chisel, "%c%c R%02X S%02X %02X %02X\n",
 			(writing)?'W':'R',
 			(do_subreg)?'S':'D',
 			regnum, subreg, data_low, data_high);
@@ -659,7 +662,7 @@
 	BUG_ON(!xpd);
 	priv = xpd->priv;
 	BUG_ON(!priv);
-	DBG("%s/%s: %s\n", xbus->busname, xpd->xpdname, (on) ? "on" : "off");
+	XPD_DBG(xpd, "%s\n", (on) ? "on" : "off");
 	return ret;
 }
 
@@ -667,7 +670,7 @@
 {
 	BUG_ON(!xbus);
 	BUG_ON(!xpd);
-	DBG("%s/%s/%d: %s\n", xbus->busname, xpd->xpdname, chan, (on) ? "on" : "off");
+	LINE_DBG(xpd, chan, "%s\n", (on) ? "on" : "off");
 	return DAA_DIRECT_REQUEST(xbus, xpd, chan, DAA_WRITE, 0x40, (on)?0x04:0x01);
 }
 
@@ -692,22 +695,21 @@
 	}
 	priv = xpd->priv;
 	BUG_ON(!priv);
-	DBG("%s/%s: (PSTN) sig_toggles=0x%04X sig_status=0x%04X\n", xpd->xbus->busname, xpd->xpdname, sig_toggles, sig_status);
+	XPD_DBG(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)) {
-				DBG("%s/%s/%d: SIG_CHANGED while battery is off.\n",
-					xbus->busname, xpd->xpdname, i);
+				LINE_DBG(xpd, i, "SIG_CHANGED while battery is off.\n");
 				// FIXME: allow dialing without battery polling...
 				// continue;
 			}
 			/* First report false ring alarms */
 			debounce = atomic_read(&priv->ring_debounce[i]);
 			if(debounce)
-				NOTICE("%s/%s/%d: debounced %d ticks\n", xbus->busname, xpd->xpdname, i, debounce);
+				LINE_NOTICE(xpd, i, "debounced %d ticks\n", debounce);
 			/*
 			 * Now set a new ring alarm.
 			 * It will be checked in handle_fxo_ring()
@@ -733,7 +735,7 @@
 		 * Check for battery voltage fluctuations
 		 */
 		if(IS_SET(priv->battery, chipsel) && priv->battery_debounce[chipsel]++ > BAT_DEBOUNCE) {
-			DBG("%s/%s/%d: BATTERY OFF voltage=%d\n", xpd->xbus->busname, xpd->xpdname, chipsel, bat);
+			LINE_DBG(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);
@@ -742,7 +744,7 @@
 	} else {
 		priv->battery_debounce[chipsel] = 0;
 		if(!IS_SET(priv->battery, chipsel)) {
-			DBG("%s/%s/%d: BATTERY ON voltage=%d\n", xpd->xbus->busname, xpd->xpdname, chipsel, bat);
+			LINE_DBG(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);
@@ -768,7 +770,7 @@
 					BIT_CLR(priv->polarity, chipsel);
 				priv->polarity_counter[chipsel] = 0;
 				/* Inform Zaptel */
-				DBG("%s/%s/%d: Send ZT_EVENT_POLARITY\n", xpd->xbus->busname, xpd->xpdname, chipsel);
+				LINE_DBG(xpd, chipsel, "Send ZT_EVENT_POLARITY\n");
 				zt_qevent_lock(&xpd->chans[chipsel], ZT_EVENT_POLARITY);
 #if 0
 				/*
@@ -780,7 +782,7 @@
 				 */
 				do_sethook(xpd, chipsel, 0);
 				update_line_status(xpd, chipsel, 0);
-				pcm_recompute(xpd);
+				pcm_recompute(xpd, xpd->offhook | xpd->cid_on);
 #endif
 			}
 		}
@@ -797,11 +799,11 @@
 		/* Current dropped */
 		priv->current_counter[chipsel]++;
 		if (priv->current_counter[chipsel] * poll_battery_interval >= POWER_DENIAL_TIME) {
-			DBG("%s/%s/%d: Power Denial Hangup\n", xpd->xbus->busname, xpd->xpdname, chipsel);
+			LINE_DBG(xpd, chipsel, "Power Denial Hangup\n");
 			priv->current_counter[chipsel] = 0;
 			do_sethook(xpd, chipsel, 0);
 			update_line_status(xpd, chipsel, 0);
-			pcm_recompute(xpd);
+			pcm_recompute(xpd, xpd->offhook | xpd->cid_on);
 		}
 	} else
 		priv->current_counter[chipsel] = 0;
@@ -819,8 +821,7 @@
 	priv = xpd->priv;
 	BUG_ON(!priv);
 	old_metering_tone = IS_SET(priv->metering_tone_state, chipsel);
-	DBG("%s/%s/%d: METERING: %s [dL=0x%X] (%d)\n",
-		xpd->xbus->busname, xpd->xpdname, chipsel,
+	LINE_DBG(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,8 +865,8 @@
 #endif
 	}
 #if 0
-	DBG("DAA_REPLY: xpd #%d %s reg_num=0x%X, dataL=0x%X dataH=0x%X\n",
-			xpd->xbus_idx, (info->size == 3)?"I":"D",
+	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
 
@@ -1073,7 +1074,7 @@
 	BUG_ON(!xpd);
 	xbus = xpd->xbus;
 	if(!down_read_trylock(&xbus->in_use)) {
-		DBG("Dropped packet. %s is in_use\n", xbus->busname);
+		XBUS_DBG(xbus, "Dropped packet. Is in_use\n");
 		return -EBUSY;
 	}
 	xpd->requested_reply = regcmd;
@@ -1185,15 +1186,14 @@
 int __init card_fxo_startup(void)
 {
 	if(ring_debounce <= 0) {
-		ERR("%s: ring_debounce=%d. Must be positive number of ticks\n",
-				THIS_MODULE->name, ring_debounce);
+		ERR("ring_debounce=%d. Must be positive number of ticks\n", ring_debounce);
 		return -EINVAL;
 	}
-	INFO("%s revision %s\n", THIS_MODULE->name, XPP_VERSION);
-#ifdef	WITH_METERING
-	INFO("FEATURE: %s WITH METERING Detection\n", THIS_MODULE->name);
+	INFO("revision %s\n", XPP_VERSION);
+#ifdef	WITH_METERING
+	INFO("FEATURE: WITH METERING Detection\n");
 #else
-	INFO("FEATURE: %s NO METERING Detection\n", THIS_MODULE->name);
+	INFO("FEATURE: NO METERING Detection\n");
 #endif
 	xproto_register(&PROTO_TABLE(FXO));
 	return 0;

Modified: branches/1.2/xpp/card_fxs.c
URL: http://svn.digium.com/view/zaptel/branches/1.2/xpp/card_fxs.c?view=diff&rev=2811&r1=2810&r2=2811
==============================================================================
--- branches/1.2/xpp/card_fxs.c (original)
+++ branches/1.2/xpp/card_fxs.c Wed Aug  1 16:33:56 2007
@@ -52,12 +52,8 @@
 #define	FXS_DEFAULT_SIGCAP	(ZT_SIG_SF | ZT_SIG_EM)
 #endif
 
-#define	LINES_REGULAR	8

[... 6604 lines stripped ...]



More information about the zaptel-commits mailing list