You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
178 lines
7.5 KiB
178 lines
7.5 KiB
From c86be7b4f9ca4f4c8c916a9c350edbcd0e86a528 Mon Sep 17 00:00:00 2001
|
|
From: Madalin Bucur <madalin.bucur@freescale.com>
|
|
Date: Mon, 18 Apr 2016 16:41:59 +0300
|
|
Subject: [PATCH 30/70] fmd: use kernel api for 64bit division
|
|
|
|
Signed-off-by: Madalin Bucur <madalin.bucur@freescale.com>
|
|
---
|
|
.../freescale/sdk_fman/Peripherals/FM/Pcd/fm_cc.c | 1 +
|
|
.../sdk_fman/Peripherals/FM/Pcd/fm_plcr.c | 5 +++--
|
|
.../freescale/sdk_fman/Peripherals/FM/Pcd/fm_prs.c | 1 +
|
|
.../freescale/sdk_fman/Peripherals/FM/Rtc/fm_rtc.c | 12 ++++++------
|
|
.../freescale/sdk_fman/Peripherals/FM/fm.c | 5 +++--
|
|
.../freescale/sdk_fman/Peripherals/FM/fman.c | 7 +++----
|
|
.../net/ethernet/freescale/sdk_fman/inc/math_ext.h | 1 +
|
|
.../net/ethernet/freescale/sdk_fman/inc/ncsw_ext.h | 2 +-
|
|
8 files changed, 19 insertions(+), 15 deletions(-)
|
|
|
|
--- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_cc.c
|
|
+++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_cc.c
|
|
@@ -36,6 +36,7 @@
|
|
|
|
@Description FM Coarse Classifier implementation
|
|
*//***************************************************************************/
|
|
+#include <linux/math64.h>
|
|
#include "std_ext.h"
|
|
#include "error_ext.h"
|
|
#include "string_ext.h"
|
|
--- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_plcr.c
|
|
+++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_plcr.c
|
|
@@ -36,6 +36,7 @@
|
|
|
|
@Description FM PCD POLICER...
|
|
*//***************************************************************************/
|
|
+#include <linux/math64.h>
|
|
#include "std_ext.h"
|
|
#include "error_ext.h"
|
|
#include "string_ext.h"
|
|
@@ -205,13 +206,13 @@ static void GetInfoRateReg(e_FmPcdPlcrRa
|
|
div = 1000000000; /* nano */
|
|
div *= 10; /* 10 nano */
|
|
}
|
|
- *p_Integer = (tmp<<fppShift)/div;
|
|
+ *p_Integer = div64_u64(tmp<<fppShift, div);
|
|
|
|
/* for calculating the fraction, we will recalculate cir and deduct the integer.
|
|
* For precision, we will multiply by 2^16. we do not divid back, since we write
|
|
* this value as fraction - see spec.
|
|
*/
|
|
- *p_Fraction = (((tmp<<fppShift)<<16) - ((*p_Integer<<16)*div))/div;
|
|
+ *p_Fraction = div64_u64(((tmp<<fppShift)<<16) - ((*p_Integer<<16)*div), div);
|
|
}
|
|
|
|
/* .......... */
|
|
--- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_prs.c
|
|
+++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_prs.c
|
|
@@ -36,6 +36,7 @@
|
|
|
|
@Description FM PCD ...
|
|
*//***************************************************************************/
|
|
+#include <linux/math64.h>
|
|
#include "std_ext.h"
|
|
#include "error_ext.h"
|
|
#include "string_ext.h"
|
|
--- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Rtc/fm_rtc.c
|
|
+++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Rtc/fm_rtc.c
|
|
@@ -38,7 +38,7 @@
|
|
|
|
@Cautions None
|
|
*//***************************************************************************/
|
|
-
|
|
+#include <linux/math64.h>
|
|
#include "error_ext.h"
|
|
#include "debug_ext.h"
|
|
#include "string_ext.h"
|
|
@@ -470,11 +470,11 @@ t_Error FM_RTC_SetAlarm(t_Handle h_FmRtc
|
|
RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
|
|
("Alarm time must be equal or larger than RTC period - %d nanoseconds",
|
|
p_Rtc->clockPeriodNanoSec));
|
|
- if (p_FmRtcAlarmParams->alarmTime % (uint64_t)p_Rtc->clockPeriodNanoSec)
|
|
+ tmpAlarm = p_FmRtcAlarmParams->alarmTime;
|
|
+ if (do_div(tmpAlarm, p_Rtc->clockPeriodNanoSec))
|
|
RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
|
|
("Alarm time must be a multiple of RTC period - %d nanoseconds",
|
|
p_Rtc->clockPeriodNanoSec));
|
|
- tmpAlarm = p_FmRtcAlarmParams->alarmTime/(uint64_t)p_Rtc->clockPeriodNanoSec;
|
|
|
|
if (p_FmRtcAlarmParams->f_AlarmCallback)
|
|
{
|
|
@@ -508,11 +508,11 @@ t_Error FM_RTC_SetPeriodicPulse(t_Handle
|
|
RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
|
|
("Periodic pulse must be equal or larger than RTC period - %d nanoseconds",
|
|
p_Rtc->clockPeriodNanoSec));
|
|
- if (p_FmRtcPeriodicPulseParams->periodicPulsePeriod % (uint64_t)p_Rtc->clockPeriodNanoSec)
|
|
+ tmpFiper = p_FmRtcPeriodicPulseParams->periodicPulsePeriod;
|
|
+ if (do_div(tmpFiper, p_Rtc->clockPeriodNanoSec))
|
|
RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
|
|
("Periodic pulse must be a multiple of RTC period - %d nanoseconds",
|
|
p_Rtc->clockPeriodNanoSec));
|
|
- tmpFiper = p_FmRtcPeriodicPulseParams->periodicPulsePeriod/(uint64_t)p_Rtc->clockPeriodNanoSec;
|
|
if (tmpFiper & 0xffffffff00000000LL)
|
|
RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
|
|
("Periodic pulse/RTC Period must be smaller than 4294967296",
|
|
@@ -628,7 +628,7 @@ t_Error FM_RTC_SetCurrentTime(t_Handle h
|
|
SANITY_CHECK_RETURN_ERROR(p_Rtc, E_INVALID_HANDLE);
|
|
SANITY_CHECK_RETURN_ERROR(!p_Rtc->p_RtcDriverParam, E_INVALID_STATE);
|
|
|
|
- ts = ts/p_Rtc->clockPeriodNanoSec;
|
|
+ do_div(ts, p_Rtc->clockPeriodNanoSec);
|
|
fman_rtc_set_timer(p_Rtc->p_MemMap, (int64_t)ts);
|
|
|
|
return E_OK;
|
|
--- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fm.c
|
|
+++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fm.c
|
|
@@ -43,6 +43,7 @@
|
|
#include "sprint_ext.h"
|
|
#include "debug_ext.h"
|
|
#include "fm_muram_ext.h"
|
|
+#include <linux/math64.h>
|
|
|
|
#include "fm_common.h"
|
|
#include "fm_ipc.h"
|
|
@@ -5087,9 +5088,9 @@ t_Error FM_CtrlMonGetCounters(t_Handle h
|
|
effValue = (uint64_t)
|
|
((uint64_t)GET_UINT32(p_MonRegs->tpc2h) << 32 | GET_UINT32(p_MonRegs->tpc2l));
|
|
|
|
- p_Mon->percentCnt[0] = (uint8_t)((clkCnt - utilValue) * 100 / clkCnt);
|
|
+ p_Mon->percentCnt[0] = (uint8_t)div64_u64((clkCnt - utilValue) * 100, clkCnt);
|
|
if (clkCnt != utilValue)
|
|
- p_Mon->percentCnt[1] = (uint8_t)(((clkCnt - utilValue) - effValue) * 100 / (clkCnt - utilValue));
|
|
+ p_Mon->percentCnt[1] = (uint8_t)div64_u64(((clkCnt - utilValue) - effValue) * 100, clkCnt - utilValue);
|
|
else
|
|
p_Mon->percentCnt[1] = 0;
|
|
|
|
--- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fman.c
|
|
+++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fman.c
|
|
@@ -31,7 +31,7 @@
|
|
*/
|
|
|
|
|
|
-
|
|
+#include <linux/math64.h>
|
|
#include "fsl_fman.h"
|
|
#include "dpaa_integration_ext.h"
|
|
|
|
@@ -186,10 +186,9 @@ void fman_enable_time_stamp(struct fman_
|
|
* we do not div back, since we write this value as a fraction
|
|
* see spec */
|
|
|
|
- frac = (((uint64_t)ts_freq << 16) - ((uint64_t)intgr << 16) * fm_clk_freq)
|
|
- / fm_clk_freq;
|
|
+ frac = ((uint64_t)ts_freq << 16) - ((uint64_t)intgr << 16) * fm_clk_freq;
|
|
/* we check remainder of the division in order to round up if not int */
|
|
- if (((ts_freq << 16) - (intgr << 16)*fm_clk_freq) % fm_clk_freq)
|
|
+ if (do_div(frac, fm_clk_freq))
|
|
frac++;
|
|
|
|
tmp = (intgr << FPM_TS_INT_SHIFT) | (uint16_t)frac;
|
|
--- a/drivers/net/ethernet/freescale/sdk_fman/inc/math_ext.h
|
|
+++ b/drivers/net/ethernet/freescale/sdk_fman/inc/math_ext.h
|
|
@@ -37,6 +37,7 @@
|
|
|
|
#if defined(NCSW_LINUX) && defined(__KERNEL__)
|
|
#include <linux/math.h>
|
|
+#include <linux/math64.h>
|
|
|
|
#elif defined(__MWERKS__)
|
|
#define LOW(x) ( sizeof(x)==8 ? *(1+(int32_t*)&x) : (*(int32_t*)&x))
|
|
--- a/drivers/net/ethernet/freescale/sdk_fman/inc/ncsw_ext.h
|
|
+++ b/drivers/net/ethernet/freescale/sdk_fman/inc/ncsw_ext.h
|
|
@@ -142,7 +142,7 @@ do
|
|
} while (0)
|
|
|
|
/* Ceiling division - not the fastest way, but safer in terms of overflow */
|
|
-#define DIV_CEIL(x,y) (((x)/(y)) + ((((((x)/(y)))*(y)) == (x)) ? 0 : 1))
|
|
+#define DIV_CEIL(x,y) (div64_u64((x),(y)) + (((div64_u64((x),(y))*(y)) == (x)) ? 0 : 1))
|
|
|
|
/* Round up a number to be a multiple of a second number */
|
|
#define ROUND_UP(x,y) ((((x) + (y) - 1) / (y)) * (y))
|
|
|