aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/layerscape/patches-4.4/7030-fmd-use-kernel-api-for-64bit-division.patch
blob: cd2283ca77bdf09bb05cf0f86d64bf6c6cde3c16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
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))