1af866496SDavid Daney /***********************license start***************
2af866496SDavid Daney  * Author: Cavium Networks
3af866496SDavid Daney  *
4af866496SDavid Daney  * Contact: support@caviumnetworks.com
5af866496SDavid Daney  * This file is part of the OCTEON SDK
6af866496SDavid Daney  *
7af866496SDavid Daney  * Copyright (c) 2003-2008 Cavium Networks
8af866496SDavid Daney  *
9af866496SDavid Daney  * This file is free software; you can redistribute it and/or modify
10af866496SDavid Daney  * it under the terms of the GNU General Public License, Version 2, as
11af866496SDavid Daney  * published by the Free Software Foundation.
12af866496SDavid Daney  *
13af866496SDavid Daney  * This file is distributed in the hope that it will be useful, but
14af866496SDavid Daney  * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15af866496SDavid Daney  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16af866496SDavid Daney  * NONINFRINGEMENT.  See the GNU General Public License for more
17af866496SDavid Daney  * details.
18af866496SDavid Daney  *
19af866496SDavid Daney  * You should have received a copy of the GNU General Public License
20af866496SDavid Daney  * along with this file; if not, write to the Free Software
21af866496SDavid Daney  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22af866496SDavid Daney  * or visit http://www.gnu.org/licenses/.
23af866496SDavid Daney  *
24af866496SDavid Daney  * This file may also be available under a different license from Cavium.
25af866496SDavid Daney  * Contact Cavium Networks for more information
26af866496SDavid Daney  ***********************license end**************************************/
27af866496SDavid Daney 
28af866496SDavid Daney /*
29af866496SDavid Daney  * Interface to the hardware Fetch and Add Unit.
30af866496SDavid Daney  */
31af866496SDavid Daney 
32af866496SDavid Daney #ifndef __CVMX_FAU_H__
33af866496SDavid Daney #define __CVMX_FAU_H__
34af866496SDavid Daney 
35af866496SDavid Daney /*
36af866496SDavid Daney  * Octeon Fetch and Add Unit (FAU)
37af866496SDavid Daney  */
38af866496SDavid Daney 
39af866496SDavid Daney #define CVMX_FAU_LOAD_IO_ADDRESS    cvmx_build_io_address(0x1e, 0)
40af866496SDavid Daney #define CVMX_FAU_BITS_SCRADDR	    63, 56
41af866496SDavid Daney #define CVMX_FAU_BITS_LEN	    55, 48
42af866496SDavid Daney #define CVMX_FAU_BITS_INEVAL	    35, 14
43af866496SDavid Daney #define CVMX_FAU_BITS_TAGWAIT	    13, 13
44af866496SDavid Daney #define CVMX_FAU_BITS_NOADD	    13, 13
45af866496SDavid Daney #define CVMX_FAU_BITS_SIZE	    12, 11
46af866496SDavid Daney #define CVMX_FAU_BITS_REGISTER	    10, 0
47af866496SDavid Daney 
48af866496SDavid Daney typedef enum {
49af866496SDavid Daney 	CVMX_FAU_OP_SIZE_8 = 0,
50af866496SDavid Daney 	CVMX_FAU_OP_SIZE_16 = 1,
51af866496SDavid Daney 	CVMX_FAU_OP_SIZE_32 = 2,
52af866496SDavid Daney 	CVMX_FAU_OP_SIZE_64 = 3
53af866496SDavid Daney } cvmx_fau_op_size_t;
54af866496SDavid Daney 
55af866496SDavid Daney /**
56af866496SDavid Daney  * Tagwait return definition. If a timeout occurs, the error
57af866496SDavid Daney  * bit will be set. Otherwise the value of the register before
58af866496SDavid Daney  * the update will be returned.
59af866496SDavid Daney  */
60af866496SDavid Daney typedef struct {
61af866496SDavid Daney 	uint64_t error:1;
62af866496SDavid Daney 	int64_t value:63;
63af866496SDavid Daney } cvmx_fau_tagwait64_t;
64af866496SDavid Daney 
65af866496SDavid Daney /**
66af866496SDavid Daney  * Tagwait return definition. If a timeout occurs, the error
67af866496SDavid Daney  * bit will be set. Otherwise the value of the register before
68af866496SDavid Daney  * the update will be returned.
69af866496SDavid Daney  */
70af866496SDavid Daney typedef struct {
71af866496SDavid Daney 	uint64_t error:1;
72af866496SDavid Daney 	int32_t value:31;
73af866496SDavid Daney } cvmx_fau_tagwait32_t;
74af866496SDavid Daney 
75af866496SDavid Daney /**
76af866496SDavid Daney  * Tagwait return definition. If a timeout occurs, the error
77af866496SDavid Daney  * bit will be set. Otherwise the value of the register before
78af866496SDavid Daney  * the update will be returned.
79af866496SDavid Daney  */
80af866496SDavid Daney typedef struct {
81af866496SDavid Daney 	uint64_t error:1;
82af866496SDavid Daney 	int16_t value:15;
83af866496SDavid Daney } cvmx_fau_tagwait16_t;
84af866496SDavid Daney 
85af866496SDavid Daney /**
86af866496SDavid Daney  * Tagwait return definition. If a timeout occurs, the error
87af866496SDavid Daney  * bit will be set. Otherwise the value of the register before
88af866496SDavid Daney  * the update will be returned.
89af866496SDavid Daney  */
90af866496SDavid Daney typedef struct {
91af866496SDavid Daney 	uint64_t error:1;
92af866496SDavid Daney 	int8_t value:7;
93af866496SDavid Daney } cvmx_fau_tagwait8_t;
94af866496SDavid Daney 
95af866496SDavid Daney /**
96af866496SDavid Daney  * Asynchronous tagwait return definition. If a timeout occurs,
97af866496SDavid Daney  * the error bit will be set. Otherwise the value of the
98af866496SDavid Daney  * register before the update will be returned.
99af866496SDavid Daney  */
100af866496SDavid Daney typedef union {
101af866496SDavid Daney 	uint64_t u64;
102af866496SDavid Daney 	struct {
103af866496SDavid Daney 		uint64_t invalid:1;
104af866496SDavid Daney 		uint64_t data:63;	/* unpredictable if invalid is set */
105af866496SDavid Daney 	} s;
106af866496SDavid Daney } cvmx_fau_async_tagwait_result_t;
107af866496SDavid Daney 
108f1e770cfSPaul Martin #ifdef __BIG_ENDIAN_BITFIELD
109f1e770cfSPaul Martin #define SWIZZLE_8  0
110f1e770cfSPaul Martin #define SWIZZLE_16 0
111f1e770cfSPaul Martin #define SWIZZLE_32 0
112f1e770cfSPaul Martin #else
113f1e770cfSPaul Martin #define SWIZZLE_8  0x7
114f1e770cfSPaul Martin #define SWIZZLE_16 0x6
115f1e770cfSPaul Martin #define SWIZZLE_32 0x4
116f1e770cfSPaul Martin #endif
117f1e770cfSPaul Martin 
118af866496SDavid Daney /**
119af866496SDavid Daney  * Builds a store I/O address for writing to the FAU
120af866496SDavid Daney  *
121af866496SDavid Daney  * @noadd:  0 = Store value is atomically added to the current value
122af866496SDavid Daney  *		 1 = Store value is atomically written over the current value
123af866496SDavid Daney  * @reg:    FAU atomic register to access. 0 <= reg < 2048.
124af866496SDavid Daney  *		 - Step by 2 for 16 bit access.
125af866496SDavid Daney  *		 - Step by 4 for 32 bit access.
126af866496SDavid Daney  *		 - Step by 8 for 64 bit access.
127af866496SDavid Daney  * Returns Address to store for atomic update
128af866496SDavid Daney  */
__cvmx_fau_store_address(uint64_t noadd,uint64_t reg)129af866496SDavid Daney static inline uint64_t __cvmx_fau_store_address(uint64_t noadd, uint64_t reg)
130af866496SDavid Daney {
131af866496SDavid Daney 	return CVMX_ADD_IO_SEG(CVMX_FAU_LOAD_IO_ADDRESS) |
132af866496SDavid Daney 	       cvmx_build_bits(CVMX_FAU_BITS_NOADD, noadd) |
133af866496SDavid Daney 	       cvmx_build_bits(CVMX_FAU_BITS_REGISTER, reg);
134af866496SDavid Daney }
135af866496SDavid Daney 
136af866496SDavid Daney /**
137af866496SDavid Daney  * Builds a I/O address for accessing the FAU
138af866496SDavid Daney  *
139af866496SDavid Daney  * @tagwait: Should the atomic add wait for the current tag switch
140af866496SDavid Daney  *		  operation to complete.
141af866496SDavid Daney  *		  - 0 = Don't wait
142af866496SDavid Daney  *		  - 1 = Wait for tag switch to complete
143af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
144af866496SDavid Daney  *		  - Step by 2 for 16 bit access.
145af866496SDavid Daney  *		  - Step by 4 for 32 bit access.
146af866496SDavid Daney  *		  - Step by 8 for 64 bit access.
147af866496SDavid Daney  * @value:   Signed value to add.
148af866496SDavid Daney  *		  Note: When performing 32 and 64 bit access, only the low
149af866496SDavid Daney  *		  22 bits are available.
150af866496SDavid Daney  * Returns Address to read from for atomic update
151af866496SDavid Daney  */
__cvmx_fau_atomic_address(uint64_t tagwait,uint64_t reg,int64_t value)152af866496SDavid Daney static inline uint64_t __cvmx_fau_atomic_address(uint64_t tagwait, uint64_t reg,
153af866496SDavid Daney 						 int64_t value)
154af866496SDavid Daney {
155af866496SDavid Daney 	return CVMX_ADD_IO_SEG(CVMX_FAU_LOAD_IO_ADDRESS) |
156af866496SDavid Daney 	       cvmx_build_bits(CVMX_FAU_BITS_INEVAL, value) |
157af866496SDavid Daney 	       cvmx_build_bits(CVMX_FAU_BITS_TAGWAIT, tagwait) |
158af866496SDavid Daney 	       cvmx_build_bits(CVMX_FAU_BITS_REGISTER, reg);
159af866496SDavid Daney }
160af866496SDavid Daney 
161af866496SDavid Daney /**
162af866496SDavid Daney  * Perform an atomic 64 bit add
163af866496SDavid Daney  *
164af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
165af866496SDavid Daney  *		  - Step by 8 for 64 bit access.
166af866496SDavid Daney  * @value:   Signed value to add.
167af866496SDavid Daney  *		  Note: Only the low 22 bits are available.
168af866496SDavid Daney  * Returns Value of the register before the update
169af866496SDavid Daney  */
cvmx_fau_fetch_and_add64(cvmx_fau_reg_64_t reg,int64_t value)170af866496SDavid Daney static inline int64_t cvmx_fau_fetch_and_add64(cvmx_fau_reg_64_t reg,
171af866496SDavid Daney 					       int64_t value)
172af866496SDavid Daney {
173af866496SDavid Daney 	return cvmx_read64_int64(__cvmx_fau_atomic_address(0, reg, value));
174af866496SDavid Daney }
175af866496SDavid Daney 
176af866496SDavid Daney /**
177af866496SDavid Daney  * Perform an atomic 32 bit add
178af866496SDavid Daney  *
179af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
180af866496SDavid Daney  *		  - Step by 4 for 32 bit access.
181af866496SDavid Daney  * @value:   Signed value to add.
182af866496SDavid Daney  *		  Note: Only the low 22 bits are available.
183af866496SDavid Daney  * Returns Value of the register before the update
184af866496SDavid Daney  */
cvmx_fau_fetch_and_add32(cvmx_fau_reg_32_t reg,int32_t value)185af866496SDavid Daney static inline int32_t cvmx_fau_fetch_and_add32(cvmx_fau_reg_32_t reg,
186af866496SDavid Daney 					       int32_t value)
187af866496SDavid Daney {
188f1e770cfSPaul Martin 	reg ^= SWIZZLE_32;
189af866496SDavid Daney 	return cvmx_read64_int32(__cvmx_fau_atomic_address(0, reg, value));
190af866496SDavid Daney }
191af866496SDavid Daney 
192af866496SDavid Daney /**
193af866496SDavid Daney  * Perform an atomic 16 bit add
194af866496SDavid Daney  *
195af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
196af866496SDavid Daney  *		  - Step by 2 for 16 bit access.
197af866496SDavid Daney  * @value:   Signed value to add.
198af866496SDavid Daney  * Returns Value of the register before the update
199af866496SDavid Daney  */
cvmx_fau_fetch_and_add16(cvmx_fau_reg_16_t reg,int16_t value)200af866496SDavid Daney static inline int16_t cvmx_fau_fetch_and_add16(cvmx_fau_reg_16_t reg,
201af866496SDavid Daney 					       int16_t value)
202af866496SDavid Daney {
203f1e770cfSPaul Martin 	reg ^= SWIZZLE_16;
204af866496SDavid Daney 	return cvmx_read64_int16(__cvmx_fau_atomic_address(0, reg, value));
205af866496SDavid Daney }
206af866496SDavid Daney 
207af866496SDavid Daney /**
208af866496SDavid Daney  * Perform an atomic 8 bit add
209af866496SDavid Daney  *
210af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
211af866496SDavid Daney  * @value:   Signed value to add.
212af866496SDavid Daney  * Returns Value of the register before the update
213af866496SDavid Daney  */
cvmx_fau_fetch_and_add8(cvmx_fau_reg_8_t reg,int8_t value)214af866496SDavid Daney static inline int8_t cvmx_fau_fetch_and_add8(cvmx_fau_reg_8_t reg, int8_t value)
215af866496SDavid Daney {
216f1e770cfSPaul Martin 	reg ^= SWIZZLE_8;
217af866496SDavid Daney 	return cvmx_read64_int8(__cvmx_fau_atomic_address(0, reg, value));
218af866496SDavid Daney }
219af866496SDavid Daney 
220af866496SDavid Daney /**
221af866496SDavid Daney  * Perform an atomic 64 bit add after the current tag switch
222af866496SDavid Daney  * completes
223af866496SDavid Daney  *
224af866496SDavid Daney  * @reg:    FAU atomic register to access. 0 <= reg < 2048.
225af866496SDavid Daney  *		 - Step by 8 for 64 bit access.
226af866496SDavid Daney  * @value:  Signed value to add.
227af866496SDavid Daney  *		 Note: Only the low 22 bits are available.
228af866496SDavid Daney  * Returns If a timeout occurs, the error bit will be set. Otherwise
229af866496SDavid Daney  *	   the value of the register before the update will be
230af866496SDavid Daney  *	   returned
231af866496SDavid Daney  */
232af866496SDavid Daney static inline cvmx_fau_tagwait64_t
cvmx_fau_tagwait_fetch_and_add64(cvmx_fau_reg_64_t reg,int64_t value)233af866496SDavid Daney cvmx_fau_tagwait_fetch_and_add64(cvmx_fau_reg_64_t reg, int64_t value)
234af866496SDavid Daney {
235af866496SDavid Daney 	union {
236af866496SDavid Daney 		uint64_t i64;
237af866496SDavid Daney 		cvmx_fau_tagwait64_t t;
238af866496SDavid Daney 	} result;
239af866496SDavid Daney 	result.i64 =
240af866496SDavid Daney 	    cvmx_read64_int64(__cvmx_fau_atomic_address(1, reg, value));
241af866496SDavid Daney 	return result.t;
242af866496SDavid Daney }
243af866496SDavid Daney 
244af866496SDavid Daney /**
245af866496SDavid Daney  * Perform an atomic 32 bit add after the current tag switch
246af866496SDavid Daney  * completes
247af866496SDavid Daney  *
248af866496SDavid Daney  * @reg:    FAU atomic register to access. 0 <= reg < 2048.
249af866496SDavid Daney  *		 - Step by 4 for 32 bit access.
250af866496SDavid Daney  * @value:  Signed value to add.
251af866496SDavid Daney  *		 Note: Only the low 22 bits are available.
252af866496SDavid Daney  * Returns If a timeout occurs, the error bit will be set. Otherwise
253af866496SDavid Daney  *	   the value of the register before the update will be
254af866496SDavid Daney  *	   returned
255af866496SDavid Daney  */
256af866496SDavid Daney static inline cvmx_fau_tagwait32_t
cvmx_fau_tagwait_fetch_and_add32(cvmx_fau_reg_32_t reg,int32_t value)257af866496SDavid Daney cvmx_fau_tagwait_fetch_and_add32(cvmx_fau_reg_32_t reg, int32_t value)
258af866496SDavid Daney {
259af866496SDavid Daney 	union {
260af866496SDavid Daney 		uint64_t i32;
261af866496SDavid Daney 		cvmx_fau_tagwait32_t t;
262af866496SDavid Daney 	} result;
263f1e770cfSPaul Martin 	reg ^= SWIZZLE_32;
264af866496SDavid Daney 	result.i32 =
265af866496SDavid Daney 	    cvmx_read64_int32(__cvmx_fau_atomic_address(1, reg, value));
266af866496SDavid Daney 	return result.t;
267af866496SDavid Daney }
268af866496SDavid Daney 
269af866496SDavid Daney /**
270af866496SDavid Daney  * Perform an atomic 16 bit add after the current tag switch
271af866496SDavid Daney  * completes
272af866496SDavid Daney  *
273af866496SDavid Daney  * @reg:    FAU atomic register to access. 0 <= reg < 2048.
274af866496SDavid Daney  *		 - Step by 2 for 16 bit access.
275af866496SDavid Daney  * @value:  Signed value to add.
276af866496SDavid Daney  * Returns If a timeout occurs, the error bit will be set. Otherwise
277af866496SDavid Daney  *	   the value of the register before the update will be
278af866496SDavid Daney  *	   returned
279af866496SDavid Daney  */
280af866496SDavid Daney static inline cvmx_fau_tagwait16_t
cvmx_fau_tagwait_fetch_and_add16(cvmx_fau_reg_16_t reg,int16_t value)281af866496SDavid Daney cvmx_fau_tagwait_fetch_and_add16(cvmx_fau_reg_16_t reg, int16_t value)
282af866496SDavid Daney {
283af866496SDavid Daney 	union {
284af866496SDavid Daney 		uint64_t i16;
285af866496SDavid Daney 		cvmx_fau_tagwait16_t t;
286af866496SDavid Daney 	} result;
287f1e770cfSPaul Martin 	reg ^= SWIZZLE_16;
288af866496SDavid Daney 	result.i16 =
289af866496SDavid Daney 	    cvmx_read64_int16(__cvmx_fau_atomic_address(1, reg, value));
290af866496SDavid Daney 	return result.t;
291af866496SDavid Daney }
292af866496SDavid Daney 
293af866496SDavid Daney /**
294af866496SDavid Daney  * Perform an atomic 8 bit add after the current tag switch
295af866496SDavid Daney  * completes
296af866496SDavid Daney  *
297af866496SDavid Daney  * @reg:    FAU atomic register to access. 0 <= reg < 2048.
298af866496SDavid Daney  * @value:  Signed value to add.
299af866496SDavid Daney  * Returns If a timeout occurs, the error bit will be set. Otherwise
300af866496SDavid Daney  *	   the value of the register before the update will be
301af866496SDavid Daney  *	   returned
302af866496SDavid Daney  */
303af866496SDavid Daney static inline cvmx_fau_tagwait8_t
cvmx_fau_tagwait_fetch_and_add8(cvmx_fau_reg_8_t reg,int8_t value)304af866496SDavid Daney cvmx_fau_tagwait_fetch_and_add8(cvmx_fau_reg_8_t reg, int8_t value)
305af866496SDavid Daney {
306af866496SDavid Daney 	union {
307af866496SDavid Daney 		uint64_t i8;
308af866496SDavid Daney 		cvmx_fau_tagwait8_t t;
309af866496SDavid Daney 	} result;
310f1e770cfSPaul Martin 	reg ^= SWIZZLE_8;
311af866496SDavid Daney 	result.i8 = cvmx_read64_int8(__cvmx_fau_atomic_address(1, reg, value));
312af866496SDavid Daney 	return result.t;
313af866496SDavid Daney }
314af866496SDavid Daney 
315af866496SDavid Daney /**
316af866496SDavid Daney  * Builds I/O data for async operations
317af866496SDavid Daney  *
318af866496SDavid Daney  * @scraddr: Scratch pad byte address to write to.  Must be 8 byte aligned
319af866496SDavid Daney  * @value:   Signed value to add.
320af866496SDavid Daney  *		  Note: When performing 32 and 64 bit access, only the low
321af866496SDavid Daney  *		  22 bits are available.
322af866496SDavid Daney  * @tagwait: Should the atomic add wait for the current tag switch
323af866496SDavid Daney  *		  operation to complete.
324af866496SDavid Daney  *		  - 0 = Don't wait
325af866496SDavid Daney  *		  - 1 = Wait for tag switch to complete
326af866496SDavid Daney  * @size:    The size of the operation:
327af866496SDavid Daney  *		  - CVMX_FAU_OP_SIZE_8	(0) = 8 bits
328af866496SDavid Daney  *		  - CVMX_FAU_OP_SIZE_16 (1) = 16 bits
329af866496SDavid Daney  *		  - CVMX_FAU_OP_SIZE_32 (2) = 32 bits
330af866496SDavid Daney  *		  - CVMX_FAU_OP_SIZE_64 (3) = 64 bits
331af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
332af866496SDavid Daney  *		  - Step by 2 for 16 bit access.
333af866496SDavid Daney  *		  - Step by 4 for 32 bit access.
334af866496SDavid Daney  *		  - Step by 8 for 64 bit access.
335af866496SDavid Daney  * Returns Data to write using cvmx_send_single
336af866496SDavid Daney  */
__cvmx_fau_iobdma_data(uint64_t scraddr,int64_t value,uint64_t tagwait,cvmx_fau_op_size_t size,uint64_t reg)337af866496SDavid Daney static inline uint64_t __cvmx_fau_iobdma_data(uint64_t scraddr, int64_t value,
338af866496SDavid Daney 					      uint64_t tagwait,
339af866496SDavid Daney 					      cvmx_fau_op_size_t size,
340af866496SDavid Daney 					      uint64_t reg)
341af866496SDavid Daney {
342af866496SDavid Daney 	return CVMX_FAU_LOAD_IO_ADDRESS |
343af866496SDavid Daney 	       cvmx_build_bits(CVMX_FAU_BITS_SCRADDR, scraddr >> 3) |
344af866496SDavid Daney 	       cvmx_build_bits(CVMX_FAU_BITS_LEN, 1) |
345af866496SDavid Daney 	       cvmx_build_bits(CVMX_FAU_BITS_INEVAL, value) |
346af866496SDavid Daney 	       cvmx_build_bits(CVMX_FAU_BITS_TAGWAIT, tagwait) |
347af866496SDavid Daney 	       cvmx_build_bits(CVMX_FAU_BITS_SIZE, size) |
348af866496SDavid Daney 	       cvmx_build_bits(CVMX_FAU_BITS_REGISTER, reg);
349af866496SDavid Daney }
350af866496SDavid Daney 
351af866496SDavid Daney /**
352af866496SDavid Daney  * Perform an async atomic 64 bit add. The old value is
353af866496SDavid Daney  * placed in the scratch memory at byte address scraddr.
354af866496SDavid Daney  *
355af866496SDavid Daney  * @scraddr: Scratch memory byte address to put response in.
356af866496SDavid Daney  *		  Must be 8 byte aligned.
357af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
358af866496SDavid Daney  *		  - Step by 8 for 64 bit access.
359af866496SDavid Daney  * @value:   Signed value to add.
360af866496SDavid Daney  *		  Note: Only the low 22 bits are available.
361af866496SDavid Daney  * Returns Placed in the scratch pad register
362af866496SDavid Daney  */
cvmx_fau_async_fetch_and_add64(uint64_t scraddr,cvmx_fau_reg_64_t reg,int64_t value)363af866496SDavid Daney static inline void cvmx_fau_async_fetch_and_add64(uint64_t scraddr,
364af866496SDavid Daney 						  cvmx_fau_reg_64_t reg,
365af866496SDavid Daney 						  int64_t value)
366af866496SDavid Daney {
367af866496SDavid Daney 	cvmx_send_single(__cvmx_fau_iobdma_data
368af866496SDavid Daney 			 (scraddr, value, 0, CVMX_FAU_OP_SIZE_64, reg));
369af866496SDavid Daney }
370af866496SDavid Daney 
371af866496SDavid Daney /**
372af866496SDavid Daney  * Perform an async atomic 32 bit add. The old value is
373af866496SDavid Daney  * placed in the scratch memory at byte address scraddr.
374af866496SDavid Daney  *
375af866496SDavid Daney  * @scraddr: Scratch memory byte address to put response in.
376af866496SDavid Daney  *		  Must be 8 byte aligned.
377af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
378af866496SDavid Daney  *		  - Step by 4 for 32 bit access.
379af866496SDavid Daney  * @value:   Signed value to add.
380af866496SDavid Daney  *		  Note: Only the low 22 bits are available.
381af866496SDavid Daney  * Returns Placed in the scratch pad register
382af866496SDavid Daney  */
cvmx_fau_async_fetch_and_add32(uint64_t scraddr,cvmx_fau_reg_32_t reg,int32_t value)383af866496SDavid Daney static inline void cvmx_fau_async_fetch_and_add32(uint64_t scraddr,
384af866496SDavid Daney 						  cvmx_fau_reg_32_t reg,
385af866496SDavid Daney 						  int32_t value)
386af866496SDavid Daney {
387af866496SDavid Daney 	cvmx_send_single(__cvmx_fau_iobdma_data
388af866496SDavid Daney 			 (scraddr, value, 0, CVMX_FAU_OP_SIZE_32, reg));
389af866496SDavid Daney }
390af866496SDavid Daney 
391af866496SDavid Daney /**
392af866496SDavid Daney  * Perform an async atomic 16 bit add. The old value is
393af866496SDavid Daney  * placed in the scratch memory at byte address scraddr.
394af866496SDavid Daney  *
395af866496SDavid Daney  * @scraddr: Scratch memory byte address to put response in.
396af866496SDavid Daney  *		  Must be 8 byte aligned.
397af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
398af866496SDavid Daney  *		  - Step by 2 for 16 bit access.
399af866496SDavid Daney  * @value:   Signed value to add.
400af866496SDavid Daney  * Returns Placed in the scratch pad register
401af866496SDavid Daney  */
cvmx_fau_async_fetch_and_add16(uint64_t scraddr,cvmx_fau_reg_16_t reg,int16_t value)402af866496SDavid Daney static inline void cvmx_fau_async_fetch_and_add16(uint64_t scraddr,
403af866496SDavid Daney 						  cvmx_fau_reg_16_t reg,
404af866496SDavid Daney 						  int16_t value)
405af866496SDavid Daney {
406af866496SDavid Daney 	cvmx_send_single(__cvmx_fau_iobdma_data
407af866496SDavid Daney 			 (scraddr, value, 0, CVMX_FAU_OP_SIZE_16, reg));
408af866496SDavid Daney }
409af866496SDavid Daney 
410af866496SDavid Daney /**
411af866496SDavid Daney  * Perform an async atomic 8 bit add. The old value is
412af866496SDavid Daney  * placed in the scratch memory at byte address scraddr.
413af866496SDavid Daney  *
414af866496SDavid Daney  * @scraddr: Scratch memory byte address to put response in.
415af866496SDavid Daney  *		  Must be 8 byte aligned.
416af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
417af866496SDavid Daney  * @value:   Signed value to add.
418af866496SDavid Daney  * Returns Placed in the scratch pad register
419af866496SDavid Daney  */
cvmx_fau_async_fetch_and_add8(uint64_t scraddr,cvmx_fau_reg_8_t reg,int8_t value)420af866496SDavid Daney static inline void cvmx_fau_async_fetch_and_add8(uint64_t scraddr,
421af866496SDavid Daney 						 cvmx_fau_reg_8_t reg,
422af866496SDavid Daney 						 int8_t value)
423af866496SDavid Daney {
424af866496SDavid Daney 	cvmx_send_single(__cvmx_fau_iobdma_data
425af866496SDavid Daney 			 (scraddr, value, 0, CVMX_FAU_OP_SIZE_8, reg));
426af866496SDavid Daney }
427af866496SDavid Daney 
428af866496SDavid Daney /**
429af866496SDavid Daney  * Perform an async atomic 64 bit add after the current tag
430af866496SDavid Daney  * switch completes.
431af866496SDavid Daney  *
432af866496SDavid Daney  * @scraddr: Scratch memory byte address to put response in.  Must be
433af866496SDavid Daney  *	     8 byte aligned.  If a timeout occurs, the error bit (63)
434af866496SDavid Daney  *	     will be set. Otherwise the value of the register before
435af866496SDavid Daney  *	     the update will be returned
436af866496SDavid Daney  *
437af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
438af866496SDavid Daney  *		  - Step by 8 for 64 bit access.
439af866496SDavid Daney  * @value:   Signed value to add.
440af866496SDavid Daney  *		  Note: Only the low 22 bits are available.
441af866496SDavid Daney  * Returns Placed in the scratch pad register
442af866496SDavid Daney  */
cvmx_fau_async_tagwait_fetch_and_add64(uint64_t scraddr,cvmx_fau_reg_64_t reg,int64_t value)443af866496SDavid Daney static inline void cvmx_fau_async_tagwait_fetch_and_add64(uint64_t scraddr,
444af866496SDavid Daney 							  cvmx_fau_reg_64_t reg,
445af866496SDavid Daney 							  int64_t value)
446af866496SDavid Daney {
447af866496SDavid Daney 	cvmx_send_single(__cvmx_fau_iobdma_data
448af866496SDavid Daney 			 (scraddr, value, 1, CVMX_FAU_OP_SIZE_64, reg));
449af866496SDavid Daney }
450af866496SDavid Daney 
451af866496SDavid Daney /**
452af866496SDavid Daney  * Perform an async atomic 32 bit add after the current tag
453af866496SDavid Daney  * switch completes.
454af866496SDavid Daney  *
455af866496SDavid Daney  * @scraddr: Scratch memory byte address to put response in.  Must be
456af866496SDavid Daney  *	     8 byte aligned.  If a timeout occurs, the error bit (63)
457af866496SDavid Daney  *	     will be set. Otherwise the value of the register before
458af866496SDavid Daney  *	     the update will be returned
459af866496SDavid Daney  *
460af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
461af866496SDavid Daney  *		  - Step by 4 for 32 bit access.
462af866496SDavid Daney  * @value:   Signed value to add.
463af866496SDavid Daney  *		  Note: Only the low 22 bits are available.
464af866496SDavid Daney  * Returns Placed in the scratch pad register
465af866496SDavid Daney  */
cvmx_fau_async_tagwait_fetch_and_add32(uint64_t scraddr,cvmx_fau_reg_32_t reg,int32_t value)466af866496SDavid Daney static inline void cvmx_fau_async_tagwait_fetch_and_add32(uint64_t scraddr,
467af866496SDavid Daney 							  cvmx_fau_reg_32_t reg,
468af866496SDavid Daney 							  int32_t value)
469af866496SDavid Daney {
470af866496SDavid Daney 	cvmx_send_single(__cvmx_fau_iobdma_data
471af866496SDavid Daney 			 (scraddr, value, 1, CVMX_FAU_OP_SIZE_32, reg));
472af866496SDavid Daney }
473af866496SDavid Daney 
474af866496SDavid Daney /**
475af866496SDavid Daney  * Perform an async atomic 16 bit add after the current tag
476af866496SDavid Daney  * switch completes.
477af866496SDavid Daney  *
478af866496SDavid Daney  * @scraddr: Scratch memory byte address to put response in.  Must be
479af866496SDavid Daney  *	     8 byte aligned.  If a timeout occurs, the error bit (63)
480af866496SDavid Daney  *	     will be set. Otherwise the value of the register before
481af866496SDavid Daney  *	     the update will be returned
482af866496SDavid Daney  *
483af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
484af866496SDavid Daney  *		  - Step by 2 for 16 bit access.
485af866496SDavid Daney  * @value:   Signed value to add.
486af866496SDavid Daney  *
487af866496SDavid Daney  * Returns Placed in the scratch pad register
488af866496SDavid Daney  */
cvmx_fau_async_tagwait_fetch_and_add16(uint64_t scraddr,cvmx_fau_reg_16_t reg,int16_t value)489af866496SDavid Daney static inline void cvmx_fau_async_tagwait_fetch_and_add16(uint64_t scraddr,
490af866496SDavid Daney 							  cvmx_fau_reg_16_t reg,
491af866496SDavid Daney 							  int16_t value)
492af866496SDavid Daney {
493af866496SDavid Daney 	cvmx_send_single(__cvmx_fau_iobdma_data
494af866496SDavid Daney 			 (scraddr, value, 1, CVMX_FAU_OP_SIZE_16, reg));
495af866496SDavid Daney }
496af866496SDavid Daney 
497af866496SDavid Daney /**
498af866496SDavid Daney  * Perform an async atomic 8 bit add after the current tag
499af866496SDavid Daney  * switch completes.
500af866496SDavid Daney  *
501af866496SDavid Daney  * @scraddr: Scratch memory byte address to put response in.  Must be
502af866496SDavid Daney  *	     8 byte aligned.  If a timeout occurs, the error bit (63)
503af866496SDavid Daney  *	     will be set. Otherwise the value of the register before
504af866496SDavid Daney  *	     the update will be returned
505af866496SDavid Daney  *
506af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
507af866496SDavid Daney  * @value:   Signed value to add.
508af866496SDavid Daney  *
509af866496SDavid Daney  * Returns Placed in the scratch pad register
510af866496SDavid Daney  */
cvmx_fau_async_tagwait_fetch_and_add8(uint64_t scraddr,cvmx_fau_reg_8_t reg,int8_t value)511af866496SDavid Daney static inline void cvmx_fau_async_tagwait_fetch_and_add8(uint64_t scraddr,
512af866496SDavid Daney 							 cvmx_fau_reg_8_t reg,
513af866496SDavid Daney 							 int8_t value)
514af866496SDavid Daney {
515af866496SDavid Daney 	cvmx_send_single(__cvmx_fau_iobdma_data
516af866496SDavid Daney 			 (scraddr, value, 1, CVMX_FAU_OP_SIZE_8, reg));
517af866496SDavid Daney }
518af866496SDavid Daney 
519af866496SDavid Daney /**
520af866496SDavid Daney  * Perform an atomic 64 bit add
521af866496SDavid Daney  *
522af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
523af866496SDavid Daney  *		  - Step by 8 for 64 bit access.
524af866496SDavid Daney  * @value:   Signed value to add.
525af866496SDavid Daney  */
cvmx_fau_atomic_add64(cvmx_fau_reg_64_t reg,int64_t value)526af866496SDavid Daney static inline void cvmx_fau_atomic_add64(cvmx_fau_reg_64_t reg, int64_t value)
527af866496SDavid Daney {
528af866496SDavid Daney 	cvmx_write64_int64(__cvmx_fau_store_address(0, reg), value);
529af866496SDavid Daney }
530af866496SDavid Daney 
531af866496SDavid Daney /**
532af866496SDavid Daney  * Perform an atomic 32 bit add
533af866496SDavid Daney  *
534af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
535af866496SDavid Daney  *		  - Step by 4 for 32 bit access.
536af866496SDavid Daney  * @value:   Signed value to add.
537af866496SDavid Daney  */
cvmx_fau_atomic_add32(cvmx_fau_reg_32_t reg,int32_t value)538af866496SDavid Daney static inline void cvmx_fau_atomic_add32(cvmx_fau_reg_32_t reg, int32_t value)
539af866496SDavid Daney {
540f1e770cfSPaul Martin 	reg ^= SWIZZLE_32;
541af866496SDavid Daney 	cvmx_write64_int32(__cvmx_fau_store_address(0, reg), value);
542af866496SDavid Daney }
543af866496SDavid Daney 
544af866496SDavid Daney /**
545af866496SDavid Daney  * Perform an atomic 16 bit add
546af866496SDavid Daney  *
547af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
548af866496SDavid Daney  *		  - Step by 2 for 16 bit access.
549af866496SDavid Daney  * @value:   Signed value to add.
550af866496SDavid Daney  */
cvmx_fau_atomic_add16(cvmx_fau_reg_16_t reg,int16_t value)551af866496SDavid Daney static inline void cvmx_fau_atomic_add16(cvmx_fau_reg_16_t reg, int16_t value)
552af866496SDavid Daney {
553f1e770cfSPaul Martin 	reg ^= SWIZZLE_16;
554af866496SDavid Daney 	cvmx_write64_int16(__cvmx_fau_store_address(0, reg), value);
555af866496SDavid Daney }
556af866496SDavid Daney 
557af866496SDavid Daney /**
558af866496SDavid Daney  * Perform an atomic 8 bit add
559af866496SDavid Daney  *
560af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
561af866496SDavid Daney  * @value:   Signed value to add.
562af866496SDavid Daney  */
cvmx_fau_atomic_add8(cvmx_fau_reg_8_t reg,int8_t value)563af866496SDavid Daney static inline void cvmx_fau_atomic_add8(cvmx_fau_reg_8_t reg, int8_t value)
564af866496SDavid Daney {
565f1e770cfSPaul Martin 	reg ^= SWIZZLE_8;
566af866496SDavid Daney 	cvmx_write64_int8(__cvmx_fau_store_address(0, reg), value);
567af866496SDavid Daney }
568af866496SDavid Daney 
569af866496SDavid Daney /**
570af866496SDavid Daney  * Perform an atomic 64 bit write
571af866496SDavid Daney  *
572af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
573af866496SDavid Daney  *		  - Step by 8 for 64 bit access.
574af866496SDavid Daney  * @value:   Signed value to write.
575af866496SDavid Daney  */
cvmx_fau_atomic_write64(cvmx_fau_reg_64_t reg,int64_t value)576af866496SDavid Daney static inline void cvmx_fau_atomic_write64(cvmx_fau_reg_64_t reg, int64_t value)
577af866496SDavid Daney {
578af866496SDavid Daney 	cvmx_write64_int64(__cvmx_fau_store_address(1, reg), value);
579af866496SDavid Daney }
580af866496SDavid Daney 
581af866496SDavid Daney /**
582af866496SDavid Daney  * Perform an atomic 32 bit write
583af866496SDavid Daney  *
584af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
585af866496SDavid Daney  *		  - Step by 4 for 32 bit access.
586af866496SDavid Daney  * @value:   Signed value to write.
587af866496SDavid Daney  */
cvmx_fau_atomic_write32(cvmx_fau_reg_32_t reg,int32_t value)588af866496SDavid Daney static inline void cvmx_fau_atomic_write32(cvmx_fau_reg_32_t reg, int32_t value)
589af866496SDavid Daney {
590f1e770cfSPaul Martin 	reg ^= SWIZZLE_32;
591af866496SDavid Daney 	cvmx_write64_int32(__cvmx_fau_store_address(1, reg), value);
592af866496SDavid Daney }
593af866496SDavid Daney 
594af866496SDavid Daney /**
595af866496SDavid Daney  * Perform an atomic 16 bit write
596af866496SDavid Daney  *
597af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
598af866496SDavid Daney  *		  - Step by 2 for 16 bit access.
599af866496SDavid Daney  * @value:   Signed value to write.
600af866496SDavid Daney  */
cvmx_fau_atomic_write16(cvmx_fau_reg_16_t reg,int16_t value)601af866496SDavid Daney static inline void cvmx_fau_atomic_write16(cvmx_fau_reg_16_t reg, int16_t value)
602af866496SDavid Daney {
603f1e770cfSPaul Martin 	reg ^= SWIZZLE_16;
604af866496SDavid Daney 	cvmx_write64_int16(__cvmx_fau_store_address(1, reg), value);
605af866496SDavid Daney }
606af866496SDavid Daney 
607af866496SDavid Daney /**
608af866496SDavid Daney  * Perform an atomic 8 bit write
609af866496SDavid Daney  *
610af866496SDavid Daney  * @reg:     FAU atomic register to access. 0 <= reg < 2048.
611af866496SDavid Daney  * @value:   Signed value to write.
612af866496SDavid Daney  */
cvmx_fau_atomic_write8(cvmx_fau_reg_8_t reg,int8_t value)613af866496SDavid Daney static inline void cvmx_fau_atomic_write8(cvmx_fau_reg_8_t reg, int8_t value)
614af866496SDavid Daney {
615f1e770cfSPaul Martin 	reg ^= SWIZZLE_8;
616af866496SDavid Daney 	cvmx_write64_int8(__cvmx_fau_store_address(1, reg), value);
617af866496SDavid Daney }
618af866496SDavid Daney 
619af866496SDavid Daney #endif /* __CVMX_FAU_H__ */
620