From bed205c14a363fedd8b3a497ef0141588b610d50 Mon Sep 17 00:00:00 2001 From: xyzz <1065521+xyzz@users.noreply.github.com> Date: Mon, 12 Feb 2018 21:33:26 -0500 Subject: [PATCH] Fix timers (#244) This commit adds support for kernel 4.15, which changed the timer interface. Additionally this reverts commit ee9ad6c3483c77be5600075fcf43a41129ffe71f --- hal/OUTSRC/phydm_types.h | 12 ++++++++++-- include/osdep_service.h | 4 ++++ include/osdep_service_linux.h | 37 ++++++++++++++++++++++++++++------- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/hal/OUTSRC/phydm_types.h b/hal/OUTSRC/phydm_types.h index bfd5296..b9384a4 100644 --- a/hal/OUTSRC/phydm_types.h +++ b/hal/OUTSRC/phydm_types.h @@ -193,7 +193,11 @@ typedef long long s8Byte,*ps8Byte; typedef struct rtl8192cd_priv *prtl8192cd_priv; typedef struct stat_info STA_INFO_T,*PSTA_INFO_T; -typedef struct timer_list RT_TIMER, *PRT_TIMER; +#if defined (LINUX_VERSION_CODE) && (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)) + typedef struct legacy_timer_emu RT_TIMER, *PRT_TIMER; +#else + typedef struct timer_list RT_TIMER, *PRT_TIMER; +#endif typedef void * RT_TIMER_CALL_BACK; #ifdef CONFIG_PCI_HCI @@ -262,7 +266,11 @@ typedef s64 s8Byte,*ps8Byte; #define ODM_ENDIAN_TYPE ODM_ENDIAN_BIG #endif -typedef struct timer_list RT_TIMER, *PRT_TIMER; +#if defined (LINUX_VERSION_CODE) && (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)) + typedef struct legacy_timer_emu RT_TIMER, *PRT_TIMER; +#else + typedef struct timer_list RT_TIMER, *PRT_TIMER; +#endif typedef void * RT_TIMER_CALL_BACK; #define STA_INFO_T struct sta_info #define PSTA_INFO_T struct sta_info * diff --git a/include/osdep_service.h b/include/osdep_service.h index 657a7b8..1662e4a 100644 --- a/include/osdep_service.h +++ b/include/osdep_service.h @@ -319,8 +319,12 @@ extern void rtw_init_timer(_timer *ptimer, void *padapter, void *pfunc); __inline static unsigned char _cancel_timer_ex(_timer *ptimer) { #ifdef PLATFORM_LINUX +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)) + return del_timer_sync(&ptimer->t); +#else return del_timer_sync(ptimer); #endif +#endif #ifdef PLATFORM_FREEBSD _cancel_timer(ptimer,0); return 0; diff --git a/include/osdep_service_linux.h b/include/osdep_service_linux.h index 0b85417..b09ab5d 100644 --- a/include/osdep_service_linux.h +++ b/include/osdep_service_linux.h @@ -134,7 +134,15 @@ typedef struct mutex _mutex; #else typedef struct semaphore _mutex; #endif -typedef struct timer_list _timer; +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)) + typedef struct legacy_timer_emu { + struct timer_list t; + void (*function)(unsigned long); + unsigned long data; + } _timer; +#else + typedef struct timer_list _timer; +#endif struct __queue { struct list_head queue; @@ -267,27 +275,42 @@ __inline static void rtw_list_delete(_list *plist) #define RTW_TIMER_HDL_ARGS void *FunctionContext -__inline static void _init_timer(_timer *ptimer,_nic_hdl nic_hdl,void *pfunc,void* cntx) +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)) +static void legacy_timer_emu_func(struct timer_list *t) +{ + struct legacy_timer_emu *lt = from_timer(lt, t, t); + lt->function(lt->data); +} +#endif +__inline static void _init_timer(_timer *ptimer, _nic_hdl nic_hdl, void *pfunc, void *cntx) { //setup_timer(ptimer, pfunc,(u32)cntx); ptimer->function = pfunc; -#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0)) ptimer->data = (unsigned long)cntx; - init_timer(ptimer); +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)) + timer_setup(&ptimer->t, legacy_timer_emu_func, 0); #else - timer_setup(ptimer, pfunc, 0); + init_timer(ptimer); #endif } __inline static void _set_timer(_timer *ptimer,u32 delay_time) { - mod_timer(ptimer , (jiffies+(delay_time*HZ/1000))); +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)) + mod_timer(&ptimer->t, (jiffies+(delay_time*HZ/1000))); +#else + mod_timer(ptimer , (jiffies + (delay_time * HZ / 1000))); +#endif } __inline static void _cancel_timer(_timer *ptimer,u8 *bcancelled) { +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)) + del_timer_sync(&ptimer->t); +#else del_timer_sync(ptimer); - *bcancelled= _TRUE;//TRUE ==1; FALSE==0 +#endif + *bcancelled = 1; }