7030-fmd-use-kernel-api-for-64bit-division.patch 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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
  5. Signed-off-by: Madalin Bucur <madalin.bucur@freescale.com>
  6. ---
  7. .../freescale/sdk_fman/Peripherals/FM/Pcd/fm_cc.c | 1 +
  8. .../sdk_fman/Peripherals/FM/Pcd/fm_plcr.c | 5 +++--
  9. .../freescale/sdk_fman/Peripherals/FM/Pcd/fm_prs.c | 1 +
  10. .../freescale/sdk_fman/Peripherals/FM/Rtc/fm_rtc.c | 12 ++++++------
  11. .../freescale/sdk_fman/Peripherals/FM/fm.c | 5 +++--
  12. .../freescale/sdk_fman/Peripherals/FM/fman.c | 7 +++----
  13. .../net/ethernet/freescale/sdk_fman/inc/math_ext.h | 1 +
  14. .../net/ethernet/freescale/sdk_fman/inc/ncsw_ext.h | 2 +-
  15. 8 files changed, 19 insertions(+), 15 deletions(-)
  16. --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_cc.c
  17. +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_cc.c
  18. @@ -36,6 +36,7 @@
  19. @Description FM Coarse Classifier implementation
  20. *//***************************************************************************/
  21. +#include <linux/math64.h>
  22. #include "std_ext.h"
  23. #include "error_ext.h"
  24. #include "string_ext.h"
  25. --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_plcr.c
  26. +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_plcr.c
  27. @@ -36,6 +36,7 @@
  28. @Description FM PCD POLICER...
  29. *//***************************************************************************/
  30. +#include <linux/math64.h>
  31. #include "std_ext.h"
  32. #include "error_ext.h"
  33. #include "string_ext.h"
  34. @@ -205,13 +206,13 @@ static void GetInfoRateReg(e_FmPcdPlcrRa
  35. div = 1000000000; /* nano */
  36. div *= 10; /* 10 nano */
  37. }
  38. - *p_Integer = (tmp<<fppShift)/div;
  39. + *p_Integer = div64_u64(tmp<<fppShift, div);
  40. /* for calculating the fraction, we will recalculate cir and deduct the integer.
  41. * For precision, we will multiply by 2^16. we do not divid back, since we write
  42. * this value as fraction - see spec.
  43. */
  44. - *p_Fraction = (((tmp<<fppShift)<<16) - ((*p_Integer<<16)*div))/div;
  45. + *p_Fraction = div64_u64(((tmp<<fppShift)<<16) - ((*p_Integer<<16)*div), div);
  46. }
  47. /* .......... */
  48. --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_prs.c
  49. +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Pcd/fm_prs.c
  50. @@ -36,6 +36,7 @@
  51. @Description FM PCD ...
  52. *//***************************************************************************/
  53. +#include <linux/math64.h>
  54. #include "std_ext.h"
  55. #include "error_ext.h"
  56. #include "string_ext.h"
  57. --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Rtc/fm_rtc.c
  58. +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Rtc/fm_rtc.c
  59. @@ -38,7 +38,7 @@
  60. @Cautions None
  61. *//***************************************************************************/
  62. -
  63. +#include <linux/math64.h>
  64. #include "error_ext.h"
  65. #include "debug_ext.h"
  66. #include "string_ext.h"
  67. @@ -470,11 +470,11 @@ t_Error FM_RTC_SetAlarm(t_Handle h_FmRtc
  68. RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
  69. ("Alarm time must be equal or larger than RTC period - %d nanoseconds",
  70. p_Rtc->clockPeriodNanoSec));
  71. - if (p_FmRtcAlarmParams->alarmTime % (uint64_t)p_Rtc->clockPeriodNanoSec)
  72. + tmpAlarm = p_FmRtcAlarmParams->alarmTime;
  73. + if (do_div(tmpAlarm, p_Rtc->clockPeriodNanoSec))
  74. RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
  75. ("Alarm time must be a multiple of RTC period - %d nanoseconds",
  76. p_Rtc->clockPeriodNanoSec));
  77. - tmpAlarm = p_FmRtcAlarmParams->alarmTime/(uint64_t)p_Rtc->clockPeriodNanoSec;
  78. if (p_FmRtcAlarmParams->f_AlarmCallback)
  79. {
  80. @@ -508,11 +508,11 @@ t_Error FM_RTC_SetPeriodicPulse(t_Handle
  81. RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
  82. ("Periodic pulse must be equal or larger than RTC period - %d nanoseconds",
  83. p_Rtc->clockPeriodNanoSec));
  84. - if (p_FmRtcPeriodicPulseParams->periodicPulsePeriod % (uint64_t)p_Rtc->clockPeriodNanoSec)
  85. + tmpFiper = p_FmRtcPeriodicPulseParams->periodicPulsePeriod;
  86. + if (do_div(tmpFiper, p_Rtc->clockPeriodNanoSec))
  87. RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
  88. ("Periodic pulse must be a multiple of RTC period - %d nanoseconds",
  89. p_Rtc->clockPeriodNanoSec));
  90. - tmpFiper = p_FmRtcPeriodicPulseParams->periodicPulsePeriod/(uint64_t)p_Rtc->clockPeriodNanoSec;
  91. if (tmpFiper & 0xffffffff00000000LL)
  92. RETURN_ERROR(MAJOR, E_INVALID_SELECTION,
  93. ("Periodic pulse/RTC Period must be smaller than 4294967296",
  94. @@ -628,7 +628,7 @@ t_Error FM_RTC_SetCurrentTime(t_Handle h
  95. SANITY_CHECK_RETURN_ERROR(p_Rtc, E_INVALID_HANDLE);
  96. SANITY_CHECK_RETURN_ERROR(!p_Rtc->p_RtcDriverParam, E_INVALID_STATE);
  97. - ts = ts/p_Rtc->clockPeriodNanoSec;
  98. + do_div(ts, p_Rtc->clockPeriodNanoSec);
  99. fman_rtc_set_timer(p_Rtc->p_MemMap, (int64_t)ts);
  100. return E_OK;
  101. --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fm.c
  102. +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fm.c
  103. @@ -43,6 +43,7 @@
  104. #include "sprint_ext.h"
  105. #include "debug_ext.h"
  106. #include "fm_muram_ext.h"
  107. +#include <linux/math64.h>
  108. #include "fm_common.h"
  109. #include "fm_ipc.h"
  110. @@ -5087,9 +5088,9 @@ t_Error FM_CtrlMonGetCounters(t_Handle h
  111. effValue = (uint64_t)
  112. ((uint64_t)GET_UINT32(p_MonRegs->tpc2h) << 32 | GET_UINT32(p_MonRegs->tpc2l));
  113. - p_Mon->percentCnt[0] = (uint8_t)((clkCnt - utilValue) * 100 / clkCnt);
  114. + p_Mon->percentCnt[0] = (uint8_t)div64_u64((clkCnt - utilValue) * 100, clkCnt);
  115. if (clkCnt != utilValue)
  116. - p_Mon->percentCnt[1] = (uint8_t)(((clkCnt - utilValue) - effValue) * 100 / (clkCnt - utilValue));
  117. + p_Mon->percentCnt[1] = (uint8_t)div64_u64(((clkCnt - utilValue) - effValue) * 100, clkCnt - utilValue);
  118. else
  119. p_Mon->percentCnt[1] = 0;
  120. --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fman.c
  121. +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fman.c
  122. @@ -31,7 +31,7 @@
  123. */
  124. -
  125. +#include <linux/math64.h>
  126. #include "fsl_fman.h"
  127. #include "dpaa_integration_ext.h"
  128. @@ -186,10 +186,9 @@ void fman_enable_time_stamp(struct fman_
  129. * we do not div back, since we write this value as a fraction
  130. * see spec */
  131. - frac = (((uint64_t)ts_freq << 16) - ((uint64_t)intgr << 16) * fm_clk_freq)
  132. - / fm_clk_freq;
  133. + frac = ((uint64_t)ts_freq << 16) - ((uint64_t)intgr << 16) * fm_clk_freq;
  134. /* we check remainder of the division in order to round up if not int */
  135. - if (((ts_freq << 16) - (intgr << 16)*fm_clk_freq) % fm_clk_freq)
  136. + if (do_div(frac, fm_clk_freq))
  137. frac++;
  138. tmp = (intgr << FPM_TS_INT_SHIFT) | (uint16_t)frac;
  139. --- a/drivers/net/ethernet/freescale/sdk_fman/inc/math_ext.h
  140. +++ b/drivers/net/ethernet/freescale/sdk_fman/inc/math_ext.h
  141. @@ -37,6 +37,7 @@
  142. #if defined(NCSW_LINUX) && defined(__KERNEL__)
  143. #include <linux/math.h>
  144. +#include <linux/math64.h>
  145. #elif defined(__MWERKS__)
  146. #define LOW(x) ( sizeof(x)==8 ? *(1+(int32_t*)&x) : (*(int32_t*)&x))
  147. --- a/drivers/net/ethernet/freescale/sdk_fman/inc/ncsw_ext.h
  148. +++ b/drivers/net/ethernet/freescale/sdk_fman/inc/ncsw_ext.h
  149. @@ -142,7 +142,7 @@ do
  150. } while (0)
  151. /* Ceiling division - not the fastest way, but safer in terms of overflow */
  152. -#define DIV_CEIL(x,y) (((x)/(y)) + ((((((x)/(y)))*(y)) == (x)) ? 0 : 1))
  153. +#define DIV_CEIL(x,y) (div64_u64((x),(y)) + (((div64_u64((x),(y))*(y)) == (x)) ? 0 : 1))
  154. /* Round up a number to be a multiple of a second number */
  155. #define ROUND_UP(x,y) ((((x) + (y) - 1) / (y)) * (y))