staging: rtl8192e: Modify time handling

In several places, the driver keeps times (in jiffies) in two 32-bit
quantities. In the rtl8192_hw_to_sleep(), there is an error in the
calculation of the difference between two 64-bit quantities. Rather
than fix that error, I have converted to a single 64-bit number. That
makes the code be much cleaner and clearer.

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
diff --git a/drivers/staging/rtl8192e/rtl_core.c b/drivers/staging/rtl8192e/rtl_core.c
index e633f0b..f585f71 100644
--- a/drivers/staging/rtl8192e/rtl_core.c
+++ b/drivers/staging/rtl8192e/rtl_core.c
@@ -2243,13 +2243,10 @@
 {
 	struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
 
-	if (stats->bIsAMPDU && !stats->bFirstMPDU) {
-		stats->mac_time[0] = priv->LastRxDescTSFLow;
-		stats->mac_time[1] = priv->LastRxDescTSFHigh;
-	} else {
-		priv->LastRxDescTSFLow = stats->mac_time[0];
-		priv->LastRxDescTSFHigh = stats->mac_time[1];
-	}
+	if (stats->bIsAMPDU && !stats->bFirstMPDU)
+		stats->mac_time = priv->LastRxDescTSF;
+	else
+		priv->LastRxDescTSF = stats->mac_time;
 }
 
 long rtl819x_translate_todbm(struct r8192_priv * priv, u8 signal_strength_index	)
diff --git a/drivers/staging/rtl8192e/rtl_core.h b/drivers/staging/rtl8192e/rtl_core.h
index 22b0a43..4f94d0a 100644
--- a/drivers/staging/rtl8192e/rtl_core.h
+++ b/drivers/staging/rtl8192e/rtl_core.h
@@ -642,8 +642,7 @@
 	int		rxringcount;
 	u16		rxbuffersize;
 
-	u32		LastRxDescTSFHigh;
-	u32		LastRxDescTSFLow;
+	u64		LastRxDescTSF;
 
 	u16		EarlyRxThreshold;
 	u32		ReceiveConfig;
diff --git a/drivers/staging/rtl8192e/rtl_ps.c b/drivers/staging/rtl8192e/rtl_ps.c
index 58966e0..ea9eac7 100644
--- a/drivers/staging/rtl8192e/rtl_ps.c
+++ b/drivers/staging/rtl8192e/rtl_ps.c
@@ -78,36 +78,33 @@
 
 #define MIN_SLEEP_TIME 50
 #define MAX_SLEEP_TIME 10000
-void rtl8192_hw_to_sleep(struct net_device *dev, u32 th, u32 tl)
+void rtl8192_hw_to_sleep(struct net_device *dev, u64 time)
 {
 	struct r8192_priv *priv = rtllib_priv(dev);
 
-	u32 rb = jiffies;
+	u32 tmp;
 	unsigned long flags;
 
 	spin_lock_irqsave(&priv->ps_lock,flags);
 
-	tl -= MSECS(8+16+7);
+	time -= MSECS(8+16+7);
 
-	if (((tl>=rb)&& (tl-rb) <= MSECS(MIN_SLEEP_TIME))
-			||((rb>tl)&& (rb-tl) < MSECS(MIN_SLEEP_TIME))) {
+	if ((time - jiffies) <= MSECS(MIN_SLEEP_TIME)) {
 		spin_unlock_irqrestore(&priv->ps_lock,flags);
-		printk("too short to sleep::%x, %x, %lx\n",tl, rb,  MSECS(MIN_SLEEP_TIME));
+		printk(KERN_INFO "too short to sleep::%lld < %ld\n",
+		       time - jiffies, MSECS(MIN_SLEEP_TIME));
 		return;
 	}
 
-	if (((tl > rb) && ((tl-rb) > MSECS(MAX_SLEEP_TIME)))||
-			((tl < rb) && (tl>MSECS(69)) && ((rb-tl) > MSECS(MAX_SLEEP_TIME)))||
-			((tl<rb)&&(tl<MSECS(69))&&((tl+0xffffffff-rb)>MSECS(MAX_SLEEP_TIME)))) {
-		printk("========>too long to sleep:%x, %x, %lx\n", tl, rb,  MSECS(MAX_SLEEP_TIME));
+	if ((time - jiffies) > MSECS(MAX_SLEEP_TIME)) {
+		printk(KERN_INFO "========>too long to sleep:%lld > %ld\n",
+		       time - jiffies,  MSECS(MAX_SLEEP_TIME));
 		spin_unlock_irqrestore(&priv->ps_lock,flags);
 		return;
 	}
-	{
-		u32 tmp = (tl>rb)?(tl-rb):(rb-tl);
-		queue_delayed_work_rsl(priv->rtllib->wq,
-				&priv->rtllib->hw_wakeup_wq,tmp);
-	}
+	tmp = time - jiffies;
+	queue_delayed_work_rsl(priv->rtllib->wq,
+			&priv->rtllib->hw_wakeup_wq,tmp);
 	queue_delayed_work_rsl(priv->rtllib->wq,
 			(void *)&priv->rtllib->hw_sleep_wq,0);
 	spin_unlock_irqrestore(&priv->ps_lock,flags);
diff --git a/drivers/staging/rtl8192e/rtl_ps.h b/drivers/staging/rtl8192e/rtl_ps.h
index d97a6ed..453df2c 100644
--- a/drivers/staging/rtl8192e/rtl_ps.h
+++ b/drivers/staging/rtl8192e/rtl_ps.h
@@ -33,7 +33,7 @@
 #define INIT_DEFAULT_CHAN	 1
 
 void rtl8192_hw_wakeup(struct net_device *dev);
-void rtl8192_hw_to_sleep(struct net_device *dev, u32 th, u32 tl);
+void rtl8192_hw_to_sleep(struct net_device *dev, u64 time);
 void rtllib_ips_leave_wq(struct net_device *dev);
 void rtllib_ips_leave(struct net_device *dev);
 void IPSLeave_wq (void *data);
diff --git a/drivers/staging/rtl8192e/rtllib.h b/drivers/staging/rtl8192e/rtllib.h
index 2ab1e6c..2a394ee 100644
--- a/drivers/staging/rtl8192e/rtllib.h
+++ b/drivers/staging/rtl8192e/rtllib.h
@@ -993,7 +993,7 @@
  *       any adverse affects. */
 struct rtllib_rx_stats {
 #if 1
-	u32 mac_time[2];
+	u64 mac_time;
 	s8  rssi;
 	u8  signal;
 	u8  noise;
@@ -1679,7 +1679,7 @@
         struct rtllib_tim_parameters tim;
 	u8  dtim_period;
 	u8  dtim_data;
-	u32 last_dtim_sta_time[2];
+	u64 last_dtim_sta_time;
 
         u8 wmm_info;
         struct rtllib_wmm_ac_param wmm_param[4];
@@ -2305,8 +2305,7 @@
 	int ps_timeout;
 	int ps_period;
 	struct tasklet_struct ps_task;
-	u32 ps_th;
-	u32 ps_tl;
+	u64 ps_time;
 	bool polling;
 
 	short raw_tx;
@@ -2498,7 +2497,7 @@
 
 	/* power save mode related */
 	void (*sta_wake_up) (struct net_device *dev);
-	void (*enter_sleep_state) (struct net_device *dev, u32 th, u32 tl);
+	void (*enter_sleep_state) (struct net_device *dev, u64 time);
 	short (*ps_is_queue_empty) (struct net_device *dev);
         int (*handle_beacon) (struct net_device * dev, struct rtllib_beacon * beacon, struct rtllib_network * network);
         int (*handle_assoc_response) (struct net_device * dev, struct rtllib_assoc_response_frame * resp, struct rtllib_network * network);
diff --git a/drivers/staging/rtl8192e/rtllib_rx.c b/drivers/staging/rtl8192e/rtllib_rx.c
index 24ad971..9606bed 100644
--- a/drivers/staging/rtl8192e/rtllib_rx.c
+++ b/drivers/staging/rtl8192e/rtllib_rx.c
@@ -1867,8 +1867,7 @@
                         network->dtim_period = info_element->data[1];
                         if (ieee->state != RTLLIB_LINKED)
                                 break;
-			network->last_dtim_sta_time[0] = jiffies;
-                        network->last_dtim_sta_time[1] = stats->mac_time[1];
+			network->last_dtim_sta_time = jiffies;
 
                         network->dtim_data = RTLLIB_DTIM_VALID;
 
@@ -2466,8 +2465,7 @@
 	dst->atim_window = src->atim_window;
 	dst->dtim_period = src->dtim_period;
 	dst->dtim_data = src->dtim_data;
-	dst->last_dtim_sta_time[0] = src->last_dtim_sta_time[0];
-	dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1];
+	dst->last_dtim_sta_time = src->last_dtim_sta_time;
 	memcpy(&dst->tim, &src->tim, sizeof(struct rtllib_tim_parameters));
 
         dst->bssht.bdSupportHT = src->bssht.bdSupportHT;
diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
index 11433c6..29277d1 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac.c
@@ -2037,7 +2037,7 @@
 
 }
 
-short rtllib_sta_ps_sleep(struct rtllib_device *ieee, u32 *time_h, u32 *time_l)
+static short rtllib_sta_ps_sleep(struct rtllib_device *ieee, u64 *time)
 {
 	int timeout = ieee->ps_timeout;
 	u8 dtim;
@@ -2074,7 +2074,7 @@
 		(ieee->mgmt_queue_tail != ieee->mgmt_queue_head))
 		return 0;
 
-	if (time_l){
+	if (time){
 		if (ieee->bAwakePktSent == true) {
 			pPSC->LPSAwakeIntvl = 1;
 		} else {
@@ -2107,17 +2107,11 @@
 					LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl;
 			}
 
-		*time_l = ieee->current_network.last_dtim_sta_time[0]
+		*time = ieee->current_network.last_dtim_sta_time
 			+ MSECS(ieee->current_network.beacon_interval * LPSAwakeIntvl_tmp);
 	}
 	}
 
-	if (time_h) {
-		*time_h = ieee->current_network.last_dtim_sta_time[1];
-		if (time_l && *time_l < ieee->current_network.last_dtim_sta_time[0])
-			*time_h += 1;
-	}
-
 	return 1;
 
 
@@ -2126,7 +2120,7 @@
 inline void rtllib_sta_ps(struct rtllib_device *ieee)
 {
 
-	u32 th,tl;
+	u64 time;
 	short sleep;
 
 	unsigned long flags,flags2;
@@ -2146,7 +2140,7 @@
 		spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
 	}
 
-	sleep = rtllib_sta_ps_sleep(ieee,&th, &tl);
+	sleep = rtllib_sta_ps_sleep(ieee, &time);
 	/* 2 wake, 1 sleep, 0 do nothing */
 	if (sleep == 0)
 	{
@@ -2154,7 +2148,7 @@
 	}
 	if (sleep == 1){
 		if (ieee->sta_sleep == LPS_IS_SLEEP){
-			ieee->enter_sleep_state(ieee->dev,th,tl);
+			ieee->enter_sleep_state(ieee->dev, time);
 		}
 
 		else if (ieee->sta_sleep == LPS_IS_WAKE){
@@ -2164,8 +2158,7 @@
 				ieee->sta_sleep = LPS_WAIT_NULL_DATA_SEND;
 				ieee->ack_tx_to_ieee = 1;
 				rtllib_sta_ps_send_null_frame(ieee,1);
-				ieee->ps_th = th;
-				ieee->ps_tl = tl;
+				ieee->ps_time = time;
 			}
 			spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2);
 
@@ -2241,7 +2234,7 @@
 		/* Null frame with PS bit set */
 		if (success){
 			ieee->sta_sleep = LPS_IS_SLEEP;
-			ieee->enter_sleep_state(ieee->dev,ieee->ps_th,ieee->ps_tl);
+			ieee->enter_sleep_state(ieee->dev, ieee->ps_time);
 		}
 		/* if the card report not success we can't be sure the AP
 		 * has not RXed so we can't assume the AP believe us awake