Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2014-2015 The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
| 27 | |
| 28 | #ifndef _I_CDF_SOFTIRQ_TIMER_H |
| 29 | #define _I_CDF_SOFTIRQ_TIMER_H |
| 30 | |
| 31 | #include <linux/version.h> |
| 32 | #include <linux/delay.h> |
| 33 | #include <linux/timer.h> |
| 34 | #include <linux/jiffies.h> |
| 35 | #include <cdf_types.h> |
| 36 | |
| 37 | /* timer data type */ |
| 38 | typedef struct timer_list __cdf_softirq_timer_t; |
| 39 | |
| 40 | /* ugly - but every other OS takes, sanely, a void */ |
| 41 | |
| 42 | typedef void (*cdf_dummy_timer_func_t)(unsigned long arg); |
| 43 | |
| 44 | /** |
| 45 | * __cdf_softirq_timer_init() - initialize a softirq timer |
| 46 | * @hdl: OS handle |
| 47 | * @timer: Pointer to timer object |
| 48 | * @func: Function pointer |
| 49 | * @arg: Arguement |
| 50 | * @type: deferrable or non deferrable timer type |
| 51 | * |
| 52 | * Timer type CDF_TIMER_TYPE_SW means its a deferrable sw timer which will |
| 53 | * not cause CPU wake upon expiry |
| 54 | * Timer type CDF_TIMER_TYPE_WAKE_APPS means its a non-deferrable timer which |
| 55 | * will cause CPU wake up on expiry |
| 56 | * |
| 57 | * Return: none |
| 58 | */ |
| 59 | static inline CDF_STATUS |
| 60 | __cdf_softirq_timer_init(cdf_handle_t hdl, |
| 61 | struct timer_list *timer, |
| 62 | cdf_softirq_timer_func_t func, void *arg, |
| 63 | CDF_TIMER_TYPE type) |
| 64 | { |
| 65 | if (CDF_TIMER_TYPE_SW == type) |
| 66 | init_timer_deferrable(timer); |
| 67 | else |
| 68 | init_timer(timer); |
| 69 | timer->function = (cdf_dummy_timer_func_t) func; |
| 70 | timer->data = (unsigned long)arg; |
| 71 | |
| 72 | return CDF_STATUS_SUCCESS; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * __cdf_softirq_timer_start() - start a cdf softirq timer |
| 77 | * @timer: Pointer to timer object |
| 78 | * @delay: Delay in milli seconds |
| 79 | * |
| 80 | * Return: none |
| 81 | */ |
| 82 | static inline CDF_STATUS |
| 83 | __cdf_softirq_timer_start(struct timer_list *timer, uint32_t delay) |
| 84 | { |
| 85 | timer->expires = jiffies + msecs_to_jiffies(delay); |
| 86 | add_timer(timer); |
| 87 | |
| 88 | return CDF_STATUS_SUCCESS; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * __cdf_softirq_timer_mod() - modify a timer |
| 93 | * @timer: Pointer to timer object |
| 94 | * @delay: Delay in milli seconds |
| 95 | * |
| 96 | * Return: none |
| 97 | */ |
| 98 | static inline CDF_STATUS |
| 99 | __cdf_softirq_timer_mod(struct timer_list *timer, uint32_t delay) |
| 100 | { |
| 101 | mod_timer(timer, jiffies + msecs_to_jiffies(delay)); |
| 102 | |
| 103 | return CDF_STATUS_SUCCESS; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * __cdf_softirq_timer_cancel() - cancel a timer |
| 108 | * @timer: Pointer to timer object |
| 109 | * |
| 110 | * Return: true if timer was cancelled and deactived, |
| 111 | * false if timer was cancelled but already got fired. |
| 112 | */ |
| 113 | static inline bool __cdf_softirq_timer_cancel(struct timer_list *timer) |
| 114 | { |
| 115 | if (likely(del_timer(timer))) |
| 116 | return 1; |
| 117 | else |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * __cdf_softirq_timer_free() - free a cdf timer |
| 123 | * @timer: Pointer to timer object |
| 124 | * |
| 125 | * Return: true if timer was cancelled and deactived, |
| 126 | * false if timer was cancelled but already got fired. |
| 127 | */ |
| 128 | static inline void __cdf_softirq_timer_free(struct timer_list *timer) |
| 129 | { |
| 130 | del_timer_sync(timer); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * __cdf_sostirq_timer_sync_cancel() - Synchronously canel a timer |
| 135 | * @timer: Pointer to timer object |
| 136 | * |
| 137 | * Synchronization Rules: |
| 138 | * 1. caller must make sure timer function will not use |
| 139 | * cdf_softirq_set_timer to add iteself again. |
| 140 | * 2. caller must not hold any lock that timer function |
| 141 | * is likely to hold as well. |
| 142 | * 3. It can't be called from interrupt context. |
| 143 | * |
| 144 | * Return: true if timer was cancelled and deactived, |
| 145 | * false if timer was cancelled but already got fired. |
| 146 | */ |
| 147 | static inline bool __cdf_sostirq_timer_sync_cancel(struct timer_list *timer) |
| 148 | { |
| 149 | return del_timer_sync(timer); |
| 150 | } |
| 151 | |
| 152 | #endif /*_ADF_OS_TIMER_PVT_H*/ |