blob: 57f66d3ead37f1642f558f8f25a09cef6a95f4e3 [file] [log] [blame]
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001/*
Vinay Adella873dc402018-05-28 12:06:34 +05302 * Copyright (c) 2014-2018 The Linux Foundation. All rights reserved.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08003 *
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08004 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080019/**
Chouhan, Anurag57763182016-03-03 18:57:27 +053020 * DOC: qdf_atomic.h
21 * This file provides OS abstraction for atomic APIs.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080022 */
23
Chouhan, Anurag57763182016-03-03 18:57:27 +053024#ifndef _QDF_ATOMIC_H
25#define _QDF_ATOMIC_H
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080026
Chouhan, Anurag57763182016-03-03 18:57:27 +053027#include <i_qdf_atomic.h>
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080028
29/**
Chouhan, Anurag57763182016-03-03 18:57:27 +053030 * qdf_atomic_t - atomic type of variable
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080031 *
32 * Use this when you want a simple resource counter etc. which is atomic
33 * across multiple CPU's. These maybe slower than usual counters on some
34 * platforms/OS'es, so use them with caution.
35 */
36
Chouhan, Anurag57763182016-03-03 18:57:27 +053037typedef __qdf_atomic_t qdf_atomic_t;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080038
39/**
Chouhan, Anurag57763182016-03-03 18:57:27 +053040 * qdf_atomic_init() - initialize an atomic type variable
41 * @v: A pointer to an opaque atomic variable
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080042 *
43 * Return: None
44 */
Chouhan, Anurag57763182016-03-03 18:57:27 +053045static inline QDF_STATUS qdf_atomic_init(qdf_atomic_t *v)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080046{
Chouhan, Anurag57763182016-03-03 18:57:27 +053047 return __qdf_atomic_init(v);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080048}
49
50/**
Chouhan, Anurag57763182016-03-03 18:57:27 +053051 * qdf_atomic_read() - read the value of an atomic variable
52 * @v: A pointer to an opaque atomic variable
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080053 *
54 * Return: The current value of the variable
55 */
Chouhan, Anurag57763182016-03-03 18:57:27 +053056static inline int32_t qdf_atomic_read(qdf_atomic_t *v)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080057{
Chouhan, Anurag57763182016-03-03 18:57:27 +053058 return __qdf_atomic_read(v);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080059}
60
61/**
Chouhan, Anurag57763182016-03-03 18:57:27 +053062 * qdf_atomic_inc() - increment the value of an atomic variable
63 * @v: A pointer to an opaque atomic variable
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080064 *
65 * Return: None
66 */
Chouhan, Anurag57763182016-03-03 18:57:27 +053067static inline void qdf_atomic_inc(qdf_atomic_t *v)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080068{
Chouhan, Anurag57763182016-03-03 18:57:27 +053069 __qdf_atomic_inc(v);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080070}
71
72/**
Chouhan, Anurag57763182016-03-03 18:57:27 +053073 * qdf_atomic_dec() - decrement the value of an atomic variable
74 * @v: A pointer to an opaque atomic variable
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080075 *
76 * Return: None
77 */
Chouhan, Anurag57763182016-03-03 18:57:27 +053078static inline void qdf_atomic_dec(qdf_atomic_t *v)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080079{
Chouhan, Anurag57763182016-03-03 18:57:27 +053080 __qdf_atomic_dec(v);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080081}
82
83/**
Chouhan, Anurag57763182016-03-03 18:57:27 +053084 * qdf_atomic_add() - add a value to the value of an atomic variable
85 * @i: The amount by which to increase the atomic counter
86 * @v: A pointer to an opaque atomic variable
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080087 *
88 * Return: None
89 */
Chouhan, Anurag57763182016-03-03 18:57:27 +053090static inline void qdf_atomic_add(int i, qdf_atomic_t *v)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080091{
Chouhan, Anurag57763182016-03-03 18:57:27 +053092 __qdf_atomic_add(i, v);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080093}
94
95/**
Chouhan, Anurag57763182016-03-03 18:57:27 +053096 * qdf_atomic_sub() - Subtract a value from an atomic variable
Houston Hoffmane8f53a62015-12-06 20:29:12 -080097 * @i: the amount by which to decrease the atomic counter
98 * @v: a pointer to an opaque atomic variable
99 *
100 * Return: none
101 */
Chouhan, Anurag57763182016-03-03 18:57:27 +0530102static inline void qdf_atomic_sub(int i, qdf_atomic_t *v)
Houston Hoffmane8f53a62015-12-06 20:29:12 -0800103{
Chouhan, Anurag57763182016-03-03 18:57:27 +0530104 __qdf_atomic_sub(i, v);
Houston Hoffmane8f53a62015-12-06 20:29:12 -0800105}
106
107/**
Chouhan, Anurag57763182016-03-03 18:57:27 +0530108 * qdf_atomic_dec_and_test() - decrement an atomic variable and check if the
109 * new value is zero
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800110 * @v: A pointer to an opaque atomic variable
111 *
112 * Return:
Chouhan, Anurag57763182016-03-03 18:57:27 +0530113 * true (non-zero) if the new value is zero,
114 * false (0) if the new value is non-zero
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800115 */
Chouhan, Anurag57763182016-03-03 18:57:27 +0530116static inline int32_t qdf_atomic_dec_and_test(qdf_atomic_t *v)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800117{
Chouhan, Anurag57763182016-03-03 18:57:27 +0530118 return __qdf_atomic_dec_and_test(v);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800119}
120
121/**
Chouhan, Anurag57763182016-03-03 18:57:27 +0530122 * qdf_atomic_set() - set a value to the value of an atomic variable
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800123 * @v: A pointer to an opaque atomic variable
Chouhan, Anurag57763182016-03-03 18:57:27 +0530124 * @i: required value to set
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800125 *
Chouhan, Anurag57763182016-03-03 18:57:27 +0530126 * Atomically sets the value of v to i
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800127 * Return: None
128 */
Chouhan, Anurag57763182016-03-03 18:57:27 +0530129static inline void qdf_atomic_set(qdf_atomic_t *v, int i)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800130{
Chouhan, Anurag57763182016-03-03 18:57:27 +0530131 __qdf_atomic_set(v, i);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800132}
133
134/**
Chouhan, Anurag57763182016-03-03 18:57:27 +0530135 * qdf_atomic_inc_return() - return the incremented value of an atomic variable
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800136 * @v: A pointer to an opaque atomic variable
137 *
138 * Return: The current value of the variable
139 */
Chouhan, Anurag57763182016-03-03 18:57:27 +0530140static inline int32_t qdf_atomic_inc_return(qdf_atomic_t *v)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800141{
Chouhan, Anurag57763182016-03-03 18:57:27 +0530142 return __qdf_atomic_inc_return(v);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800143}
144
Hanumanth Reddy Pothulafd65c6e2017-04-13 16:39:57 +0530145/**
Vinay Adella873dc402018-05-28 12:06:34 +0530146 * qdf_atomic_dec_return() - return the decremented value of an atomic
147 * variable
148 * @v: A pointer to an opaque atomic variable
149 *
150 * Return: The current value of the variable
151 */
152static inline int32_t qdf_atomic_dec_return(qdf_atomic_t *v)
153{
154 return __qdf_atomic_dec_return(v);
155}
156
157/**
Hanumanth Reddy Pothulafd65c6e2017-04-13 16:39:57 +0530158 * qdf_atomic_set_bit - Atomically set a bit in memory
159 * @nr: bit to set
160 * @addr: the address to start counting from
161 *
162 * Return: none
163 */
164static inline void qdf_atomic_set_bit(int nr, volatile unsigned long *addr)
165{
166 __qdf_atomic_set_bit(nr, addr);
167}
168
169/**
170 * qdf_atomic_clear_bit - Atomically clear a bit in memory
171 * @nr: bit to clear
172 * @addr: the address to start counting from
173 *
174 * Return: none
175 */
176static inline void qdf_atomic_clear_bit(int nr, volatile unsigned long *addr)
177{
178 __qdf_atomic_clear_bit(nr, addr);
179}
180
181/**
182 * qdf_atomic_change_bit - Atomically toggle a bit in memory
183 * from addr
184 * @nr: bit to change
185 * @addr: the address to start counting from
186 *
187 * Return: none
188 */
189static inline void qdf_atomic_change_bit(int nr, volatile unsigned long *addr)
190{
191 __qdf_atomic_change_bit(nr, addr);
192}
193
194/**
195 * qdf_atomic_test_and_set_bit - Atomically set a bit and return its old value
196 * @nr: Bit to set
197 * @addr: the address to start counting from
198 *
199 * Return: return nr bit old value
200 */
201static inline int qdf_atomic_test_and_set_bit(int nr,
202 volatile unsigned long *addr)
203{
204 return __qdf_atomic_test_and_set_bit(nr, addr);
205}
206
207/**
208 * qdf_atomic_test_and_clear_bit - Atomically clear a bit and return its old
209 * value
210 * @nr: bit to clear
211 * @addr: the address to start counting from
212 *
213 * Return: return nr bit old value
214 */
215static inline int qdf_atomic_test_and_clear_bit(int nr,
216 volatile unsigned long *addr)
217{
218 return __qdf_atomic_test_and_clear_bit(nr, addr);
219}
220
221/**
222 * qdf_atomic_test_and_change_bit - Atomically toggle a bit and return its old
223 * value
224 * @nr: bit to change
225 * @addr: the address to start counting from
226 *
227 * Return: return nr bit old value
228 */
229static inline int qdf_atomic_test_and_change_bit(int nr,
230 volatile unsigned long *addr)
231{
232 return __qdf_atomic_test_and_change_bit(nr, addr);
233}
234
235/**
236 * qdf_atomic_test_bit - Atomically get the nr-th bit value starting from addr
237 * @nr: bit to get
238 * @addr: the address to start counting from
239 *
240 * Return: return nr bit value
241 */
242static inline int qdf_atomic_test_bit(int nr, volatile unsigned long *addr)
243{
244 return __qdf_atomic_test_bit(nr, addr);
245}
246
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800247#endif