[dahdi-commits] dahdi/linux.git branch "for-5.0-v1" created.

SVN commits to the DAHDI project dahdi-commits at lists.digium.com
Sun Mar 31 12:51:29 CDT 2019


branch "for-5.0-v1" has been created
        at  4defd05eb6849753260830f9e2829f9af553fe61 (commit)

- Log -----------------------------------------------------------------
commit 4defd05eb6849753260830f9e2829f9af553fe61
Author: Shaun Ruffell <sruffell at sruffell.net>
Date:   Thu Mar 28 22:43:53 2019 -0500

    dahdi: Store the span registration time as a ktime_t value as well.
    
    Ideally we want to standardize on storing all timestamps derivied from the
    system clock as ktime_t values.

diff --git a/drivers/dahdi/dahdi-base.c b/drivers/dahdi/dahdi-base.c
index 90166d5..bcd6147 100644
--- a/drivers/dahdi/dahdi-base.c
+++ b/drivers/dahdi/dahdi-base.c
@@ -7438,7 +7438,7 @@ static int _dahdi_register_device(struct dahdi_device *ddev,
 		__dahdi_init_span(s);
 	}
 
-	ktime_get_ts(&ddev->registration_time);
+	ddev->registration_time = ktime_get();
 	ret = dahdi_sysfs_add_device(ddev, parent);
 	if (ret)
 		return ret;
diff --git a/drivers/dahdi/dahdi-sysfs.c b/drivers/dahdi/dahdi-sysfs.c
index d1f2379..ca29ddb 100644
--- a/drivers/dahdi/dahdi-sysfs.c
+++ b/drivers/dahdi/dahdi-sysfs.c
@@ -654,10 +654,11 @@ dahdi_registration_time_show(struct device *dev,
 {
 	struct dahdi_device *ddev = to_ddev(dev);
 	int count = 0;
+	struct timespec64 ts = ktime_to_timespec64(ddev->registration_time);
 
-	count += sprintf(buf, "%010ld.%09ld\n",
-		ddev->registration_time.tv_sec,
-		ddev->registration_time.tv_nsec);
+	count += sprintf(buf, "%010lld.%09ld\n",
+		(s64)ts.tv_sec,
+		ts.tv_nsec);
 	return count;
 }
 
diff --git a/include/dahdi/kernel.h b/include/dahdi/kernel.h
index 55cafd9..af995a2 100644
--- a/include/dahdi/kernel.h
+++ b/include/dahdi/kernel.h
@@ -907,7 +907,7 @@ struct dahdi_device {
 	const char *devicetype;
 	struct device dev;
 	unsigned int irqmisses;
-	struct timespec registration_time;
+	ktime_t registration_time;
 };
 
 struct dahdi_span {

commit 5342c5609b13f553a3e0364e68dc4c2a1edcc2f2
Author: Shaun Ruffell <sruffell at sruffell.net>
Date:   Wed Mar 27 17:17:45 2019 +0000

    xpp: Convert `struct timeval` -> ktime_t.
    
    `struct timeval` has been removed from the kernel interface in 5.0 as part of
    fixing the 2038 problem. ktime_t is the preferred kernel time interface now.

diff --git a/drivers/dahdi/xpp/card_fxs.c b/drivers/dahdi/xpp/card_fxs.c
index ab5f5a8..073e2ee 100644
--- a/drivers/dahdi/xpp/card_fxs.c
+++ b/drivers/dahdi/xpp/card_fxs.c
@@ -188,7 +188,7 @@ struct FXS_priv_data {
 	xpp_line_t neon_blinking;
 	xpp_line_t neonstate;
 	xpp_line_t vbat_h;		/* High voltage */
-	struct timeval prev_key_time[CHANNELS_PERXPD];
+	ktime_t prev_key_time[CHANNELS_PERXPD];
 	int led_counter[NUM_LEDS][CHANNELS_PERXPD];
 	int overheat_reset_counter[CHANNELS_PERXPD];
 	int ohttimer[CHANNELS_PERXPD];
@@ -1681,8 +1681,7 @@ static void process_hookstate(xpd_t *xpd, xpp_line_t offhook,
 			 * Reset our previous DTMF memories...
 			 */
 			BIT_CLR(priv->prev_key_down, i);
-			priv->prev_key_time[i].tv_sec =
-			    priv->prev_key_time[i].tv_usec = 0L;
+			priv->prev_key_time[i] = ktime_set(0L, 0UL);
 			if (IS_SET(offhook, i)) {
 				LINE_DBG(SIGNAL, xpd, i, "OFFHOOK\n");
 				MARK_ON(priv, i, LED_GREEN);
@@ -1795,8 +1794,9 @@ static void process_dtmf(xpd_t *xpd, uint portnum, __u8 val)
 	bool want_mute;
 	bool want_event;
 	struct FXS_priv_data *priv;
-	struct timeval now;
-	int msec = 0;
+	ktime_t now;
+	s64 msec = 0;
+	struct timespec64 ts;
 
 	if (!dtmf_detection)
 		return;
@@ -1813,16 +1813,17 @@ static void process_dtmf(xpd_t *xpd, uint portnum, __u8 val)
 		BIT_SET(priv->prev_key_down, portnum);
 	else
 		BIT_CLR(priv->prev_key_down, portnum);
-	do_gettimeofday(&now);
-	if (priv->prev_key_time[portnum].tv_sec != 0)
-		msec = usec_diff(&now, &priv->prev_key_time[portnum]) / 1000;
+	now = ktime_get();
+	if (!dahdi_ktime_equal(priv->prev_key_time[portnum], ktime_set(0, 0)))
+		msec = ktime_ms_delta(now, priv->prev_key_time[portnum]);
 	priv->prev_key_time[portnum] = now;
+	ts = ktime_to_timespec64(now);
 	LINE_DBG(SIGNAL, xpd, portnum,
-		"[%lu.%06lu] DTMF digit %-4s '%c' "
-		"(val=%d, want_mute=%s want_event=%s, delta=%d msec)\n",
-		now.tv_sec, now.tv_usec, (key_down) ? "DOWN" : "UP", digit,
-		val, (want_mute) ? "yes" : "no", (want_event) ? "yes" : "no",
-		msec);
+		"[%lld.%06ld] DTMF digit %-4s '%c' "
+		"(val=%d, want_mute=%s want_event=%s, delta=%lld msec)\n",
+		(s64)ts.tv_sec, ts.tv_nsec * NSEC_PER_USEC,
+		(key_down) ? "DOWN" : "UP", digit, val,
+		(want_mute) ? "yes" : "no", (want_event) ? "yes" : "no", msec);
 	/*
 	 * FIXME: we currently don't use the want_dtmf_mute until
 	 * we are sure about the logic in Asterisk native bridging.
diff --git a/drivers/dahdi/xpp/xbus-core.c b/drivers/dahdi/xpp/xbus-core.c
index 9a6c3b3..46debfe 100644
--- a/drivers/dahdi/xpp/xbus-core.c
+++ b/drivers/dahdi/xpp/xbus-core.c
@@ -259,7 +259,7 @@ void xframe_init(xbus_t *xbus, xframe_t *xframe, void *buf, size_t maxsize,
 	xframe->packets = xframe->first_free = buf;
 	xframe->frame_maxlen = maxsize;
 	atomic_set(&xframe->frame_len, 0);
-	do_gettimeofday(&xframe->tv_created);
+	xframe->kt_created = ktime_get();
 	xframe->xframe_magic = XFRAME_MAGIC;
 }
 EXPORT_SYMBOL(xframe_init);
@@ -946,12 +946,12 @@ static int xbus_initialize(xbus_t *xbus)
 	int unit;
 	int subunit;
 	xpd_t *xpd;
-	struct timeval time_start;
-	struct timeval time_end;
+	ktime_t time_start;
+	ktime_t time_end;
 	unsigned long timediff;
 	int res = 0;
 
-	do_gettimeofday(&time_start);
+	time_start = ktime_get();
 	XBUS_DBG(DEVICES, xbus, "refcount_xbus=%d\n", refcount_xbus(xbus));
 	if (xbus_aquire_xpds(xbus) < 0)	/* Until end of initialization */
 		return -EBUSY;
@@ -989,7 +989,7 @@ static int xbus_initialize(xbus_t *xbus)
 		}
 	}
 	xbus_echocancel(xbus, 1);
-	do_gettimeofday(&time_end);
+	time_end = ktime_get();
 	timediff = usec_diff(&time_end, &time_start);
 	timediff /= 1000 * 100;
 	XBUS_INFO(xbus, "Initialized in %ld.%1ld sec\n", timediff / 10,
@@ -1756,7 +1756,7 @@ static void xbus_fill_proc_queue(struct seq_file *sfile, struct xframe_queue *q)
 {
 	seq_printf(sfile,
 		"%-15s: counts %3d, %3d, %3d worst %3d, overflows %3d "
-		"worst_lag %02ld.%ld ms\n",
+		"worst_lag %02lld.%lld ms\n",
 		q->name, q->steady_state_count, q->count, q->max_count,
 		q->worst_count, q->overflows, q->worst_lag_usec / 1000,
 		q->worst_lag_usec % 1000);
@@ -1792,8 +1792,9 @@ static int xbus_proc_show(struct seq_file *sfile, void *data)
 		    seq_printf(sfile, "%5d ", xbus->cpu_rcv_tasklet[i]);
 		seq_printf(sfile, "\n");
 	}
-	seq_printf(sfile, "self_ticking: %d (last_tick at %ld)\n",
-		    xbus->self_ticking, xbus->ticker.last_sample.tv.tv_sec);
+	seq_printf(sfile, "self_ticking: %d (last_tick at %lld)\n",
+		    xbus->self_ticking, ktime_divns(xbus->ticker.last_sample,
+						    NSEC_PER_SEC));
 	seq_printf(sfile, "command_tick: %d\n",
 		    xbus->command_tick_counter);
 	seq_printf(sfile, "usec_nosend: %d\n", xbus->usec_nosend);
diff --git a/drivers/dahdi/xpp/xbus-core.h b/drivers/dahdi/xpp/xbus-core.h
index 26c0ba7..b522bed 100644
--- a/drivers/dahdi/xpp/xbus-core.h
+++ b/drivers/dahdi/xpp/xbus-core.h
@@ -234,8 +234,8 @@ struct xbus {
 	spinlock_t lock;
 
 	/* PCM metrics */
-	struct timeval last_tx_sync;
-	struct timeval last_rx_sync;
+	ktime_t last_tx_sync;
+	ktime_t last_rx_sync;
 	unsigned long max_tx_sync;
 	unsigned long min_tx_sync;
 	unsigned long max_rx_sync;
@@ -255,7 +255,7 @@ struct xbus {
 	 */
 	int sync_adjustment;
 	int sync_adjustment_offset;
-	long pll_updated_at;
+	ktime_t pll_updated_at;
 
 	atomic_t num_xpds;
 
@@ -279,10 +279,10 @@ struct xframe {
 	struct list_head frame_list;
 	atomic_t frame_len;
 	xbus_t *xbus;
-	struct timeval tv_created;
-	struct timeval tv_queued;
-	struct timeval tv_submitted;
-	struct timeval tv_received;
+	ktime_t kt_created;
+	ktime_t kt_queued;
+	ktime_t kt_submitted;
+	ktime_t kt_received;
 	/* filled by transport layer */
 	size_t frame_maxlen;
 	__u8 *packets;		/* max XFRAME_DATASIZE */
@@ -358,4 +358,9 @@ void xbus_sysfs_remove(xbus_t *xbus);
 
 void astribank_uevent_send(xbus_t *xbus, enum kobject_action act);
 
+static inline s64 xpp_ktime_sec_delta(ktime_t later, ktime_t earlier)
+{
+	return ktime_divns(ktime_sub(later, earlier), NSEC_PER_SEC);
+}
+
 #endif /* XBUS_CORE_H */
diff --git a/drivers/dahdi/xpp/xbus-pcm.c b/drivers/dahdi/xpp/xbus-pcm.c
index 37f9260..f73aadc 100644
--- a/drivers/dahdi/xpp/xbus-pcm.c
+++ b/drivers/dahdi/xpp/xbus-pcm.c
@@ -111,24 +111,23 @@ static void xpp_ticker_init(struct xpp_ticker *ticker)
 {
 	memset(ticker, 0, sizeof(*ticker));
 	spin_lock_init(&ticker->lock);
-	do_gettimeofday(&ticker->last_sample.tv);
+	ticker->last_sample = ktime_get();
 	ticker->first_sample = ticker->last_sample;
 	ticker_set_cycle(ticker, SYNC_ADJ_QUICK);
 }
 
-static int xpp_ticker_step(struct xpp_ticker *ticker, const struct timeval *t)
+static int xpp_ticker_step(struct xpp_ticker *ticker, const ktime_t t)
 {
 	unsigned long flags;
-	long usec;
+	s64 usec;
 	bool cycled = 0;
 
 	spin_lock_irqsave(&ticker->lock, flags);
-	ticker->last_sample.tv = *t;
+	ticker->last_sample = t;
 	/* rate adjust */
 	if ((ticker->count % ticker->cycle) == ticker->cycle - 1) {
-		usec =
-		    (long)usec_diff(&ticker->last_sample.tv,
-				    &ticker->first_sample.tv);
+		usec = ktime_us_delta(ticker->last_sample,
+					ticker->first_sample);
 		ticker->first_sample = ticker->last_sample;
 		ticker->tick_period = usec / ticker->cycle;
 		cycled = 1;
@@ -147,7 +146,7 @@ static inline void xbus_drift_clear(xbus_t *xbus)
 {
 	struct xpp_drift *di = &xbus->drift;
 
-	do_gettimeofday(&di->last_lost_tick.tv);
+	di->last_lost_tick = ktime_get();
 	ticker_set_cycle(&xbus->ticker, SYNC_ADJ_QUICK);
 	di->max_speed = -SYNC_ADJ_MAX;
 	di->min_speed = SYNC_ADJ_MAX;
@@ -190,14 +189,14 @@ static void sample_tick(xbus_t *xbus, int sample)
  * including abrupt changes in sync -- to verify the stability of the
  * algorithm.
  */
-static void xpp_drift_step(xbus_t *xbus, const struct timeval *tv)
+static void xpp_drift_step(xbus_t *xbus, const ktime_t kt)
 {
 	struct xpp_drift *di = &xbus->drift;
 	struct xpp_ticker *ticker = &xbus->ticker;
 	unsigned long flags;
 
 	spin_lock_irqsave(&di->lock, flags);
-	xpp_ticker_step(&xbus->ticker, tv);
+	xpp_ticker_step(&xbus->ticker, kt);
 	/*
 	 * Do we need to be synchronized and is there an established reference
 	 * ticker (another Astribank or another DAHDI device) already?
@@ -206,7 +205,7 @@ static void xpp_drift_step(xbus_t *xbus, const struct timeval *tv)
 	    && xbus->sync_mode == SYNC_MODE_PLL) {
 		int new_delta_tick = ticker->count - ref_ticker->count;
 		int lost_ticks = new_delta_tick - di->delta_tick;
-		long usec_delta;
+		s64 usec_delta;
 
 		di->delta_tick = new_delta_tick;
 		if (lost_ticks) {
@@ -233,9 +232,8 @@ static void xpp_drift_step(xbus_t *xbus, const struct timeval *tv)
 			}
 		} else {
 			/* Sample a delta */
-			usec_delta =
-			    (long)usec_diff(&ticker->last_sample.tv,
-					    &ref_ticker->last_sample.tv);
+			usec_delta = ktime_us_delta(ticker->last_sample,
+						    ref_ticker->last_sample);
 			sample_tick(xbus, usec_delta);
 			if ((ticker->count % SYNC_CYCLE) >
 			    (SYNC_CYCLE - SYNC_CYCLE_SAMPLE))
@@ -283,7 +281,7 @@ static void xpp_drift_step(xbus_t *xbus, const struct timeval *tv)
 
 				XBUS_DBG(SYNC, xbus,
 					"offset: %d, min_speed=%d, "
-					"max_speed=%d, usec_delta(last)=%ld\n",
+					"max_speed=%d, usec_delta(last)=%lld\n",
 					offset_prev, di->min_speed,
 					di->max_speed, usec_delta);
 				XBUS_DBG(SYNC, xbus,
@@ -356,10 +354,8 @@ static void xpp_set_syncer(xbus_t *xbus, bool on)
 static void xbus_command_timer(TIMER_DATA_TYPE timer)
 {
 	xbus_t *xbus = from_timer(xbus, timer, command_timer);
-	struct timeval now;
 
 	BUG_ON(!xbus);
-	do_gettimeofday(&now);
 	xbus_command_queue_tick(xbus);
 	if (!xbus->self_ticking) /* Must be 1KHz rate */
 		mod_timer(&xbus->command_timer, jiffies + 1);
@@ -489,34 +485,34 @@ static void reset_sync_counters(void)
 
 static void send_drift(xbus_t *xbus, int drift)
 {
-	struct timeval now;
+	const ktime_t now = ktime_get();
 	const char *msg;
+	s64 msec_delta;
 
 	BUG_ON(abs(drift) > SYNC_ADJ_MAX);
-	do_gettimeofday(&now);
 	if (drift > xbus->sync_adjustment)
 		msg = "up";
 	else
 		msg = "down";
+	msec_delta = ktime_ms_delta(now, xbus->pll_updated_at);
 	XBUS_DBG(SYNC, xbus,
-		 "%sDRIFT adjust %s (%d) (last update %ld seconds ago)\n",
+		 "%sDRIFT adjust %s (%d) (last update %lld seconds ago)\n",
 		 (disable_pll_sync) ? "Fake " : "", msg, drift,
-		 now.tv_sec - xbus->pll_updated_at);
+		 msec_delta / MSEC_PER_SEC);
 	if (!disable_pll_sync)
 		CALL_PROTO(GLOBAL, SYNC_SOURCE, xbus, NULL, SYNC_MODE_PLL,
 			   drift);
-	xbus->pll_updated_at = now.tv_sec;
+	xbus->pll_updated_at = now;
 }
 
 static void global_tick(void)
 {
-	struct timeval now;
+	ktime_t now = ktime_get();
 
-	do_gettimeofday(&now);
 	atomic_inc(&xpp_tick_counter);
 	if ((atomic_read(&xpp_tick_counter) % BIG_TICK_INTERVAL) == 0)
 		reset_sync_counters();
-	xpp_ticker_step(&global_ticks_series, &now);
+	xpp_ticker_step(&global_ticks_series, now);
 }
 
 #ifdef	DAHDI_SYNC_TICK
@@ -525,11 +521,11 @@ void dahdi_sync_tick(struct dahdi_span *span, int is_master)
 	struct phonedev *phonedev = container_of(span, struct phonedev, span);
 	xpd_t *xpd = container_of(phonedev, struct xpd, phonedev);
 	static int redundant_ticks;	/* for extra spans */
-	struct timeval now;
+	ktime_t now;
 
 	if (!force_dahdi_sync)
 		goto noop;
-	do_gettimeofday(&now);
+	now = ktime_get();
 	BUG_ON(!xpd);
 	/*
 	 * Detect if any of our spans is dahdi sync master
@@ -562,7 +558,7 @@ void dahdi_sync_tick(struct dahdi_span *span, int is_master)
 #endif
 		goto noop;
 	}
-	xpp_ticker_step(&dahdi_ticker, &now);
+	xpp_ticker_step(&dahdi_ticker, now);
 	dahdi_tick_count++;
 	//flip_parport_bit(1);
 noop:
@@ -854,15 +850,14 @@ static bool pcm_valid(xpd_t *xpd, xpacket_t *pack)
 static inline void pcm_frame_out(xbus_t *xbus, xframe_t *xframe)
 {
 	unsigned long flags;
-	struct timeval now;
-	unsigned long usec;
+	const ktime_t now = ktime_get();
+	s64 usec;
 
 	spin_lock_irqsave(&xbus->lock, flags);
-	do_gettimeofday(&now);
 	if (unlikely(disable_pcm || !XBUS_IS(xbus, READY)))
 		goto dropit;
 	if (XPACKET_ADDR_SYNC((xpacket_t *)xframe->packets)) {
-		usec = usec_diff(&now, &xbus->last_tx_sync);
+		usec = ktime_us_delta(now, xbus->last_tx_sync);
 		xbus->last_tx_sync = now;
 		/* ignore startup statistics */
 		if (likely
@@ -873,7 +868,7 @@ static inline void pcm_frame_out(xbus_t *xbus, xframe_t *xframe)
 				if ((rate_limit++ % 5003) == 0)
 					XBUS_DBG(SYNC, xbus,
 						"Bad PCM TX timing(%d): "
-						"usec=%ld.\n",
+						"usec=%lld.\n",
 						rate_limit, usec);
 			}
 			if (usec > xbus->max_tx_sync)
@@ -1187,11 +1182,10 @@ static void xbus_tick(xbus_t *xbus)
 	while ((xframe = xframe_dequeue(&xbus->pcm_tospan)) != NULL) {
 		copy_pcm_tospan(xbus, xframe);
 		if (XPACKET_ADDR_SYNC((xpacket_t *)xframe->packets)) {
-			struct timeval now;
-			unsigned long usec;
+			ktime_t now = ktime_get();
+			s64 usec;
 
-			do_gettimeofday(&now);
-			usec = usec_diff(&now, &xbus->last_rx_sync);
+			usec = ktime_us_delta(now, xbus->last_rx_sync);
 			xbus->last_rx_sync = now;
 			/* ignore startup statistics */
 			if (likely
@@ -1204,7 +1198,7 @@ static void xbus_tick(xbus_t *xbus)
 						XBUS_DBG(SYNC, xbus,
 							"Bad PCM RX "
 							"timing(%d): "
-							"usec=%ld.\n",
+							"usec=%lld.\n",
 							rate_limit, usec);
 				}
 				if (usec > xbus->max_rx_sync)
@@ -1235,7 +1229,7 @@ static void xbus_tick(xbus_t *xbus)
 	}
 }
 
-static void do_tick(xbus_t *xbus, const struct timeval *tv_received)
+static void do_tick(xbus_t *xbus, const ktime_t kt_received)
 {
 	int counter = atomic_read(&xpp_tick_counter);
 	unsigned long flags;
@@ -1244,7 +1238,7 @@ static void do_tick(xbus_t *xbus, const struct timeval *tv_received)
 	if (global_ticker == xbus)
 		global_tick();	/* called from here or dahdi_sync_tick() */
 	spin_lock_irqsave(&ref_ticker_lock, flags);
-	xpp_drift_step(xbus, tv_received);
+	xpp_drift_step(xbus, kt_received);
 	spin_unlock_irqrestore(&ref_ticker_lock, flags);
 	if (likely(xbus->self_ticking))
 		xbus_tick(xbus);
@@ -1268,7 +1262,7 @@ void xframe_receive_pcm(xbus_t *xbus, xframe_t *xframe)
 	 * FIXME: what about PRI split?
 	 */
 	if (XPACKET_ADDR_SYNC((xpacket_t *)xframe->packets)) {
-		do_tick(xbus, &xframe->tv_received);
+		do_tick(xbus, xframe->kt_received);
 		atomic_inc(&xbus->pcm_rx_counter);
 	} else
 		xbus->xbus_frag_count++;
diff --git a/drivers/dahdi/xpp/xbus-pcm.h b/drivers/dahdi/xpp/xbus-pcm.h
index e64ff06..1f9398b 100644
--- a/drivers/dahdi/xpp/xbus-pcm.h
+++ b/drivers/dahdi/xpp/xbus-pcm.h
@@ -40,16 +40,6 @@ enum sync_mode {
 };
 
 /*
- * Abstract representation of timestamp.
- * It would (eventually) replace the hard-coded
- * timeval structs so we can migrate to better
- * time representations.
- */
-struct xpp_timestamp {
-	struct timeval tv;
-};
-
-/*
  * A ticker encapsulates the timing information of some
  * abstract tick source. The following tickers are used:
  *   - Each xbus has an embedded ticker.
@@ -60,8 +50,8 @@ struct xpp_timestamp {
 struct xpp_ticker {		/* for rate calculation */
 	int count;
 	int cycle;
-	struct xpp_timestamp first_sample;
-	struct xpp_timestamp last_sample;
+	ktime_t first_sample;
+	ktime_t last_sample;
 	int tick_period;	/* usec/tick */
 	spinlock_t lock;
 };
@@ -75,7 +65,7 @@ struct xpp_drift {
 	int lost_ticks;		/* occurances */
 	int lost_tick_count;
 	int sync_inaccuracy;
-	struct xpp_timestamp last_lost_tick;
+	ktime_t last_lost_tick;
 	long delta_sum;
 	int offset_prev;
 	int offset_range;
@@ -88,15 +78,10 @@ struct xpp_drift {
 
 void xpp_drift_init(xbus_t *xbus);
 
-static inline long usec_diff(const struct timeval *tv1,
-			     const struct timeval *tv2)
+static inline long usec_diff(const ktime_t *tv1,
+			     const ktime_t *tv2)
 {
-	long diff_sec;
-	long diff_usec;
-
-	diff_sec = tv1->tv_sec - tv2->tv_sec;
-	diff_usec = tv1->tv_usec - tv2->tv_usec;
-	return diff_sec * 1000000 + diff_usec;
+	return ktime_us_delta(*tv1, *tv2);
 }
 
 int xbus_pcm_init(void *top);
diff --git a/drivers/dahdi/xpp/xbus-sysfs.c b/drivers/dahdi/xpp/xbus-sysfs.c
index 8c4859e..d8c11dc 100644
--- a/drivers/dahdi/xpp/xbus-sysfs.c
+++ b/drivers/dahdi/xpp/xbus-sysfs.c
@@ -31,6 +31,7 @@
 #include <linux/device.h>
 #include <linux/delay.h>	/* for msleep() to debug */
 #include <linux/sched.h>
+#include <dahdi/kernel.h>
 #include "xpd.h"
 #include "xpp_dahdi.h"
 #include "xbus-core.h"
@@ -117,24 +118,28 @@ static DEVICE_ATTR_READER(timing_show, dev, buf)
 	xbus_t *xbus;
 	struct xpp_drift *driftinfo;
 	int len = 0;
-	struct timeval now;
+	ktime_t now;
 
-	do_gettimeofday(&now);
+	now = ktime_get();
 	xbus = dev_to_xbus(dev);
 	driftinfo = &xbus->drift;
 	len +=
 	    snprintf(buf + len, PAGE_SIZE - len, "%-3s",
 		     sync_mode_name(xbus->sync_mode));
 	if (xbus->sync_mode == SYNC_MODE_PLL) {
+		bool pll_updated = !dahdi_ktime_equal(xbus->pll_updated_at,
+						      ktime_set(0, 0));
+		s64 update_delta =
+			(!pll_updated) ? 0 :
+				xpp_ktime_sec_delta(now, xbus->pll_updated_at);
 		len +=
 		    snprintf(buf + len, PAGE_SIZE - len,
 			     " %5d: lost (%4d,%4d) : ", xbus->ticker.cycle,
 			     driftinfo->lost_ticks, driftinfo->lost_tick_count);
 		len +=
 		    snprintf(buf + len, PAGE_SIZE - len,
-			     "DRIFT %3d %ld sec ago", xbus->sync_adjustment,
-			     (xbus->pll_updated_at ==
-			      0) ? 0 : now.tv_sec - xbus->pll_updated_at);
+			     "DRIFT %3d %lld sec ago", xbus->sync_adjustment,
+			     update_delta);
 	}
 	len += snprintf(buf + len, PAGE_SIZE - len, "\n");
 	return len;
@@ -229,7 +234,7 @@ static DEVICE_ATTR_READER(driftinfo_show, dev, buf)
 	xbus_t *xbus;
 	struct xpp_drift *di;
 	struct xpp_ticker *ticker;
-	struct timeval now;
+	ktime_t now = ktime_get();
 	int len = 0;
 	int hours;
 	int minutes;
@@ -244,8 +249,7 @@ static DEVICE_ATTR_READER(driftinfo_show, dev, buf)
 	/*
 	 * Calculate lost ticks time
 	 */
-	do_gettimeofday(&now);
-	seconds = now.tv_sec - di->last_lost_tick.tv.tv_sec;
+	seconds = ktime_ms_delta(now, di->last_lost_tick) / 1000;
 	minutes = seconds / 60;
 	seconds = seconds % 60;
 	hours = minutes / 60;
diff --git a/drivers/dahdi/xpp/xframe_queue.c b/drivers/dahdi/xpp/xframe_queue.c
index 5ef5a9d..e370381 100644
--- a/drivers/dahdi/xpp/xframe_queue.c
+++ b/drivers/dahdi/xpp/xframe_queue.c
@@ -34,15 +34,15 @@ static void __xframe_dump_queue(struct xframe_queue *q)
 	xframe_t *xframe;
 	int i = 0;
 	char prefix[30];
-	struct timeval now;
+	ktime_t now = ktime_get();
 
-	do_gettimeofday(&now);
 	printk(KERN_DEBUG "%s: dump queue '%s' (first packet in each frame)\n",
 	       THIS_MODULE->name, q->name);
 	list_for_each_entry_reverse(xframe, &q->head, frame_list) {
 		xpacket_t *pack = (xpacket_t *)&xframe->packets[0];
-		long usec = usec_diff(&now, &xframe->tv_queued);
-		snprintf(prefix, ARRAY_SIZE(prefix), "  %3d> %5ld.%03ld msec",
+		s64 usec = ktime_us_delta(now, xframe->kt_queued);
+
+		snprintf(prefix, ARRAY_SIZE(prefix), "  %3d> %5lld.%03lld msec",
 			 i++, usec / 1000, usec % 1000);
 		dump_packet(prefix, pack, 1);
 	}
@@ -62,7 +62,7 @@ static bool __xframe_enqueue(struct xframe_queue *q, xframe_t *xframe)
 		if ((overflow_cnt++ % 1000) < 5) {
 			NOTICE("Overflow of %-15s: counts %3d, %3d, %3d "
 				"worst %3d, overflows %3d "
-				"worst_lag %02ld.%ld ms\n",
+				"worst_lag %02lld.%lld ms\n",
 			     q->name, q->steady_state_count, q->count,
 			     q->max_count, q->worst_count, q->overflows,
 			     q->worst_lag_usec / 1000,
@@ -75,7 +75,7 @@ static bool __xframe_enqueue(struct xframe_queue *q, xframe_t *xframe)
 	if (++q->count > q->worst_count)
 		q->worst_count = q->count;
 	list_add_tail(&xframe->frame_list, &q->head);
-	do_gettimeofday(&xframe->tv_queued);
+	xframe->kt_queued = ktime_get();
 out:
 	return ret;
 }
@@ -96,8 +96,8 @@ static xframe_t *__xframe_dequeue(struct xframe_queue *q)
 {
 	xframe_t *frm = NULL;
 	struct list_head *h;
-	struct timeval now;
-	unsigned long usec_lag;
+	ktime_t now;
+	s64 usec_lag;
 
 	if (list_empty(&q->head))
 		goto out;
@@ -105,12 +105,8 @@ static xframe_t *__xframe_dequeue(struct xframe_queue *q)
 	list_del_init(h);
 	--q->count;
 	frm = list_entry(h, xframe_t, frame_list);
-	do_gettimeofday(&now);
-	usec_lag =
-	    (now.tv_sec - frm->tv_queued.tv_sec) * 1000 * 1000 + (now.tv_usec -
-								  frm->
-								  tv_queued.
-								  tv_usec);
+	now = ktime_get();
+	usec_lag = ktime_us_delta(now, frm->kt_queued);
 	if (q->worst_lag_usec < usec_lag)
 		q->worst_lag_usec = usec_lag;
 out:
@@ -284,7 +280,7 @@ xframe_t *get_xframe(struct xframe_queue *q)
 	BUG_ON(xframe->xframe_magic != XFRAME_MAGIC);
 	atomic_set(&xframe->frame_len, 0);
 	xframe->first_free = xframe->packets;
-	do_gettimeofday(&xframe->tv_created);
+	xframe->kt_created = ktime_get();
 	/*
 	 * If later parts bother to correctly initialize their
 	 * headers, there is no need to memset() the whole data.
diff --git a/drivers/dahdi/xpp/xframe_queue.h b/drivers/dahdi/xpp/xframe_queue.h
index a62fa20..7b87c70 100644
--- a/drivers/dahdi/xpp/xframe_queue.h
+++ b/drivers/dahdi/xpp/xframe_queue.h
@@ -19,7 +19,7 @@ struct xframe_queue {
 	/* statistics */
 	unsigned int worst_count;
 	unsigned int overflows;
-	unsigned long worst_lag_usec;	/* since xframe creation */
+	s64 worst_lag_usec;	/* since xframe creation */
 };
 
 void xframe_queue_init(struct xframe_queue *q, unsigned int steady_state_count,
diff --git a/drivers/dahdi/xpp/xpp_usb.c b/drivers/dahdi/xpp/xpp_usb.c
index a599e6f..1a591b1 100644
--- a/drivers/dahdi/xpp/xpp_usb.c
+++ b/drivers/dahdi/xpp/xpp_usb.c
@@ -200,7 +200,7 @@ struct xusb {
 	int counters[XUSB_COUNTER_MAX];
 
 	/* metrics */
-	struct timeval last_tx;
+	ktime_t last_tx;
 	unsigned int max_tx_delay;
 	uint usb_tx_delay[NUM_BUCKETS];
 	uint sluggish_debounce;
@@ -365,7 +365,7 @@ static int do_send_xframe(xbus_t *xbus, xframe_t *xframe)
 	BUG_ON(!urb);
 	/* update urb length */
 	urb->transfer_buffer_length = XFRAME_LEN(xframe);
-	do_gettimeofday(&xframe->tv_submitted);
+	xframe->kt_submitted = ktime_get();
 	ret = usb_submit_urb(urb, GFP_ATOMIC);
 	if (ret < 0) {
 		static int rate_limit;
@@ -863,8 +863,8 @@ static void xpp_send_callback(struct urb *urb)
 	xframe_t *xframe = &uframe->xframe;
 	xusb_t *xusb = uframe->xusb;
 	xbus_t *xbus = xbus_num(xusb->xbus_num);
-	struct timeval now;
-	long usec;
+	ktime_t now;
+	s64 usec;
 	int writes = atomic_read(&xusb->pending_writes);
 	int i;
 
@@ -875,9 +875,9 @@ static void xpp_send_callback(struct urb *urb)
 	}
 	//flip_parport_bit(6);
 	atomic_dec(&xusb->pending_writes);
-	do_gettimeofday(&now);
-	xusb->last_tx = xframe->tv_submitted;
-	usec = usec_diff(&now, &xframe->tv_submitted);
+	now = ktime_get();
+	xusb->last_tx = xframe->kt_submitted;
+	usec = ktime_us_delta(now, xframe->kt_submitted);
 	if (usec < 0)
 		usec = 0; /* System clock jumped */
 	if (usec > xusb->max_tx_delay)
@@ -931,9 +931,8 @@ static void xpp_receive_callback(struct urb *urb)
 	xbus_t *xbus = xbus_num(xusb->xbus_num);
 	size_t size;
 	bool do_resubmit = 1;
-	struct timeval now;
+	ktime_t now = ktime_get();
 
-	do_gettimeofday(&now);
 	atomic_dec(&xusb->pending_reads);
 	if (!xbus) {
 		XUSB_ERR(xusb,
@@ -961,7 +960,7 @@ static void xpp_receive_callback(struct urb *urb)
 		goto err;
 	}
 	atomic_set(&xframe->frame_len, size);
-	xframe->tv_received = now;
+	xframe->kt_received = now;
 
 //      if (debug)
 //              dump_xframe("USB_FRAME_RECEIVE", xbus, xframe, debug);
diff --git a/drivers/dahdi/xpp/xproto.c b/drivers/dahdi/xpp/xproto.c
index cd4b34c..de53b60 100644
--- a/drivers/dahdi/xpp/xproto.c
+++ b/drivers/dahdi/xpp/xproto.c
@@ -283,9 +283,8 @@ out:
 int xframe_receive(xbus_t *xbus, xframe_t *xframe)
 {
 	int ret = 0;
-	struct timeval now;
-	struct timeval tv_received;
-	int usec;
+	ktime_t kt_received;
+	s64 usec;
 
 	if (XFRAME_LEN(xframe) < RPACKET_HEADERSIZE) {
 		static int rate_limit;
@@ -301,7 +300,7 @@ int xframe_receive(xbus_t *xbus, xframe_t *xframe)
 		XBUS_DBG(GENERAL, xbus, "Dropped xframe. Is shutting down.\n");
 		return -ENODEV;
 	}
-	tv_received = xframe->tv_received;
+	kt_received = xframe->kt_received;
 	/*
 	 * We want to check that xframes do not mix PCM and other commands
 	 */
@@ -315,10 +314,7 @@ int xframe_receive(xbus_t *xbus, xframe_t *xframe)
 		ret = xframe_receive_cmd(xbus, xframe);
 	}
 	/* Calculate total processing time */
-	do_gettimeofday(&now);
-	usec =
-	    (now.tv_sec - tv_received.tv_sec) * 1000000 + now.tv_usec -
-	    tv_received.tv_usec;
+	usec = ktime_us_delta(ktime_get(), kt_received);
 	if (usec > xbus->max_rx_process)
 		xbus->max_rx_process = usec;
 	return ret;

commit d48ee498d4b8e7dda601a05264ffd16d4792096d
Author: Shaun Ruffell <sruffell at sruffell.net>
Date:   Thu Mar 28 21:54:24 2019 -0500

    dahdi: define dahdi_ktime_equal()
    
    Older kernels (2.6.32) are unable to do a direct comparison of ktime values,
    while kernels post 4.10 have removed the comparison function. Therefore we need
    to make our own compatibility interface for comparing the ktime values.

diff --git a/include/dahdi/kernel.h b/include/dahdi/kernel.h
index 1fe917c..55cafd9 100644
--- a/include/dahdi/kernel.h
+++ b/include/dahdi/kernel.h
@@ -1414,6 +1414,9 @@ timer_setup(struct timer_list *timer,
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
 #define refcount_read atomic_read
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
+#define dahdi_ktime_equal ktime_equal
+
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
 
 #ifdef RHEL_RELEASE_VERSION
@@ -1476,6 +1479,7 @@ static inline void *PDE_DATA(const struct inode *inode)
 #endif /* 3.10.0 */
 #endif /* 3.16.0 */
 #endif /* 4.0.0 */
+#endif /* 4.10.0 */
 #endif /* 4.11.0 */
 #endif /* 4.13.0 */
 #else /* >= 4.15.0 */
@@ -1486,6 +1490,13 @@ static inline void *PDE_DATA(const struct inode *inode)
 
 #endif /* 4.15.0 */
 
+#ifndef dahdi_ktime_equal
+static inline int dahdi_ktime_equal(const ktime_t cmp1, const ktime_t cmp2)
+{
+	return cmp1 == cmp2;
+}
+#endif
+
 #ifndef DEFINE_SPINLOCK
 #define DEFINE_SPINLOCK(x)      spinlock_t x = SPIN_LOCK_UNLOCKED
 #endif

commit 5ef37e81569350dc8101e3edd4995b285b6db203
Author: Shaun Ruffell <sruffell at sruffell.net>
Date:   Wed Mar 27 12:23:03 2019 -0500

    Revert "WIP: xpp does not currently build"
    
    This reverts commit aa05a446becc45396abf68c95901280410756578.

diff --git a/drivers/dahdi/Kbuild b/drivers/dahdi/Kbuild
index d2183d9..855e5bf 100644
--- a/drivers/dahdi/Kbuild
+++ b/drivers/dahdi/Kbuild
@@ -41,7 +41,7 @@ obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_WCB4XXP)		+= wcb4xxp/
 
 endif
 
-#obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_XPP)		+= xpp/
+obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_XPP)		+= xpp/
 
 obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_ECHOCAN_JPAH)	+= dahdi_echocan_jpah.o
 obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_ECHOCAN_STEVE)	+= dahdi_echocan_sec.o

commit aa05a446becc45396abf68c95901280410756578
Author: Shaun Ruffell <sruffell at sruffell.net>
Date:   Mon Mar 25 09:39:39 2019 -0500

    WIP: xpp does not currently build

diff --git a/drivers/dahdi/Kbuild b/drivers/dahdi/Kbuild
index 855e5bf..d2183d9 100644
--- a/drivers/dahdi/Kbuild
+++ b/drivers/dahdi/Kbuild
@@ -41,7 +41,7 @@ obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_WCB4XXP)		+= wcb4xxp/
 
 endif
 
-obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_XPP)		+= xpp/
+#obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_XPP)		+= xpp/
 
 obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_ECHOCAN_JPAH)	+= dahdi_echocan_jpah.o
 obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_ECHOCAN_STEVE)	+= dahdi_echocan_sec.o

commit f186e925edf4cbfcc60046758d0e1676a75c5f7d
Author: Shaun Ruffell <sruffell at sruffell.net>
Date:   Thu Jan 10 04:07:25 2019 +0000

    dahdi_dummy: 'struct timespec' -> ktime_t
    
    Use the new ktime_t based interface for dahdi_dummy as well. dahdi_dummy
    is still useful to keep around for testing purposes.

diff --git a/drivers/dahdi/dahdi_dummy.c b/drivers/dahdi/dahdi_dummy.c
index 03a2991..b1004d9 100644
--- a/drivers/dahdi/dahdi_dummy.c
+++ b/drivers/dahdi/dahdi_dummy.c
@@ -49,9 +49,8 @@
 #include <linux/moduleparam.h>
 #include <linux/slab.h>
 
-#if defined(USE_HIGHRESTIMER)
 #include <linux/hrtimer.h>
-#else
+#if !defined(USE_HIGHRESTIMER)
 #include <linux/timer.h>
 #endif
 
@@ -80,7 +79,7 @@ struct dahdi_dummy {
 	struct dahdi_chan *chan;
 #if !defined(USE_HIGHRESTIMER)
 	unsigned long calls_since_start;
-	struct timespec start_interval;
+	ktime_t start_interval;
 #endif
 };
 
@@ -138,36 +137,19 @@ static enum hrtimer_restart dahdi_dummy_hr_int(struct hrtimer *htmr)
 	return HRTIMER_RESTART;
 }
 #else
-static unsigned long timespec_diff_ms(struct timespec *t0, struct timespec *t1)
-{
-	long nanosec, sec;
-	unsigned long ms;
-	sec = (t1->tv_sec - t0->tv_sec);
-	nanosec = (t1->tv_nsec - t0->tv_nsec);
-	while (nanosec >= NSEC_PER_SEC) {
-		nanosec -= NSEC_PER_SEC;
-		++sec;
-	}
-	while (nanosec < 0) {
-		nanosec += NSEC_PER_SEC;
-		--sec;
-	}
-	ms = (sec * 1000) + (nanosec / 1000000L);
-	return ms;
-}
 
 static void dahdi_dummy_timer(TIMER_DATA_TYPE unused)
 {
-	unsigned long ms_since_start;
-	struct timespec now;
-	const unsigned long MAX_INTERVAL = 100000L;
-	const unsigned long MS_LIMIT = 3000;
+	long ms_since_start;
+	ktime_t now;
+	const long MAX_INTERVAL = 100000L;
+	const long MS_LIMIT = 3000;
 
 	if (!atomic_read(&shutdown))
 		mod_timer(&timer, jiffies + JIFFIES_INTERVAL);
 
-	now = current_kernel_time();
-	ms_since_start = timespec_diff_ms(&ztd->start_interval, &now);
+	now = ktime_get();
+	ms_since_start = ktime_ms_delta(now, ztd->start_interval);
 
 	/*
 	 * If the system time has changed, it is possible for us to be far
@@ -258,7 +240,7 @@ int init_module(void)
 	printk(KERN_INFO "dahdi_dummy: High Resolution Timer started, good to go\n");
 #else
 	timer_setup(&timer, dahdi_dummy_timer, 0);
-	ztd->start_interval = current_kernel_time();
+	ztd->start_interval = ktime_get();
 	atomic_set(&shutdown, 0);
 	mod_timer(&timer, jiffies + JIFFIES_INTERVAL);
 #endif

commit 444af631bb7440da9a2b62f4edda9b131bb0fd30
Author: Shaun Ruffell <sruffell at sruffell.net>
Date:   Thu Jan 10 03:55:26 2019 +0000

    dahdi_dummy: Fix timer_setup API usage.
    
    It looked like the recent change to add support for timer_setup was not
    completely implemented / tested with dahdi_dummy. I was using it to
    check some changes to the timekeeping API when I noticed this.
    
    This does not really affect anyone since, by default, dahdi_dummy is no
    longer built and even if it was built, it would not use the standard
    timer interface by default on newer kernels.

diff --git a/drivers/dahdi/dahdi_dummy.c b/drivers/dahdi/dahdi_dummy.c
index 61e2c4f..03a2991 100644
--- a/drivers/dahdi/dahdi_dummy.c
+++ b/drivers/dahdi/dahdi_dummy.c
@@ -156,7 +156,7 @@ static unsigned long timespec_diff_ms(struct timespec *t0, struct timespec *t1)
 	return ms;
 }
 
-static void dahdi_dummy_timer(struct timer_timer *unused)
+static void dahdi_dummy_timer(TIMER_DATA_TYPE unused)
 {
 	unsigned long ms_since_start;
 	struct timespec now;
@@ -257,7 +257,7 @@ int init_module(void)
 	hrtimer_start(&zaptimer, ktime_set(0, DAHDI_TIME_NS), HRTIMER_MODE_REL);
 	printk(KERN_INFO "dahdi_dummy: High Resolution Timer started, good to go\n");
 #else
-	timer_setup(&timer, dahdi_dummy_timer);
+	timer_setup(&timer, dahdi_dummy_timer, 0);
 	ztd->start_interval = current_kernel_time();
 	atomic_set(&shutdown, 0);
 	mod_timer(&timer, jiffies + JIFFIES_INTERVAL);

commit f01f9cbec27dd6654e0ea55602fe1a75acc22c67
Author: Shaun Ruffell <sruffell at sruffell.net>
Date:   Thu Jan 10 03:23:40 2019 +0000

    dahdi: Update coretimer to use ktime instead of 'struct timespec'
    
    Since this is only used internally, and ktime is the basis for
    timekeeping in the kernel, this allows this interface to be validated,
    before converting the other internal timekeeping to it.
    
    This is part of the changes necessary to remove the use of 'struct
    timeval' from the driver suite for compatibility with Linux 5.0, which
    is updating the internal timekeeping interfaces to fix the 2038 problem.

diff --git a/drivers/dahdi/dahdi-base.c b/drivers/dahdi/dahdi-base.c
index 7892366..90166d5 100644
--- a/drivers/dahdi/dahdi-base.c
+++ b/drivers/dahdi/dahdi-base.c
@@ -198,7 +198,7 @@ static int maxlinks;
 
 static struct core_timer {
 	struct timer_list timer;
-	struct timespec start_interval;
+	ktime_t start_interval;
 	unsigned long interval;
 	int dahdi_receive_used;
 	atomic_t count;
@@ -10025,24 +10025,6 @@ static void coretimer_cleanup(void)
 
 #else
 
-static unsigned long core_diff_ms(struct timespec *t0, struct timespec *t1)
-{
-	long nanosec, sec;
-	unsigned long ms;
-	sec = (t1->tv_sec - t0->tv_sec);
-	nanosec = (t1->tv_nsec - t0->tv_nsec);
-	while (nanosec >= NSEC_PER_SEC) {
-		nanosec -= NSEC_PER_SEC;
-		++sec;
-	}
-	while (nanosec < 0) {
-		nanosec += NSEC_PER_SEC;
-		--sec;
-	}
-	ms = (sec * 1000) + (nanosec / 1000000L);
-	return ms;
-}
-
 static inline unsigned long msecs_processed(const struct core_timer *const ct)
 {
 	return atomic_read(&ct->count) * DAHDI_MSECS_PER_CHUNK;
@@ -10051,14 +10033,14 @@ static inline unsigned long msecs_processed(const struct core_timer *const ct)
 static void coretimer_func(TIMER_DATA_TYPE unused)
 {
 	unsigned long flags;
-	unsigned long ms_since_start;
-	struct timespec now;
+	long ms_since_start;
+	ktime_t now;
 	const unsigned long MAX_INTERVAL = 100000L;
 	const unsigned long ONESEC_INTERVAL = HZ;
 	const long MS_LIMIT = 3000;
 	long difference;
 
-	ktime_get_ts(&now);
+	now = ktime_get();
 
 	if (atomic_read(&core_timer.count) ==
 	    atomic_read(&core_timer.last_count)) {
@@ -10076,7 +10058,7 @@ static void coretimer_func(TIMER_DATA_TYPE unused)
 				  core_timer.interval);
 		}
 
-		ms_since_start = core_diff_ms(&core_timer.start_interval, &now);
+		ms_since_start = ktime_ms_delta(now, core_timer.start_interval);
 
 		/*
 		 * If the system time has changed, it is possible for us to be
@@ -10130,7 +10112,7 @@ static void coretimer_func(TIMER_DATA_TYPE unused)
 static void coretimer_init(void)
 {
 	timer_setup(&core_timer.timer, coretimer_func, 0);
-	ktime_get_ts(&core_timer.start_interval);
+	core_timer.start_interval = ktime_get();
 	atomic_set(&core_timer.count, 0);
 	atomic_set(&core_timer.shutdown, 0);
 	core_timer.interval = max(msecs_to_jiffies(DAHDI_MSECS_PER_CHUNK), 1UL);

commit 419a67587c21e43193acf9fd5d325043a7455224
Author: Shaun Ruffell <sruffell at sruffell.net>
Date:   Tue Jan 8 14:03:35 2019 +0000

    oct612x: timeval -> ktime

diff --git a/drivers/dahdi/oct612x/oct612x-user.c b/drivers/dahdi/oct612x/oct612x-user.c
index 8d99271..73f1d48 100644
--- a/drivers/dahdi/oct612x/oct612x-user.c
+++ b/drivers/dahdi/oct612x/oct612x-user.c
@@ -23,6 +23,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/hrtimer.h>
 
 #include <dahdi/kernel.h>
 
@@ -31,15 +32,11 @@
 UINT32 Oct6100UserGetTime(tPOCT6100_GET_TIME f_pTime)
 {
 	/* Why couldn't they just take a timeval like everyone else? */
-	struct timeval tv;
-	unsigned long long total_usecs;
-	unsigned int mask = ~0;
-
-	do_gettimeofday(&tv);
-	total_usecs = (((unsigned long long)(tv.tv_sec)) * 1000000) +
-				  (((unsigned long long)(tv.tv_usec)));
-	f_pTime->aulWallTimeUs[0] = (total_usecs & mask);
-	f_pTime->aulWallTimeUs[1] = (total_usecs >> 32);
+	u64 total_usecs;
+
+	total_usecs = ktime_to_us(ktime_get_real());
+	f_pTime->aulWallTimeUs[0] = total_usecs;
+	f_pTime->aulWallTimeUs[1] = total_usecs >> 32;
 	return cOCT6100_ERR_OK;
 }
 

commit b42294a4cd1b96f5e25d04b0bf84d762992c1604
Author: Shaun Ruffell <sruffell at sruffell.net>
Date:   Fri Jan 11 16:10:12 2019 +0000

    Backport ktime_ms_delta().
    
    This function will return the number of milliseconds between two ktime values,
    but it was only introduced in kernel version 4.0

diff --git a/include/dahdi/kernel.h b/include/dahdi/kernel.h
index 1b4ba10..1fe917c 100644
--- a/include/dahdi/kernel.h
+++ b/include/dahdi/kernel.h
@@ -1413,6 +1413,30 @@ timer_setup(struct timer_list *timer,
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
 #define refcount_read atomic_read
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
+
+#ifdef RHEL_RELEASE_VERSION
+#if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6, 8)
+#define DAHDI_HAVE_KTIME_MS_DELTA
+#endif
+#endif
+
+#ifndef DAHDI_HAVE_KTIME_MS_DELTA
+static inline s64 dahdi_ktime_to_ms(const ktime_t kt)
+{
+	struct timeval tv = ktime_to_timeval(kt);
+	return (s64) tv.tv_sec * MSEC_PER_SEC + tv.tv_usec / USEC_PER_MSEC;
+}
+
+static inline s64 ktime_ms_delta(const ktime_t later, const ktime_t earlier)
+{
+	return dahdi_ktime_to_ms(ktime_sub(later, earlier));
+}
+#else
+#undef DAHDI_HAVE_KTIME_MS_DELTA
+#endif
+
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0)
 
 /* DAHDI only was using the xxx_clear_bit variants. */
@@ -1451,6 +1475,7 @@ static inline void *PDE_DATA(const struct inode *inode)
 #endif /* 2.6.31 */
 #endif /* 3.10.0 */
 #endif /* 3.16.0 */
+#endif /* 4.0.0 */
 #endif /* 4.11.0 */
 #endif /* 4.13.0 */
 #else /* >= 4.15.0 */

commit 3d0bf359a77eaa059f567c1daeac273b3f571cc7
Author: Shaun Ruffell <sruffell at sruffell.net>
Date:   Tue Jan 8 06:08:18 2019 +0000

    Makefile: SUBDIRS -> KBUILD_EXTMOD
    
    The SUBDIRS environment variable is scheduled to be removed in version
    5.0 of the Linux Kernel.
    
    Signed-off-by: Shaun Ruffell <sruffell at sruffell.net>

diff --git a/Makefile b/Makefile
index fda4c08..a4e5afd 100644
--- a/Makefile
+++ b/Makefile
@@ -53,7 +53,7 @@ INST_HEADERS:=kernel.h user.h fasthdlc.h wctdm_user.h dahdi_config.h
 
 DAHDI_BUILD_ALL:=m
 
-KMAKE=+$(MAKE) -C $(KSRC) SUBDIRS=$(PWD)/drivers/dahdi DAHDI_INCLUDE=$(PWD)/include DAHDI_MODULES_EXTRA="$(DAHDI_MODULES_EXTRA)" HOTPLUG_FIRMWARE=$(HOTPLUG_FIRMWARE)
+KMAKE=+$(MAKE) -C $(KSRC) KBUILD_EXTMOD=$(PWD)/drivers/dahdi DAHDI_INCLUDE=$(PWD)/include DAHDI_MODULES_EXTRA="$(DAHDI_MODULES_EXTRA)" HOTPLUG_FIRMWARE=$(HOTPLUG_FIRMWARE)
 
 ROOT_PREFIX:=
 
diff --git a/drivers/dahdi/datamods/Makefile b/drivers/dahdi/datamods/Makefile
index 310073e..5d63668 100644
--- a/drivers/dahdi/datamods/Makefile
+++ b/drivers/dahdi/datamods/Makefile
@@ -8,7 +8,7 @@ PWD=$(shell pwd)
 
 MODULESO:=$(MODULES:%=%.o)
 MODULESKO:=$(MODULES:%=%.ko)
-KMAKE = $(MAKE) -C $(KSRC) SUBDIRS=$(PWD)
+KMAKE = $(MAKE) -C $(KSRC) KBUILD_EXTMOD=$(PWD)
 KMAKE_INST = $(KMAKE) \
   INSTALL_MOD_PATH=$(INSTALL_PREFIX) INSTALL_MOD_DIR=misc modules_install
 

commit ec0211882276ed84a4c308f443deb8fd038d8c2e
Author: Shaun Ruffell <sruffell at sruffell.net>
Date:   Fri Jan 11 05:12:09 2019 +0000

    Remove CLASS_DEV_CREATE / CLASS_DEV_DESTROY macros.
    
    This is more simplification since all supported kernel versions were
    using the same signature for device_create / device_destroy.

diff --git a/drivers/dahdi/dahdi-sysfs-chan.c b/drivers/dahdi/dahdi-sysfs-chan.c
index 125a355..a91e6ed 100644
--- a/drivers/dahdi/dahdi-sysfs-chan.c
+++ b/drivers/dahdi/dahdi-sysfs-chan.c
@@ -33,9 +33,11 @@
 
 /* shortcuts, for code readability */
 #define MAKE_DAHDI_DEV(num, name) \
-	CLASS_DEV_CREATE(dahdi_class, MKDEV(DAHDI_MAJOR, num), NULL, name)
+	device_create(dahdi_class, NULL, MKDEV(DAHDI_MAJOR, num), \
+		      NULL, "%s", name)
+
 #define DEL_DAHDI_DEV(num) \
-	CLASS_DEV_DESTROY(dahdi_class, MKDEV(DAHDI_MAJOR, num))
+	device_destroy(dahdi_class, MKDEV(DAHDI_MAJOR, num))
 
 static struct class *dahdi_class;
 
diff --git a/drivers/dahdi/dahdi-sysfs.h b/drivers/dahdi/dahdi-sysfs.h
index a6f2479..d8bdb42 100644
--- a/drivers/dahdi/dahdi-sysfs.h
+++ b/drivers/dahdi/dahdi-sysfs.h
@@ -21,14 +21,6 @@
 #define	DRIVER_ATTR_READER(name, drv, buf)	\
 		ssize_t name(struct device_driver *drv, char * buf)
 
-/* Device file creation macros */
-#define CLASS_DEV_CREATE(class, devt, device, name) \
-	device_create(class, device, devt, NULL, "%s", name)
-
-/* Device file destruction macros */
-#define CLASS_DEV_DESTROY(class, devt) \
-	device_destroy(class, devt)
-
 /* Global */
 int __init dahdi_sysfs_chan_init(const struct file_operations *fops);
 void dahdi_sysfs_chan_exit(void);

commit 1133c0a14ff2a1b479c8eae591afdeecfd26e962
Author: Shaun Ruffell <sruffell at sruffell.net>
Date:   Fri Jan 11 05:04:45 2019 +0000

    wct4xxp: Remove unnused ENABLE_WORKQUEUE code paths
    
    ENABLE_WORKQUEUE was only defined for kernels that were older than the
    currently supported kernels. Instead of forward porting support for
    workqueues in the wct4xxp driver, I think it better just to remove
    support for them since they are not longer used.

diff --git a/drivers/dahdi/wct4xxp/base.c b/drivers/dahdi/wct4xxp/base.c
index 4d0c769..7089ec1 100644
--- a/drivers/dahdi/wct4xxp/base.c
+++ b/drivers/dahdi/wct4xxp/base.c
@@ -48,13 +48,6 @@
 #include "wct4xxp.h"
 #include "vpm450m.h"
 
-/*
- * Work queues can significantly improve performance and scalability
- * on multi-processor machines, but requires bypassing some kernel
- * API's, so it's not guaranteed to be compatible with all kernels.
- */
-/* #define ENABLE_WORKQUEUES */
-
 /* Support first generation cards? */
 #define SUPPORT_GEN1 
 
@@ -76,88 +69,6 @@
 /* Maximum latency to be used with Gen 5 */
 #define GEN5_MAX_LATENCY	127
 
-#ifdef ENABLE_WORKQUEUES
-#include <linux/cpu.h>
-
-/* XXX UGLY!!!! XXX  We have to access the direct structures of the workqueue which
-  are only defined within workqueue.c because they don't give us a routine to allow us
-  to nail a work to a particular thread of the CPU.  Nailing to threads gives us substantially
-  higher scalability in multi-CPU environments though! */
-
-/*
- * The per-CPU workqueue (if single thread, we always use cpu 0's).
- *
- * The sequence counters are for flush_scheduled_work().  It wants to wait
- * until until all currently-scheduled works are completed, but it doesn't
- * want to be livelocked by new, incoming ones.  So it waits until
- * remove_sequence is >= the insert_sequence which pertained when
- * flush_scheduled_work() was called.
- */
- 
-struct cpu_workqueue_struct {
-
-	spinlock_t lock;
-
-	long remove_sequence;	/* Least-recently added (next to run) */
-	long insert_sequence;	/* Next to add */
-
-	struct list_head worklist;
-	wait_queue_head_t more_work;
-	wait_queue_head_t work_done;
-
-	struct workqueue_struct *wq;
-	task_t *thread;
-
-	int run_depth;		/* Detect run_workqueue() recursion depth */
-} ____cacheline_aligned;
-
-/*
- * The externally visible workqueue abstraction is an array of
- * per-CPU workqueues:
- */
-struct workqueue_struct {
-	/* TODO: Find out exactly where the API changed */
-	struct cpu_workqueue_struct *cpu_wq;
-	const char *name;
-	struct list_head list; 	/* Empty if single thread */
-};
-
-/* Preempt must be disabled. */
-static void __t4_queue_work(struct cpu_workqueue_struct *cwq,
-			 struct work_struct *work)
-{
-	unsigned long flags;
-
-	spin_lock_irqsave(&cwq->lock, flags);
-	work->wq_data = cwq;
-	list_add_tail(&work->entry, &cwq->worklist);
-	cwq->insert_sequence++;
-	wake_up(&cwq->more_work);
-	spin_unlock_irqrestore(&cwq->lock, flags);
-}
-
-/*
- * Queue work on a workqueue. Return non-zero if it was successfully
- * added.
- *
- * We queue the work to the CPU it was submitted, but there is no
- * guarantee that it will be processed by that CPU.
- */
-static inline int t4_queue_work(struct workqueue_struct *wq, struct work_struct *work, int cpu)
-{
-	int ret = 0;
-	get_cpu();
-	if (!test_and_set_bit(0, &work->pending)) {
-		BUG_ON(!list_empty(&work->entry));
-		__t4_queue_work(wq->cpu_wq + cpu, work);
-		ret = 1;
-	}
-	put_cpu();
-	return ret;
-}
-
-#endif
-
 /*
  * Define CONFIG_FORCE_EXTENDED_RESET to allow the qfalc framer extra time
  * to reset itself upon hardware initialization. This exits for rare
@@ -321,9 +232,6 @@ struct t4_span {
 	unsigned long dtmfmask;
 	unsigned long dtmfmutemask;
 #endif
-#ifdef ENABLE_WORKQUEUES
-	struct work_struct swork;
-#endif	
 	struct dahdi_chan *chans[32];		/* Individual channels */
 	struct dahdi_echocan_state *ec[32];	/* Echocan state for each channel */
 };
@@ -356,10 +264,6 @@ struct t4 {
 	int spansstarted;		/* number of spans started */
 	u32 *writechunk;		/* Double-word aligned write memory */
 	u32 *readchunk;			/* Double-word aligned read memory */
-#ifdef ENABLE_WORKQUEUES
-	atomic_t worklist;
-	struct workqueue_struct *workq;
-#endif
 	int last0;		/* for detecting double-missed IRQ */
 
 	/* DMA related fields */
@@ -3192,19 +3096,6 @@ static inline void __transmit_span(struct t4_span *ts)
 	_dahdi_transmit(&ts->span);
 }
 
-#ifdef ENABLE_WORKQUEUES
-static void workq_handlespan(void *data)
-{
-	struct t4_span *ts = data;
-	struct t4 *wc = ts->owner;
-	
-	__receive_span(ts);
-	__transmit_span(ts);
-	atomic_dec(&wc->worklist);
-	if (!atomic_read(&wc->worklist))
-		t4_pci_out(wc, WC_INTR, 0);
-}
-#else
 static void t4_prep_gen2(struct t4 *wc)
 {
 	int x;
@@ -3216,7 +3107,6 @@ static void t4_prep_gen2(struct t4 *wc)
 	}
 }
 
-#endif
 #ifdef SUPPORT_GEN1
 static void t4_transmitprep(struct t4 *wc, int irq)
 {
@@ -4094,10 +3984,6 @@ static irqreturn_t _t4_interrupt_gen2(int irq, void *dev_id)
 		return IRQ_NONE;
 	}
 
-#ifdef ENABLE_WORKQUEUES
-	__t4_pci_out(wc, WC_INTR, status & 0x00000008);
-#endif
-
 	if (unlikely(!wc->spansstarted)) {
 		dev_info(&wc->dev->dev, "Not prepped yet!\n");
 		return IRQ_NONE;
@@ -4160,28 +4046,6 @@ static irqreturn_t _t4_interrupt_gen2(int irq, void *dev_id)
 #endif
 
 	if (likely(status & 0x2)) {
-#ifdef ENABLE_WORKQUEUES
-		int cpus = num_online_cpus();
-		atomic_set(&wc->worklist, wc->numspans);
-		if (wc->tspans[0]->span.flags & DAHDI_FLAG_RUNNING)
-			t4_queue_work(wc->workq, &wc->tspans[0]->swork, 0);
-		else
-			atomic_dec(&wc->worklist);
-		if (wc->tspans[1]->span.flags & DAHDI_FLAG_RUNNING)
-			t4_queue_work(wc->workq, &wc->tspans[1]->swork, 1 % cpus);
-		else
-			atomic_dec(&wc->worklist);
-		if (wc->numspans == 4) {
-			if (wc->tspans[2]->span.flags & DAHDI_FLAG_RUNNING)
-				t4_queue_work(wc->workq, &wc->tspans[2]->swork, 2 % cpus);
-			else
-				atomic_dec(&wc->worklist);
-			if (wc->tspans[3]->span.flags & DAHDI_FLAG_RUNNING)
-				t4_queue_work(wc->workq, &wc->tspans[3]->swork, 3 % cpus);
-			else
-				atomic_dec(&wc->worklist);
-		}
-#else
 		unsigned int reg5 = __t4_pci_in(wc, 5);
 
 #ifdef DEBUG
@@ -4201,7 +4065,6 @@ static irqreturn_t _t4_interrupt_gen2(int irq, void *dev_id)
 			t4_prep_gen2(wc);
 		}
 
-#endif
 		t4_do_counters(wc);
 		spin_lock(&wc->reglock);
 		__handle_leds(wc);
@@ -4256,10 +4119,7 @@ out:
 	if (unlikely(test_bit(T4_CHANGE_LATENCY, &wc->checkflag) || test_bit(T4_CHECK_VPM, &wc->checkflag)))
 		schedule_work(&wc->bh_work);
 
-#ifndef ENABLE_WORKQUEUES
 	__t4_pci_out(wc, WC_INTR, 0);
-#endif	
-
 	return IRQ_RETVAL(1);
 }
 
@@ -4925,9 +4785,6 @@ __t4_hardware_init_1(struct t4 *wc, unsigned int cardflags, bool first_time)
 	if (debug) {
 		dev_info(&wc->dev->dev, "Burst Mode: %s\n",
 			(!(cardflags & FLAG_BURST) && noburst) ? "Off" : "On");
-#ifdef ENABLE_WORKQUEUES
-		dev_info(&wc->dev->dev, "Work Queues: Enabled\n");
-#endif
 	}
 
 	/* Check the field updatable firmware for the wcte820 */
@@ -5286,15 +5143,6 @@ t4_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	wc->num = x;
 	cards[x] = wc;
 	
-#ifdef ENABLE_WORKQUEUES
-	if (wc->devtype->flags & FLAG_2NDGEN) {
-		char tmp[20];
-
-		sprintf(tmp, "te%dxxp[%d]", wc->numspans, wc->num);
-		wc->workq = create_workqueue(tmp);
-	}
-#endif			
-
 	/* Allocate pieces we need here */
 	for (x = 0; x < ports_on_framer(wc); x++) {
 		struct t4_span *ts;
@@ -5307,9 +5155,6 @@ t4_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		}
 		wc->tspans[x] = ts;
 
-#ifdef ENABLE_WORKQUEUES
-		INIT_WORK(&ts->swork, workq_handlespan, ts);
-#endif				
 		ts->spanflags |= wc->devtype->flags;
 		linemode = (wc->t1e1 & (1 << x)) ? E1 : ((j1mode) ? J1 : T1);
 		t4_alloc_channels(wc, wc->tspans[x], linemode);
@@ -5449,13 +5294,6 @@ static void _t4_remove_one(struct t4 *wc)
 	if (!(wc->tspans[0]->spanflags & FLAG_2NDGEN))
 		basesize = basesize * 2;
 
-#ifdef ENABLE_WORKQUEUES
-	if (wc->workq) {
-		flush_workqueue(wc->workq);
-		destroy_workqueue(wc->workq);
-	}
-#endif			
-	
 	free_irq(wc->dev->irq, wc);
 	
 	if (wc->membase)

commit 867170c508701298be742e5aa7edb6cc2184a2f0
Author: Shaun Ruffell <sruffell at sruffell.net>
Date:   Fri Jan 11 04:46:35 2019 +0000

    Remove unnecessary dahdi_pci_module macro.
    
    All supported kernel variations support the same signature for registering a
    PCI module, so we can eliminate the macro.

diff --git a/drivers/dahdi/wcaxx-base.c b/drivers/dahdi/wcaxx-base.c
index ed7207a..b934960 100644
--- a/drivers/dahdi/wcaxx-base.c
+++ b/drivers/dahdi/wcaxx-base.c
@@ -4474,7 +4474,7 @@ static int __init wcaxx_init(void)
 	if (!battthresh)
 		battthresh = fxo_modes[_opermode].battthresh;
 
-	res = dahdi_pci_module(&wcaxx_driver);
+	res = pci_register_driver(&wcaxx_driver);
 	if (res)
 		return -ENODEV;
 
diff --git a/drivers/dahdi/wcb4xxp/base.c b/drivers/dahdi/wcb4xxp/base.c
index 1f72f14..784929f 100644
--- a/drivers/dahdi/wcb4xxp/base.c
+++ b/drivers/dahdi/wcb4xxp/base.c
@@ -3672,7 +3672,7 @@ static int __init b4xx_init(void)
 		printk(KERN_ERR "%s: ERROR: Could not initialize /proc/%s\n",THIS_MODULE->name, PROCFS_NAME);
 	}
 #endif
-	if (dahdi_pci_module(&b4xx_driver))
+	if (pci_register_driver(&b4xx_driver))
 		return -ENODEV;
 
 	return 0;
diff --git a/drivers/dahdi/wct4xxp/base.c b/drivers/dahdi/wct4xxp/base.c
index c1d9612..4d0c769 100644
--- a/drivers/dahdi/wct4xxp/base.c
+++ b/drivers/dahdi/wct4xxp/base.c
@@ -5543,7 +5543,7 @@ static int __init t4_init(void)
 			"Please use 'default_linemode' instead.\n");
 	}
 
-	res = dahdi_pci_module(&t4_driver);
+	res = pci_register_driver(&t4_driver);
 	if (res)
 		return -ENODEV;
 
diff --git a/drivers/dahdi/wctc4xxp/base.c b/drivers/dahdi/wctc4xxp/base.c
index 54e28d3..3bd56d1 100644
--- a/drivers/dahdi/wctc4xxp/base.c
+++ b/drivers/dahdi/wctc4xxp/base.c
@@ -4236,7 +4236,7 @@ static int __init wctc4xxp_init(void)
 		return -ENOMEM;
 	spin_lock_init(&wctc4xxp_list_lock);
 	INIT_LIST_HEAD(&wctc4xxp_list);
-	res = dahdi_pci_module(&wctc4xxp_driver);
+	res = pci_register_driver(&wctc4xxp_driver);
 	if (res) {
 		kmem_cache_destroy(cmd_cache);
 		return -ENODEV;
diff --git a/drivers/dahdi/wctdm24xxp/base.c b/drivers/dahdi/wctdm24xxp/base.c
index d2e481a..16bf384 100644
--- a/drivers/dahdi/wctdm24xxp/base.c
+++ b/drivers/dahdi/wctdm24xxp/base.c
@@ -6102,7 +6102,7 @@ static int __init wctdm_init(void)
 
 	b400m_module_init();
 
-	res = dahdi_pci_module(&wctdm_driver);
+	res = pci_register_driver(&wctdm_driver);
 	if (res)
 		return -ENODEV;
 
diff --git a/drivers/dahdi/wcte13xp-base.c b/drivers/dahdi/wcte13xp-base.c
index 25d4e31..b5f8043 100644
--- a/drivers/dahdi/wcte13xp-base.c
+++ b/drivers/dahdi/wcte13xp-base.c
@@ -2788,7 +2788,7 @@ static int __init te13xp_init(void)
 		return -EINVAL;
 	}
 
-	res = dahdi_pci_module(&te13xp_driver);
+	res = pci_register_driver(&te13xp_driver);
 	if (res)
 		return -ENODEV;
 
diff --git a/drivers/dahdi/wcte43x-base.c b/drivers/dahdi/wcte43x-base.c
index dd8b8ed..b023504 100644
--- a/drivers/dahdi/wcte43x-base.c
+++ b/drivers/dahdi/wcte43x-base.c
@@ -3612,7 +3612,7 @@ static int __init t43x_init(void)
 		return -EINVAL;
 	}
 
-	res = dahdi_pci_module(&t43x_driver);
+	res = pci_register_driver(&t43x_driver);
 	if (res)
 		return -ENODEV;
 
diff --git a/include/dahdi/kernel.h b/include/dahdi/kernel.h
index eb3f691..1b4ba10 100644
--- a/include/dahdi/kernel.h
+++ b/include/dahdi/kernel.h
@@ -58,8 +58,6 @@
 
 #include <linux/poll.h>
 
-#define dahdi_pci_module pci_register_driver
-
 #ifdef CONFIG_PCI
 #include <linux/pci-aspm.h>
 #endif

commit 1683b8d36c1ec8e2902874342c0976df01987c32
Author: Shaun Ruffell <sruffell at sruffell.net>
Date:   Fri Jan 11 04:43:26 2019 +0000

    Remove unnecessary DAHDI_IRQ_HANDLER macro.
    
    All supported kernels now use the same signature for the IRQ handler.

diff --git a/drivers/dahdi/wcb4xxp/base.c b/drivers/dahdi/wcb4xxp/base.c
index 5fe6fb2..1f72f14 100644
--- a/drivers/dahdi/wcb4xxp/base.c
+++ b/drivers/dahdi/wcb4xxp/base.c
@@ -2963,7 +2963,7 @@ static void init_spans(struct b4xxp *b4)
 static void b4xxp_bottom_half(unsigned long data);
 
 /* top-half interrupt handler */
-DAHDI_IRQ_HANDLER(b4xxp_interrupt)
+static irqreturn_t b4xxp_interrupt(int irq, void *dev_id)
 {
 	struct b4xxp *b4 = dev_id;
 	unsigned char status;
diff --git a/drivers/dahdi/wct4xxp/base.c b/drivers/dahdi/wct4xxp/base.c
index 1b37c43..c1d9612 100644
--- a/drivers/dahdi/wct4xxp/base.c
+++ b/drivers/dahdi/wct4xxp/base.c
@@ -3941,7 +3941,7 @@ static irqreturn_t _t4_interrupt(int irq, void *dev_id)
 	return IRQ_RETVAL(1);
 }
 
-DAHDI_IRQ_HANDLER(t4_interrupt)
+static irqreturn_t t4_interrupt(int irq, void *dev_id)
 {
 	irqreturn_t ret;
 	unsigned long flags;
@@ -4263,7 +4263,7 @@ out:
 	return IRQ_RETVAL(1);
 }
 
-DAHDI_IRQ_HANDLER(t4_interrupt_gen2)
+static irqreturn_t t4_interrupt_gen2(int irq, void *dev_id)
 {
 	irqreturn_t ret;
 	unsigned long flags;
diff --git a/drivers/dahdi/wctc4xxp/base.c b/drivers/dahdi/wctc4xxp/base.c
index 55c6026..54e28d3 100644
--- a/drivers/dahdi/wctc4xxp/base.c
+++ b/drivers/dahdi/wctc4xxp/base.c
@@ -2731,7 +2731,7 @@ static void deferred_work_func(struct work_struct *work)
 	service_rx_ring(wc);
 }
 
-DAHDI_IRQ_HANDLER(wctc4xxp_interrupt)
+static irqreturn_t wctc4xxp_interrupt(int irq, void *dev_id)
 {
 	struct wcdte *wc = dev_id;
 	bool packets_to_process = false;
diff --git a/drivers/dahdi/wcxb.c b/drivers/dahdi/wcxb.c
index 4eaba8f..122f9d3 100644
--- a/drivers/dahdi/wcxb.c
+++ b/drivers/dahdi/wcxb.c
@@ -478,7 +478,7 @@ static irqreturn_t _wcxb_isr(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
-DAHDI_IRQ_HANDLER(wcxb_isr)
+static irqreturn_t wcxb_isr(int irq, void *dev_id)
 {
 	irqreturn_t ret;
 	unsigned long flags;
diff --git a/include/dahdi/kernel.h b/include/dahdi/kernel.h
index 363b613..eb3f691 100644
--- a/include/dahdi/kernel.h
+++ b/include/dahdi/kernel.h
@@ -60,8 +60,6 @@
 
 #define dahdi_pci_module pci_register_driver
 
-#define DAHDI_IRQ_HANDLER(a) static irqreturn_t a(int irq, void *dev_id)
-
 #ifdef CONFIG_PCI
 #include <linux/pci-aspm.h>
 #endif

commit ac80259bcc34dad70155f72bdc7e5e195cef9d83
Author: Shaun Ruffell <sruffell at sruffell.net>
Date:   Fri Jan 11 03:59:45 2019 +0000

    Remove support for kernels older than 2.6.27
    
    There are not any major distributions that are still supporting kernels
    older than 2.6.27 so we can remove many typedefs. The primary motivator
    for this change is that kernel 5.0 is dropping support for timeval and
    it would be ideal if the in-kernel time representation can
    standardize on ktime_t, but 2.6.18 did not support the ktime
    interface that was needed.

diff --git a/drivers/dahdi/dahdi-base.c b/drivers/dahdi/dahdi-base.c
index 38df9c4..7892366 100644
--- a/drivers/dahdi/dahdi-base.c
+++ b/drivers/dahdi/dahdi-base.c
@@ -103,11 +103,7 @@
 #define chan_to_netdev(h) ((h)->hdlcnetdev->netdev)
 
 /* macro-oni for determining a unit (channel) number */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20)
-#define	UNIT(file) MINOR(file->f_dentry->d_inode->i_rdev)
-#else
 #define	UNIT(file) MINOR(file->f_path.dentry->d_inode->i_rdev)
-#endif
 
 EXPORT_SYMBOL(dahdi_transcode_fops);
 EXPORT_SYMBOL(dahdi_init_tone_state);
@@ -1973,12 +1969,10 @@ static inline void print_debug_writebuf(struct dahdi_chan* ss, struct sk_buff *s
 #endif
 
 #ifdef CONFIG_DAHDI_NET
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 26)
 static inline struct net_device_stats *hdlc_stats(struct net_device *dev)
 {
 	return &dev->stats;
 }
-#endif
 
 static int dahdi_net_open(struct net_device *dev)
 {
@@ -3938,19 +3932,11 @@ static void __dahdi_find_master_span(void)
 		module_printk(KERN_NOTICE, "Master changed to %s\n", s->name);
 }
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20)
-static void _dahdi_find_master_span(void *work)
-{
-	__dahdi_find_master_span();
-}
-static DECLARE_WORK(find_master_work, _dahdi_find_master_span, NULL);
-#else
 static void _dahdi_find_master_span(struct work_struct *work)
 {
 	__dahdi_find_master_span();
 }
 static DECLARE_WORK(find_master_work, _dahdi_find_master_span);
-#endif
 
 static void dahdi_find_master_span(void)
 {
@@ -4970,9 +4956,6 @@ static int dahdi_ioctl_chanconfig(struct file *file, unsigned long data)
 			chan->hdlcnetdev->netdev = alloc_hdlcdev(chan->hdlcnetdev);
 			if (chan->hdlcnetdev->netdev) {
 				chan->hdlcnetdev->chan = chan;
-#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 23)
-				SET_MODULE_OWNER(chan->hdlcnetdev->netdev);
-#endif
 				chan->hdlcnetdev->netdev->tx_queue_len = 50;
 #ifdef HAVE_NET_DEVICE_OPS
 				chan->hdlcnetdev->netdev->netdev_ops = &dahdi_netdev_ops;
@@ -9384,11 +9367,7 @@ that the waitqueue is empty. */
 #ifdef CONFIG_DAHDI_NET
 		if (skb && dahdi_have_netdev(ms))
 		{
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
-			skb->mac.raw = skb->data;
-#else
 			skb_reset_mac_header(skb);
-#endif
 			skb->dev = chan_to_netdev(ms);
 #ifdef DAHDI_HDLC_TYPE_TRANS
 			skb->protocol = hdlc_type_trans(skb,
@@ -10550,35 +10529,10 @@ failed_driver_init:
 	return res;
 }
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)
-#ifdef CONFIG_PCI
-void dahdi_pci_disable_link_state(struct pci_dev *pdev, int state)
-{
-	u16 reg16;
-	int pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
-	state &= (PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
-		  PCIE_LINK_STATE_CLKPM);
-	if (!pos)
-		return;
-	pci_read_config_word(pdev, pos + PCI_EXP_LNKCTL, &reg16);
-	reg16 &= ~(state);
-	pci_write_config_word(pdev, pos + PCI_EXP_LNKCTL, reg16);
-}
-EXPORT_SYMBOL(dahdi_pci_disable_link_state);
-#endif /* CONFIG_PCI */
-#endif /* 2.6.25 */
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 22)
-static inline void flush_find_master_work(void)
-{
-	flush_scheduled_work();
-}
-#else
 static inline void flush_find_master_work(void)
 {
 	cancel_work_sync(&find_master_work);
 }
-#endif
 
 static void __exit dahdi_cleanup(void)
 {
diff --git a/drivers/dahdi/dahdi-sysfs.c b/drivers/dahdi/dahdi-sysfs.c
index b440fab..d1f2379 100644
--- a/drivers/dahdi/dahdi-sysfs.c
+++ b/drivers/dahdi/dahdi-sysfs.c
@@ -61,38 +61,6 @@ static inline struct dahdi_span *dev_to_span(struct device *dev)
 		DAHDI_ADD_UEVENT_VAR("SPAN_NAME=%s", span->name);	\
 	} while (0)
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
-#define DAHDI_ADD_UEVENT_VAR(fmt, val...)			\
-	do {							\
-		int err = add_uevent_var(envp, num_envp, &i,	\
-				buffer, buffer_size, &len,	\
-				fmt, val);			\
-		if (err)					\
-			return err;				\
-	} while (0)
-
-static int span_uevent(struct device *dev, char **envp, int num_envp,
-		char *buffer, int buffer_size)
-{
-	struct dahdi_span	*span;
-	int			i = 0;
-	int			len = 0;
-
-	if (!dev)
-		return -ENODEV;
-
-	span = dev_to_span(dev);
-	if (!span)
-		return -ENODEV;
-
-	dahdi_dbg(GENERAL, "SYFS dev_name=%s span=%s\n",
-			dev_name(dev), span->name);
-	SPAN_VAR_BLOCK;
-	envp[i] = NULL;
-	return 0;
-}
-
-#else
 #define DAHDI_ADD_UEVENT_VAR(fmt, val...)			\
 	do {							\
 		int err = add_uevent_var(kenv, fmt, val);	\
@@ -115,8 +83,6 @@ static int span_uevent(struct device *dev, struct kobj_uevent_env *kenv)
 	return 0;
 }
 
-#endif
-
 #define span_attr(field, format_string)				\
 static BUS_ATTR_READER(field##_show, dev, buf)			\
 {								\
@@ -465,37 +431,6 @@ static inline struct dahdi_device *to_ddev(struct device *dev)
 				ddev->location);			\
 	} while (0)
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
-#define DAHDI_ADD_UEVENT_VAR(fmt, val...)			\
-	do {							\
-		int err = add_uevent_var(envp, num_envp, &i,	\
-				buffer, buffer_size, &len,	\
-				fmt, val);			\
-		if (err)					\
-			return err;				\
-	} while (0)
-
-static int device_uevent(struct device *dev, char **envp, int num_envp,
-		char *buffer, int buffer_size)
-{
-	struct dahdi_device	*ddev;
-	int			i = 0;
-	int			len = 0;
-
-	if (!dev)
-		return -ENODEV;
-
-	ddev = to_ddev(dev);
-	if (!ddev)
-		return -ENODEV;
-
-	dahdi_dbg(GENERAL, "SYFS dev_name=%s\n", dev_name(dev));
-	DEVICE_VAR_BLOCK;
-	envp[i] = NULL;
-	return 0;
-}
-
-#else
 #define DAHDI_ADD_UEVENT_VAR(fmt, val...)			\
 	do {							\
 		int err = add_uevent_var(kenv, fmt, val);	\
@@ -517,8 +452,6 @@ static int device_uevent(struct device *dev, struct kobj_uevent_env *kenv)
 	return 0;
 }
 
-#endif
-
 static ssize_t
 manufacturer_show(struct device *dev,
 			       struct device_attribute *attr, char *buf)
diff --git a/drivers/dahdi/dahdi-sysfs.h b/drivers/dahdi/dahdi-sysfs.h
index 9cbd9f9..a6f2479 100644
--- a/drivers/dahdi/dahdi-sysfs.h
+++ b/drivers/dahdi/dahdi-sysfs.h
@@ -22,27 +22,12 @@
 		ssize_t name(struct device_driver *drv, char * buf)
 
 /* Device file creation macros */
-
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
 #define CLASS_DEV_CREATE(class, devt, device, name) \
 	device_create(class, device, devt, NULL, "%s", name)
-#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
-#define CLASS_DEV_CREATE(class, devt, device, name) \
-	device_create(class, device, devt, name)
-#else
-#define CLASS_DEV_CREATE(class, devt, device, name) \
-	class_device_create(class, NULL, devt, device, name)
-#endif
 
 /* Device file destruction macros */
-
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
 #define CLASS_DEV_DESTROY(class, devt) \
 	device_destroy(class, devt)
-#else
... 1481 lines suppressed ...


-- 
dahdi/linux.git



More information about the dahdi-commits mailing list