[svn-commits] tzafrir: linux/trunk r8909 - /linux/trunk/drivers/dahdi/xpp/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jul 13 13:35:24 CDT 2010


Author: tzafrir
Date: Tue Jul 13 13:35:20 2010
New Revision: 8909

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=8909
Log:
PRI Astribanks always sync AB (and independent)

* PRI devices always get SYNC-AB (never PLL, not even for NT)
* Fix Timing priority calculation accordingly.
* On PRI layer1 changes, elect_syncer() is called, so we have
  re-election.

Modified:
    linux/trunk/drivers/dahdi/xpp/card_bri.c
    linux/trunk/drivers/dahdi/xpp/card_fxo.c
    linux/trunk/drivers/dahdi/xpp/card_fxs.c
    linux/trunk/drivers/dahdi/xpp/card_pri.c
    linux/trunk/drivers/dahdi/xpp/xbus-core.c
    linux/trunk/drivers/dahdi/xpp/xbus-core.h
    linux/trunk/drivers/dahdi/xpp/xbus-pcm.c
    linux/trunk/drivers/dahdi/xpp/xbus-pcm.h
    linux/trunk/drivers/dahdi/xpp/xpp_dahdi.c
    linux/trunk/drivers/dahdi/xpp/xproto.h

Modified: linux/trunk/drivers/dahdi/xpp/card_bri.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/xpp/card_bri.c?view=diff&rev=8909&r1=8908&r2=8909
==============================================================================
--- linux/trunk/drivers/dahdi/xpp/card_bri.c (original)
+++ linux/trunk/drivers/dahdi/xpp/card_bri.c Tue Jul 13 13:35:20 2010
@@ -1671,6 +1671,7 @@
 		.card_pcm_recompute	= BRI_card_pcm_recompute,
 		.card_pcm_fromspan	= BRI_card_pcm_fromspan,
 		.card_pcm_tospan	= BRI_card_pcm_tospan,
+		.card_timing_priority	= generic_timing_priority,
 		.card_ioctl	= BRI_card_ioctl,
 		.card_open	= BRI_card_open,
 		.card_close	= BRI_card_close,

Modified: linux/trunk/drivers/dahdi/xpp/card_fxo.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/xpp/card_fxo.c?view=diff&rev=8909&r1=8908&r2=8909
==============================================================================
--- linux/trunk/drivers/dahdi/xpp/card_fxo.c (original)
+++ linux/trunk/drivers/dahdi/xpp/card_fxo.c Tue Jul 13 13:35:20 2010
@@ -1133,6 +1133,7 @@
 		.card_pcm_recompute	= generic_card_pcm_recompute,
 		.card_pcm_fromspan	= generic_card_pcm_fromspan,
 		.card_pcm_tospan	= generic_card_pcm_tospan,
+		.card_timing_priority	= generic_timing_priority,
 		.card_ioctl	= FXO_card_ioctl,
 		.card_open	= FXO_card_open,
 		.card_register_reply	= FXO_card_register_reply,

Modified: linux/trunk/drivers/dahdi/xpp/card_fxs.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/xpp/card_fxs.c?view=diff&rev=8909&r1=8908&r2=8909
==============================================================================
--- linux/trunk/drivers/dahdi/xpp/card_fxs.c (original)
+++ linux/trunk/drivers/dahdi/xpp/card_fxs.c Tue Jul 13 13:35:20 2010
@@ -1409,6 +1409,7 @@
 		.card_pcm_recompute	= generic_card_pcm_recompute,
 		.card_pcm_fromspan	= generic_card_pcm_fromspan,
 		.card_pcm_tospan	= generic_card_pcm_tospan,
+		.card_timing_priority	= generic_timing_priority,
 		.card_open	= FXS_card_open,
 		.card_close	= FXS_card_close,
 		.card_ioctl	= FXS_card_ioctl,

Modified: linux/trunk/drivers/dahdi/xpp/card_pri.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/xpp/card_pri.c?view=diff&rev=8909&r1=8908&r2=8909
==============================================================================
--- linux/trunk/drivers/dahdi/xpp/card_pri.c (original)
+++ linux/trunk/drivers/dahdi/xpp/card_pri.c Tue Jul 13 13:35:20 2010
@@ -1193,6 +1193,7 @@
 		return NULL;
 	}
 #endif
+	xbus->sync_mode_default = SYNC_MODE_AB;
 	return xpd;
 }
 
@@ -1825,6 +1826,18 @@
 	}
 	XPD_COUNTER(xpd, PCM_READ)++;
 	spin_unlock_irqrestore(&xpd->lock, flags);
+}
+
+int PRI_timing_priority(xbus_t *xbus, xpd_t *xpd)
+{
+	struct PRI_priv_data	*priv;
+
+	priv = xpd->priv;
+	BUG_ON(!priv);
+	if (priv->layer1_up)
+		return xpd->timing_priority;
+	XPD_DBG(SYNC, xpd, "No timing priority (no layer1)\n");
+	return -ENOENT;
 }
 
 /*---------------- PRI: HOST COMMANDS -------------------------------------*/
@@ -1917,6 +1930,7 @@
 				send_idlebits(xpd, 1);
 		}
 		xpd->span.alarms = alarms;
+		elect_syncer("LAYER1");
 		dahdi_alarm_notify(&xpd->span);
 		set_clocking(xpd);
 	}
@@ -2140,6 +2154,7 @@
 		.card_pcm_recompute	= PRI_card_pcm_recompute,
 		.card_pcm_fromspan	= PRI_card_pcm_fromspan,
 		.card_pcm_tospan	= PRI_card_pcm_tospan,
+		.card_timing_priority	= PRI_timing_priority,
 		.card_ioctl	= PRI_card_ioctl,
 		.card_close	= PRI_card_close,
 		.card_register_reply	= PRI_card_register_reply,

Modified: linux/trunk/drivers/dahdi/xpp/xbus-core.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/xpp/xbus-core.c?view=diff&rev=8909&r1=8908&r2=8909
==============================================================================
--- linux/trunk/drivers/dahdi/xpp/xbus-core.c (original)
+++ linux/trunk/drivers/dahdi/xpp/xbus-core.c Tue Jul 13 13:35:20 2010
@@ -1475,6 +1475,7 @@
 	worker_init(xbus);
 	atomic_set(&xbus->num_xpds, 0);
 	xbus->sync_mode = SYNC_MODE_NONE;
+	xbus->sync_mode_default = SYNC_MODE_PLL;
 	err = xbus_sysfs_create(xbus);
 	if(err) {
 		XBUS_ERR(xbus, "SYSFS creation failed: %d\n", err);

Modified: linux/trunk/drivers/dahdi/xpp/xbus-core.h
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/xpp/xbus-core.h?view=diff&rev=8909&r1=8908&r2=8909
==============================================================================
--- linux/trunk/drivers/dahdi/xpp/xbus-core.h (original)
+++ linux/trunk/drivers/dahdi/xpp/xbus-core.h Tue Jul 13 13:35:20 2010
@@ -194,6 +194,8 @@
 
 	bool			self_ticking;
 	enum sync_mode		sync_mode;
+	/* Managed by low-level drivers: */
+	enum sync_mode		sync_mode_default;
 	struct timer_list	command_timer;
 	unsigned int		xbus_frag_count;
 	struct xframe_queue	pcm_tospan;

Modified: linux/trunk/drivers/dahdi/xpp/xbus-pcm.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/xpp/xbus-pcm.c?view=diff&rev=8909&r1=8908&r2=8909
==============================================================================
--- linux/trunk/drivers/dahdi/xpp/xbus-pcm.c (original)
+++ linux/trunk/drivers/dahdi/xpp/xbus-pcm.c Tue Jul 13 13:35:20 2010
@@ -56,6 +56,7 @@
  */
 static struct xpp_ticker	*ref_ticker = NULL;
 static spinlock_t		ref_ticker_lock = SPIN_LOCK_UNLOCKED;
+static spinlock_t		elect_syncer_lock = SPIN_LOCK_UNLOCKED;
 static bool			force_dahdi_sync = 0;	/* from /sys/bus/astribanks/drivers/xppdrv/sync */
 static xbus_t			*global_ticker;
 static struct xpp_ticker	global_ticks_series;
@@ -305,17 +306,17 @@
 	return sync_mode_names[mode];
 }
 
+/*
+ * Caller must aquire/release the 'ref_ticker_lock' spinlock
+ */
 static void xpp_set_syncer(xbus_t *xbus, bool on)
 {
-	unsigned long	flags;
-
-	spin_lock_irqsave(&ref_ticker_lock, flags);
 	if(!xbus) {	/* Special case, no more syncers */
 		DBG(SYNC, "No more syncers\n");
 		syncer = NULL;
 		if(ref_ticker != &dahdi_ticker)
 			ref_ticker = NULL;
-		goto out;
+		return;
 	}
 	if(syncer != xbus && on) {
 		XBUS_DBG(SYNC, xbus, "New syncer\n");
@@ -329,8 +330,6 @@
 		XBUS_DBG(SYNC, xbus, "ignore %s (current syncer: %s)\n",
 			(on)?"ON":"OFF",
 			(syncer) ? syncer->busname : "NO-SYNC");
-out:
-	spin_unlock_irqrestore(&ref_ticker_lock, flags);
 }
 
 static void xbus_command_timer(unsigned long param)
@@ -369,11 +368,14 @@
 void got_new_syncer(xbus_t *xbus, enum sync_mode mode, int drift)
 {
 	unsigned long	flags;
+	unsigned long	flags2;
 
 	spin_lock_irqsave(&xbus->lock, flags);
+	spin_lock_irqsave(&ref_ticker_lock, flags2);
 	xbus->sync_adjustment = (signed char)drift;
 	if(xbus->sync_mode == mode) {
-		/* XBUS_DBG(SYNC, xbus, "Already in mode '%s'. Ignored\n", sync_mode_name(mode)); */
+		XBUS_DBG(SYNC, xbus, "Already in mode '%s'. Ignored\n",
+				sync_mode_name(mode));
 		goto out;
 	}
 	XBUS_DBG(SYNC, xbus, "Mode %s (%d), drift=%d (pcm_rx_counter=%d)\n",
@@ -402,15 +404,32 @@
 		XBUS_ERR(xbus, "%s: unknown mode=0x%X\n", __FUNCTION__, mode);
 	}
 out:
+	spin_unlock_irqrestore(&ref_ticker_lock, flags2);
 	spin_unlock_irqrestore(&xbus->lock, flags);
 }
 
 void xbus_request_sync(xbus_t *xbus, enum sync_mode mode)
 {
+	unsigned long	flags;
+
 	BUG_ON(!xbus);
 	XBUS_DBG(SYNC, xbus, "sent request (mode=%d)\n", mode);
 	CALL_PROTO(GLOBAL, SYNC_SOURCE, xbus, NULL, mode, 0);
 	if(mode == SYNC_MODE_NONE) {
+		/*
+		 * We must deselect the syncer *now* and not wait for the
+		 * reply from the AB. Otherwise, a disconnect of the syncing
+		 * AB would result in a corrupted 'syncer'.
+		 */
+		spin_lock_irqsave(&ref_ticker_lock, flags);
+		xpp_set_syncer(xbus, 0);
+		spin_unlock_irqrestore(&ref_ticker_lock, flags);
+		/*
+		 * We must activate timer now since the commands go to
+		 * the command queue, and we should maintain something to
+		 * "tick" meanwhile until the AB get these commands and
+		 * start being "self_ticking".
+		 */
 		xbus_set_command_timer(xbus, 1);
 	}
 }
@@ -559,6 +578,7 @@
 		force_dahdi_sync = 0;
 		ref_ticker = &new_syncer->ticker;
 		xbus_drift_clear(new_syncer);	/* Clean new data */
+		xpp_set_syncer(new_syncer, 1);
 		xbus_request_sync(new_syncer, SYNC_MODE_AB);
 	} else if(force_dahdi_sync) {
 		ref_ticker = &dahdi_ticker;
@@ -574,7 +594,8 @@
 			continue;
 		if(XBUS_FLAGS(xbus, CONNECTED) && xbus != new_syncer) {
 			if(xbus->self_ticking)
-				xbus_request_sync(xbus, SYNC_MODE_PLL);
+				xbus_request_sync(xbus,
+						xbus->sync_mode_default);
 			else
 				XBUS_DBG(SYNC, xbus, "Not self_ticking yet. Ignore\n");
 		}
@@ -588,7 +609,9 @@
 	uint	timing_priority = INT_MAX;
 	xpd_t	*best_xpd = NULL;
 	xbus_t	*the_xbus = NULL;
-
+	unsigned long	flags;
+
+	spin_lock_irqsave(&elect_syncer_lock, flags);
 	for(i = 0; i < MAX_BUSES; i++) {
 		xbus_t	*xbus = xbus_num(i);
 		if(!xbus)
@@ -598,11 +621,19 @@
 				the_xbus = xbus;	/* First candidate */
 			for(j = 0; j < MAX_XPDS; j++) {
 				xpd_t	*xpd = xpd_of(xbus, j);
+				int	prio;
 
 				if(!xpd || !xpd->card_present)
 					continue;
-				if(xpd->timing_priority > 0 && xpd->timing_priority < timing_priority) {
-					timing_priority = xpd->timing_priority;
+				prio = CALL_XMETHOD(card_timing_priority,
+						xbus, xpd);
+				if (prio < 0) {
+					DBG(SYNC, "%s/%s: skip sync\n",
+						xbus->busname, xpd->xpdname);
+					continue;
+				}
+				if (prio > 0 && prio < timing_priority) {
+					timing_priority = prio;
 					best_xpd = xpd;
 				}
 			}
@@ -614,12 +645,17 @@
 	} else if(the_xbus) {
 		XBUS_DBG(SYNC, the_xbus, "%s: elected\n", msg);
 	} else {
+		unsigned long	flags;
+
 		DBG(SYNC, "%s: No more syncers\n", msg);
+		spin_lock_irqsave(&ref_ticker_lock, flags);
 		xpp_set_syncer(NULL, 0);
+		spin_unlock_irqrestore(&ref_ticker_lock, flags);
 		the_xbus = NULL;
 	}
 	if(the_xbus != syncer)
 		update_sync_master(the_xbus, force_dahdi_sync);
+	spin_unlock_irqrestore(&elect_syncer_lock, flags);
 }
 
 /*
@@ -960,6 +996,11 @@
 out:
 	FREE_RECV_XFRAME(xbus, xframe);
 	return ret;
+}
+
+int generic_timing_priority(xbus_t *xbus, xpd_t *xpd)
+{
+	return xpd->timing_priority;
 }
 
 static void xbus_tick(xbus_t *xbus)
@@ -1290,6 +1331,7 @@
 EXPORT_SYMBOL(generic_card_pcm_recompute);
 EXPORT_SYMBOL(generic_card_pcm_tospan);
 EXPORT_SYMBOL(generic_card_pcm_fromspan);
+EXPORT_SYMBOL(generic_timing_priority);
 #ifdef	DEBUG_PCMTX
 EXPORT_SYMBOL(pcmtx);
 EXPORT_SYMBOL(pcmtx_chan);

Modified: linux/trunk/drivers/dahdi/xpp/xbus-pcm.h
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/xpp/xbus-pcm.h?view=diff&rev=8909&r1=8908&r2=8909
==============================================================================
--- linux/trunk/drivers/dahdi/xpp/xbus-pcm.h (original)
+++ linux/trunk/drivers/dahdi/xpp/xbus-pcm.h Tue Jul 13 13:35:20 2010
@@ -108,6 +108,7 @@
 void		generic_card_pcm_recompute(xbus_t *xbus, xpd_t *xpd, xpp_line_t pcm_mask);
 void		generic_card_pcm_fromspan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack);
 void		generic_card_pcm_tospan(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack);
+int		generic_timing_priority(xbus_t *xbus, xpd_t *xpd);
 void		fill_beep(u_char *buf, int num, int duration);
 const char	*sync_mode_name(enum sync_mode mode);
 void		xbus_set_command_timer(xbus_t *xbus, bool on);

Modified: linux/trunk/drivers/dahdi/xpp/xpp_dahdi.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/xpp/xpp_dahdi.c?view=diff&rev=8909&r1=8908&r2=8909
==============================================================================
--- linux/trunk/drivers/dahdi/xpp/xpp_dahdi.c (original)
+++ linux/trunk/drivers/dahdi/xpp/xpp_dahdi.c Tue Jul 13 13:35:20 2010
@@ -130,7 +130,7 @@
 	xpd_t	*xpd;
 
 	xpd = kref_to_xpd(kref);
-	XPD_NOTICE(xpd, "%s\n", __func__);
+	XPD_DBG(DEVICES, xpd, "%s\n", __func__);
 	xpd_device_unregister(xpd);
 }
 

Modified: linux/trunk/drivers/dahdi/xpp/xproto.h
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/xpp/xproto.h?view=diff&rev=8909&r1=8908&r2=8909
==============================================================================
--- linux/trunk/drivers/dahdi/xpp/xproto.h (original)
+++ linux/trunk/drivers/dahdi/xpp/xproto.h Tue Jul 13 13:35:20 2010
@@ -226,6 +226,7 @@
 	void (*card_pcm_recompute)(xbus_t *xbus, xpd_t *xpd, xpp_line_t pcm_mask);
 	void (*card_pcm_fromspan)(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack);
 	void (*card_pcm_tospan)(xbus_t *xbus, xpd_t *xpd, xpacket_t *pack);
+	int (*card_timing_priority)(xbus_t *xbus, xpd_t *xpd);
 	int (*card_dahdi_preregistration)(xpd_t *xpd, bool on);
 	int (*card_dahdi_postregistration)(xpd_t *xpd, bool on);
 	int (*card_hooksig)(xbus_t *xbus, xpd_t *xpd, int pos, enum dahdi_txsig txsig);




More information about the svn-commits mailing list