1 From c86be7b4f9ca4f4c8c916a9c350edbcd0e86a528 Mon Sep 17 00:00:00 2001
2 From: Madalin Bucur <madalin.bucur@freescale.com>
3 Date: Mon, 18 Apr 2016 16:41:59 +0300
4 Subject: [PATCH 30/70] fmd: use kernel api for 64bit division
6 Signed-off-by: Madalin Bucur <madalin.bucur@freescale.com>
8 .../freescale/sdk_fman/Peripherals/FM/Pcd/fm_cc.c | 1 +
9 .../sdk_fman/Peripherals/FM/Pcd/fm_plcr.c | 5 +++--
10 .../freescale/sdk_fman/Peripherals/FM/Pcd/fm_prs.c | 1 +
11 .../freescale/sdk_fman/Peripherals/FM/Rtc/fm_rtc.c | 12 ++++++------
12 .../freescale/sdk_fman/Peripherals/FM/fm.c | 5 +++--
13 .../freescale/sdk_fman/Peripherals/FM/fman.c | 7 +++----
14 .../net/ethernet/freescale/sdk_fman/inc/math_ext.h | 1 +
15 .../net/ethernet/freescale/sdk_fman/inc/ncsw_ext.h | 2 +-
16 8 files changed, 19 insertions(+), 15 deletions(-)
18 --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_cc.c
19 +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_cc.c
22 @Description FM Coarse Classifier implementation
23 *//***************************************************************************/
24 +#include <linux/math64.h>
26 #include "error_ext.h"
27 #include "string_ext.h"
28 --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_plcr.c
29 +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_plcr.c
32 @Description FM PCD POLICER...
33 *//***************************************************************************/
34 +#include <linux/math64.h>
36 #include "error_ext.h"
37 #include "string_ext.h"
38 @@ -205,13 +206,13 @@ static void GetInfoRateReg(e_FmPcdPlcrRa
39 div = 1000000000; /* nano */
40 div *= 10; /* 10 nano */
42 - *p_Integer = (tmp<<fppShift)/div;
43 + *p_Integer = div64_u64(tmp<<fppShift, div);
45 /* for calculating the fraction, we will recalculate cir and deduct the integer.
46 * For precision, we will multiply by 2^16. we do not divid back, since we write
47 * this value as fraction - see spec.
49 - *p_Fraction = (((tmp<<fppShift)<<16) - ((*p_Integer<<16)*div))/div;
50 + *p_Fraction = div64_u64(((tmp<<fppShift)<<16) - ((*p_Integer<<16)*div), div);
54 --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_prs.c
55 +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_prs.c
58 @Description FM PCD ...
59 *//***************************************************************************/
60 +#include <linux/math64.h>
62 #include "error_ext.h"
63 #include "string_ext.h"
64 --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Rtc/fm_rtc.c
65 +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Rtc/fm_rtc.c
69 *//***************************************************************************/
71 +#include <linux/math64.h>
72 #include "error_ext.h"
73 #include "debug_ext.h"
74 #include "string_ext.h"
75 @@ -470,11 +470,11 @@ t_Error FM_RTC_SetAlarm(t_Handle h_FmRtc
76 RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
77 ("Alarm time must be equal or larger than RTC period - %d nanoseconds",
78 p_Rtc->clockPeriodNanoSec));
79 - if (p_FmRtcAlarmParams->alarmTime % (uint64_t)p_Rtc->clockPeriodNanoSec)
80 + tmpAlarm = p_FmRtcAlarmParams->alarmTime;
81 + if (do_div(tmpAlarm, p_Rtc->clockPeriodNanoSec))
82 RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
83 ("Alarm time must be a multiple of RTC period - %d nanoseconds",
84 p_Rtc->clockPeriodNanoSec));
85 - tmpAlarm = p_FmRtcAlarmParams->alarmTime/(uint64_t)p_Rtc->clockPeriodNanoSec;
87 if (p_FmRtcAlarmParams->f_AlarmCallback)
89 @@ -508,11 +508,11 @@ t_Error FM_RTC_SetPeriodicPulse(t_Handle
90 RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
91 ("Periodic pulse must be equal or larger than RTC period - %d nanoseconds",
92 p_Rtc->clockPeriodNanoSec));
93 - if (p_FmRtcPeriodicPulseParams->periodicPulsePeriod % (uint64_t)p_Rtc->clockPeriodNanoSec)
94 + tmpFiper = p_FmRtcPeriodicPulseParams->periodicPulsePeriod;
95 + if (do_div(tmpFiper, p_Rtc->clockPeriodNanoSec))
96 RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
97 ("Periodic pulse must be a multiple of RTC period - %d nanoseconds",
98 p_Rtc->clockPeriodNanoSec));
99 - tmpFiper = p_FmRtcPeriodicPulseParams->periodicPulsePeriod/(uint64_t)p_Rtc->clockPeriodNanoSec;
100 if (tmpFiper & 0xffffffff00000000LL)
101 RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
102 ("Periodic pulse/RTC Period must be smaller than 4294967296",
103 @@ -628,7 +628,7 @@ t_Error FM_RTC_SetCurrentTime(t_Handle h
104 SANITY_CHECK_RETURN_ERROR(p_Rtc, E_INVALID_HANDLE);
105 SANITY_CHECK_RETURN_ERROR(!p_Rtc->p_RtcDriverParam, E_INVALID_STATE);
107 - ts = ts/p_Rtc->clockPeriodNanoSec;
108 + do_div(ts, p_Rtc->clockPeriodNanoSec);
109 fman_rtc_set_timer(p_Rtc->p_MemMap, (int64_t)ts);
112 --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fm.c
113 +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fm.c
115 #include "sprint_ext.h"
116 #include "debug_ext.h"
117 #include "fm_muram_ext.h"
118 +#include <linux/math64.h>
120 #include "fm_common.h"
122 @@ -5087,9 +5088,9 @@ t_Error FM_CtrlMonGetCounters(t_Handle h
123 effValue = (uint64_t)
124 ((uint64_t)GET_UINT32(p_MonRegs->tpc2h) << 32 | GET_UINT32(p_MonRegs->tpc2l));
126 - p_Mon->percentCnt[0] = (uint8_t)((clkCnt - utilValue) * 100 / clkCnt);
127 + p_Mon->percentCnt[0] = (uint8_t)div64_u64((clkCnt - utilValue) * 100, clkCnt);
128 if (clkCnt != utilValue)
129 - p_Mon->percentCnt[1] = (uint8_t)(((clkCnt - utilValue) - effValue) * 100 / (clkCnt - utilValue));
130 + p_Mon->percentCnt[1] = (uint8_t)div64_u64(((clkCnt - utilValue) - effValue) * 100, clkCnt - utilValue);
132 p_Mon->percentCnt[1] = 0;
134 --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fman.c
135 +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fman.c
141 +#include <linux/math64.h>
142 #include "fsl_fman.h"
143 #include "dpaa_integration_ext.h"
145 @@ -186,10 +186,9 @@ void fman_enable_time_stamp(struct fman_
146 * we do not div back, since we write this value as a fraction
149 - frac = (((uint64_t)ts_freq << 16) - ((uint64_t)intgr << 16) * fm_clk_freq)
151 + frac = ((uint64_t)ts_freq << 16) - ((uint64_t)intgr << 16) * fm_clk_freq;
152 /* we check remainder of the division in order to round up if not int */
153 - if (((ts_freq << 16) - (intgr << 16)*fm_clk_freq) % fm_clk_freq)
154 + if (do_div(frac, fm_clk_freq))
157 tmp = (intgr << FPM_TS_INT_SHIFT) | (uint16_t)frac;
158 --- a/drivers/net/ethernet/freescale/sdk_fman/inc/math_ext.h
159 +++ b/drivers/net/ethernet/freescale/sdk_fman/inc/math_ext.h
162 #if defined(NCSW_LINUX) && defined(__KERNEL__)
163 #include <linux/math.h>
164 +#include <linux/math64.h>
166 #elif defined(__MWERKS__)
167 #define LOW(x) ( sizeof(x)==8 ? *(1+(int32_t*)&x) : (*(int32_t*)&x))
168 --- a/drivers/net/ethernet/freescale/sdk_fman/inc/ncsw_ext.h
169 +++ b/drivers/net/ethernet/freescale/sdk_fman/inc/ncsw_ext.h
170 @@ -142,7 +142,7 @@ do
173 /* Ceiling division - not the fastest way, but safer in terms of overflow */
174 -#define DIV_CEIL(x,y) (((x)/(y)) + ((((((x)/(y)))*(y)) == (x)) ? 0 : 1))
175 +#define DIV_CEIL(x,y) (div64_u64((x),(y)) + (((div64_u64((x),(y))*(y)) == (x)) ? 0 : 1))
177 /* Round up a number to be a multiple of a second number */
178 #define ROUND_UP(x,y) ((((x) + (y) - 1) / (y)) * (y))