162306a36Sopenharmony_ci/***********************license start***************
262306a36Sopenharmony_ci * Author: Cavium Networks
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Contact: support@caviumnetworks.com
562306a36Sopenharmony_ci * This file is part of the OCTEON SDK
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Copyright (c) 2003-2008 Cavium Networks
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * This file is free software; you can redistribute it and/or modify
1062306a36Sopenharmony_ci * it under the terms of the GNU General Public License, Version 2, as
1162306a36Sopenharmony_ci * published by the Free Software Foundation.
1262306a36Sopenharmony_ci *
1362306a36Sopenharmony_ci * This file is distributed in the hope that it will be useful, but
1462306a36Sopenharmony_ci * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
1562306a36Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
1662306a36Sopenharmony_ci * NONINFRINGEMENT.  See the GNU General Public License for more
1762306a36Sopenharmony_ci * details.
1862306a36Sopenharmony_ci *
1962306a36Sopenharmony_ci * You should have received a copy of the GNU General Public License
2062306a36Sopenharmony_ci * along with this file; if not, write to the Free Software
2162306a36Sopenharmony_ci * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2262306a36Sopenharmony_ci * or visit http://www.gnu.org/licenses/.
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci * This file may also be available under a different license from Cavium.
2562306a36Sopenharmony_ci * Contact Cavium Networks for more information
2662306a36Sopenharmony_ci ***********************license end**************************************/
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/*
2962306a36Sopenharmony_ci * Interface to the hardware Fetch and Add Unit.
3062306a36Sopenharmony_ci */
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#ifndef __CVMX_FAU_H__
3362306a36Sopenharmony_ci#define __CVMX_FAU_H__
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci/*
3662306a36Sopenharmony_ci * Octeon Fetch and Add Unit (FAU)
3762306a36Sopenharmony_ci */
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci#define CVMX_FAU_LOAD_IO_ADDRESS    cvmx_build_io_address(0x1e, 0)
4062306a36Sopenharmony_ci#define CVMX_FAU_BITS_SCRADDR	    63, 56
4162306a36Sopenharmony_ci#define CVMX_FAU_BITS_LEN	    55, 48
4262306a36Sopenharmony_ci#define CVMX_FAU_BITS_INEVAL	    35, 14
4362306a36Sopenharmony_ci#define CVMX_FAU_BITS_TAGWAIT	    13, 13
4462306a36Sopenharmony_ci#define CVMX_FAU_BITS_NOADD	    13, 13
4562306a36Sopenharmony_ci#define CVMX_FAU_BITS_SIZE	    12, 11
4662306a36Sopenharmony_ci#define CVMX_FAU_BITS_REGISTER	    10, 0
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_citypedef enum {
4962306a36Sopenharmony_ci	CVMX_FAU_OP_SIZE_8 = 0,
5062306a36Sopenharmony_ci	CVMX_FAU_OP_SIZE_16 = 1,
5162306a36Sopenharmony_ci	CVMX_FAU_OP_SIZE_32 = 2,
5262306a36Sopenharmony_ci	CVMX_FAU_OP_SIZE_64 = 3
5362306a36Sopenharmony_ci} cvmx_fau_op_size_t;
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci/**
5662306a36Sopenharmony_ci * Tagwait return definition. If a timeout occurs, the error
5762306a36Sopenharmony_ci * bit will be set. Otherwise the value of the register before
5862306a36Sopenharmony_ci * the update will be returned.
5962306a36Sopenharmony_ci */
6062306a36Sopenharmony_citypedef struct {
6162306a36Sopenharmony_ci	uint64_t error:1;
6262306a36Sopenharmony_ci	int64_t value:63;
6362306a36Sopenharmony_ci} cvmx_fau_tagwait64_t;
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci/**
6662306a36Sopenharmony_ci * Tagwait return definition. If a timeout occurs, the error
6762306a36Sopenharmony_ci * bit will be set. Otherwise the value of the register before
6862306a36Sopenharmony_ci * the update will be returned.
6962306a36Sopenharmony_ci */
7062306a36Sopenharmony_citypedef struct {
7162306a36Sopenharmony_ci	uint64_t error:1;
7262306a36Sopenharmony_ci	int32_t value:31;
7362306a36Sopenharmony_ci} cvmx_fau_tagwait32_t;
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci/**
7662306a36Sopenharmony_ci * Tagwait return definition. If a timeout occurs, the error
7762306a36Sopenharmony_ci * bit will be set. Otherwise the value of the register before
7862306a36Sopenharmony_ci * the update will be returned.
7962306a36Sopenharmony_ci */
8062306a36Sopenharmony_citypedef struct {
8162306a36Sopenharmony_ci	uint64_t error:1;
8262306a36Sopenharmony_ci	int16_t value:15;
8362306a36Sopenharmony_ci} cvmx_fau_tagwait16_t;
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci/**
8662306a36Sopenharmony_ci * Tagwait return definition. If a timeout occurs, the error
8762306a36Sopenharmony_ci * bit will be set. Otherwise the value of the register before
8862306a36Sopenharmony_ci * the update will be returned.
8962306a36Sopenharmony_ci */
9062306a36Sopenharmony_citypedef struct {
9162306a36Sopenharmony_ci	uint64_t error:1;
9262306a36Sopenharmony_ci	int8_t value:7;
9362306a36Sopenharmony_ci} cvmx_fau_tagwait8_t;
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci/**
9662306a36Sopenharmony_ci * Asynchronous tagwait return definition. If a timeout occurs,
9762306a36Sopenharmony_ci * the error bit will be set. Otherwise the value of the
9862306a36Sopenharmony_ci * register before the update will be returned.
9962306a36Sopenharmony_ci */
10062306a36Sopenharmony_citypedef union {
10162306a36Sopenharmony_ci	uint64_t u64;
10262306a36Sopenharmony_ci	struct {
10362306a36Sopenharmony_ci		uint64_t invalid:1;
10462306a36Sopenharmony_ci		uint64_t data:63;	/* unpredictable if invalid is set */
10562306a36Sopenharmony_ci	} s;
10662306a36Sopenharmony_ci} cvmx_fau_async_tagwait_result_t;
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci#ifdef __BIG_ENDIAN_BITFIELD
10962306a36Sopenharmony_ci#define SWIZZLE_8  0
11062306a36Sopenharmony_ci#define SWIZZLE_16 0
11162306a36Sopenharmony_ci#define SWIZZLE_32 0
11262306a36Sopenharmony_ci#else
11362306a36Sopenharmony_ci#define SWIZZLE_8  0x7
11462306a36Sopenharmony_ci#define SWIZZLE_16 0x6
11562306a36Sopenharmony_ci#define SWIZZLE_32 0x4
11662306a36Sopenharmony_ci#endif
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci/**
11962306a36Sopenharmony_ci * Builds a store I/O address for writing to the FAU
12062306a36Sopenharmony_ci *
12162306a36Sopenharmony_ci * @noadd:  0 = Store value is atomically added to the current value
12262306a36Sopenharmony_ci *		 1 = Store value is atomically written over the current value
12362306a36Sopenharmony_ci * @reg:    FAU atomic register to access. 0 <= reg < 2048.
12462306a36Sopenharmony_ci *		 - Step by 2 for 16 bit access.
12562306a36Sopenharmony_ci *		 - Step by 4 for 32 bit access.
12662306a36Sopenharmony_ci *		 - Step by 8 for 64 bit access.
12762306a36Sopenharmony_ci * Returns Address to store for atomic update
12862306a36Sopenharmony_ci */
12962306a36Sopenharmony_cistatic inline uint64_t __cvmx_fau_store_address(uint64_t noadd, uint64_t reg)
13062306a36Sopenharmony_ci{
13162306a36Sopenharmony_ci	return CVMX_ADD_IO_SEG(CVMX_FAU_LOAD_IO_ADDRESS) |
13262306a36Sopenharmony_ci	       cvmx_build_bits(CVMX_FAU_BITS_NOADD, noadd) |
13362306a36Sopenharmony_ci	       cvmx_build_bits(CVMX_FAU_BITS_REGISTER, reg);
13462306a36Sopenharmony_ci}
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci/**
13762306a36Sopenharmony_ci * Builds a I/O address for accessing the FAU
13862306a36Sopenharmony_ci *
13962306a36Sopenharmony_ci * @tagwait: Should the atomic add wait for the current tag switch
14062306a36Sopenharmony_ci *		  operation to complete.
14162306a36Sopenharmony_ci *		  - 0 = Don't wait
14262306a36Sopenharmony_ci *		  - 1 = Wait for tag switch to complete
14362306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
14462306a36Sopenharmony_ci *		  - Step by 2 for 16 bit access.
14562306a36Sopenharmony_ci *		  - Step by 4 for 32 bit access.
14662306a36Sopenharmony_ci *		  - Step by 8 for 64 bit access.
14762306a36Sopenharmony_ci * @value:   Signed value to add.
14862306a36Sopenharmony_ci *		  Note: When performing 32 and 64 bit access, only the low
14962306a36Sopenharmony_ci *		  22 bits are available.
15062306a36Sopenharmony_ci * Returns Address to read from for atomic update
15162306a36Sopenharmony_ci */
15262306a36Sopenharmony_cistatic inline uint64_t __cvmx_fau_atomic_address(uint64_t tagwait, uint64_t reg,
15362306a36Sopenharmony_ci						 int64_t value)
15462306a36Sopenharmony_ci{
15562306a36Sopenharmony_ci	return CVMX_ADD_IO_SEG(CVMX_FAU_LOAD_IO_ADDRESS) |
15662306a36Sopenharmony_ci	       cvmx_build_bits(CVMX_FAU_BITS_INEVAL, value) |
15762306a36Sopenharmony_ci	       cvmx_build_bits(CVMX_FAU_BITS_TAGWAIT, tagwait) |
15862306a36Sopenharmony_ci	       cvmx_build_bits(CVMX_FAU_BITS_REGISTER, reg);
15962306a36Sopenharmony_ci}
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci/**
16262306a36Sopenharmony_ci * Perform an atomic 64 bit add
16362306a36Sopenharmony_ci *
16462306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
16562306a36Sopenharmony_ci *		  - Step by 8 for 64 bit access.
16662306a36Sopenharmony_ci * @value:   Signed value to add.
16762306a36Sopenharmony_ci *		  Note: Only the low 22 bits are available.
16862306a36Sopenharmony_ci * Returns Value of the register before the update
16962306a36Sopenharmony_ci */
17062306a36Sopenharmony_cistatic inline int64_t cvmx_fau_fetch_and_add64(cvmx_fau_reg_64_t reg,
17162306a36Sopenharmony_ci					       int64_t value)
17262306a36Sopenharmony_ci{
17362306a36Sopenharmony_ci	return cvmx_read64_int64(__cvmx_fau_atomic_address(0, reg, value));
17462306a36Sopenharmony_ci}
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ci/**
17762306a36Sopenharmony_ci * Perform an atomic 32 bit add
17862306a36Sopenharmony_ci *
17962306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
18062306a36Sopenharmony_ci *		  - Step by 4 for 32 bit access.
18162306a36Sopenharmony_ci * @value:   Signed value to add.
18262306a36Sopenharmony_ci *		  Note: Only the low 22 bits are available.
18362306a36Sopenharmony_ci * Returns Value of the register before the update
18462306a36Sopenharmony_ci */
18562306a36Sopenharmony_cistatic inline int32_t cvmx_fau_fetch_and_add32(cvmx_fau_reg_32_t reg,
18662306a36Sopenharmony_ci					       int32_t value)
18762306a36Sopenharmony_ci{
18862306a36Sopenharmony_ci	reg ^= SWIZZLE_32;
18962306a36Sopenharmony_ci	return cvmx_read64_int32(__cvmx_fau_atomic_address(0, reg, value));
19062306a36Sopenharmony_ci}
19162306a36Sopenharmony_ci
19262306a36Sopenharmony_ci/**
19362306a36Sopenharmony_ci * Perform an atomic 16 bit add
19462306a36Sopenharmony_ci *
19562306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
19662306a36Sopenharmony_ci *		  - Step by 2 for 16 bit access.
19762306a36Sopenharmony_ci * @value:   Signed value to add.
19862306a36Sopenharmony_ci * Returns Value of the register before the update
19962306a36Sopenharmony_ci */
20062306a36Sopenharmony_cistatic inline int16_t cvmx_fau_fetch_and_add16(cvmx_fau_reg_16_t reg,
20162306a36Sopenharmony_ci					       int16_t value)
20262306a36Sopenharmony_ci{
20362306a36Sopenharmony_ci	reg ^= SWIZZLE_16;
20462306a36Sopenharmony_ci	return cvmx_read64_int16(__cvmx_fau_atomic_address(0, reg, value));
20562306a36Sopenharmony_ci}
20662306a36Sopenharmony_ci
20762306a36Sopenharmony_ci/**
20862306a36Sopenharmony_ci * Perform an atomic 8 bit add
20962306a36Sopenharmony_ci *
21062306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
21162306a36Sopenharmony_ci * @value:   Signed value to add.
21262306a36Sopenharmony_ci * Returns Value of the register before the update
21362306a36Sopenharmony_ci */
21462306a36Sopenharmony_cistatic inline int8_t cvmx_fau_fetch_and_add8(cvmx_fau_reg_8_t reg, int8_t value)
21562306a36Sopenharmony_ci{
21662306a36Sopenharmony_ci	reg ^= SWIZZLE_8;
21762306a36Sopenharmony_ci	return cvmx_read64_int8(__cvmx_fau_atomic_address(0, reg, value));
21862306a36Sopenharmony_ci}
21962306a36Sopenharmony_ci
22062306a36Sopenharmony_ci/**
22162306a36Sopenharmony_ci * Perform an atomic 64 bit add after the current tag switch
22262306a36Sopenharmony_ci * completes
22362306a36Sopenharmony_ci *
22462306a36Sopenharmony_ci * @reg:    FAU atomic register to access. 0 <= reg < 2048.
22562306a36Sopenharmony_ci *		 - Step by 8 for 64 bit access.
22662306a36Sopenharmony_ci * @value:  Signed value to add.
22762306a36Sopenharmony_ci *		 Note: Only the low 22 bits are available.
22862306a36Sopenharmony_ci * Returns If a timeout occurs, the error bit will be set. Otherwise
22962306a36Sopenharmony_ci *	   the value of the register before the update will be
23062306a36Sopenharmony_ci *	   returned
23162306a36Sopenharmony_ci */
23262306a36Sopenharmony_cistatic inline cvmx_fau_tagwait64_t
23362306a36Sopenharmony_cicvmx_fau_tagwait_fetch_and_add64(cvmx_fau_reg_64_t reg, int64_t value)
23462306a36Sopenharmony_ci{
23562306a36Sopenharmony_ci	union {
23662306a36Sopenharmony_ci		uint64_t i64;
23762306a36Sopenharmony_ci		cvmx_fau_tagwait64_t t;
23862306a36Sopenharmony_ci	} result;
23962306a36Sopenharmony_ci	result.i64 =
24062306a36Sopenharmony_ci	    cvmx_read64_int64(__cvmx_fau_atomic_address(1, reg, value));
24162306a36Sopenharmony_ci	return result.t;
24262306a36Sopenharmony_ci}
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ci/**
24562306a36Sopenharmony_ci * Perform an atomic 32 bit add after the current tag switch
24662306a36Sopenharmony_ci * completes
24762306a36Sopenharmony_ci *
24862306a36Sopenharmony_ci * @reg:    FAU atomic register to access. 0 <= reg < 2048.
24962306a36Sopenharmony_ci *		 - Step by 4 for 32 bit access.
25062306a36Sopenharmony_ci * @value:  Signed value to add.
25162306a36Sopenharmony_ci *		 Note: Only the low 22 bits are available.
25262306a36Sopenharmony_ci * Returns If a timeout occurs, the error bit will be set. Otherwise
25362306a36Sopenharmony_ci *	   the value of the register before the update will be
25462306a36Sopenharmony_ci *	   returned
25562306a36Sopenharmony_ci */
25662306a36Sopenharmony_cistatic inline cvmx_fau_tagwait32_t
25762306a36Sopenharmony_cicvmx_fau_tagwait_fetch_and_add32(cvmx_fau_reg_32_t reg, int32_t value)
25862306a36Sopenharmony_ci{
25962306a36Sopenharmony_ci	union {
26062306a36Sopenharmony_ci		uint64_t i32;
26162306a36Sopenharmony_ci		cvmx_fau_tagwait32_t t;
26262306a36Sopenharmony_ci	} result;
26362306a36Sopenharmony_ci	reg ^= SWIZZLE_32;
26462306a36Sopenharmony_ci	result.i32 =
26562306a36Sopenharmony_ci	    cvmx_read64_int32(__cvmx_fau_atomic_address(1, reg, value));
26662306a36Sopenharmony_ci	return result.t;
26762306a36Sopenharmony_ci}
26862306a36Sopenharmony_ci
26962306a36Sopenharmony_ci/**
27062306a36Sopenharmony_ci * Perform an atomic 16 bit add after the current tag switch
27162306a36Sopenharmony_ci * completes
27262306a36Sopenharmony_ci *
27362306a36Sopenharmony_ci * @reg:    FAU atomic register to access. 0 <= reg < 2048.
27462306a36Sopenharmony_ci *		 - Step by 2 for 16 bit access.
27562306a36Sopenharmony_ci * @value:  Signed value to add.
27662306a36Sopenharmony_ci * Returns If a timeout occurs, the error bit will be set. Otherwise
27762306a36Sopenharmony_ci *	   the value of the register before the update will be
27862306a36Sopenharmony_ci *	   returned
27962306a36Sopenharmony_ci */
28062306a36Sopenharmony_cistatic inline cvmx_fau_tagwait16_t
28162306a36Sopenharmony_cicvmx_fau_tagwait_fetch_and_add16(cvmx_fau_reg_16_t reg, int16_t value)
28262306a36Sopenharmony_ci{
28362306a36Sopenharmony_ci	union {
28462306a36Sopenharmony_ci		uint64_t i16;
28562306a36Sopenharmony_ci		cvmx_fau_tagwait16_t t;
28662306a36Sopenharmony_ci	} result;
28762306a36Sopenharmony_ci	reg ^= SWIZZLE_16;
28862306a36Sopenharmony_ci	result.i16 =
28962306a36Sopenharmony_ci	    cvmx_read64_int16(__cvmx_fau_atomic_address(1, reg, value));
29062306a36Sopenharmony_ci	return result.t;
29162306a36Sopenharmony_ci}
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_ci/**
29462306a36Sopenharmony_ci * Perform an atomic 8 bit add after the current tag switch
29562306a36Sopenharmony_ci * completes
29662306a36Sopenharmony_ci *
29762306a36Sopenharmony_ci * @reg:    FAU atomic register to access. 0 <= reg < 2048.
29862306a36Sopenharmony_ci * @value:  Signed value to add.
29962306a36Sopenharmony_ci * Returns If a timeout occurs, the error bit will be set. Otherwise
30062306a36Sopenharmony_ci *	   the value of the register before the update will be
30162306a36Sopenharmony_ci *	   returned
30262306a36Sopenharmony_ci */
30362306a36Sopenharmony_cistatic inline cvmx_fau_tagwait8_t
30462306a36Sopenharmony_cicvmx_fau_tagwait_fetch_and_add8(cvmx_fau_reg_8_t reg, int8_t value)
30562306a36Sopenharmony_ci{
30662306a36Sopenharmony_ci	union {
30762306a36Sopenharmony_ci		uint64_t i8;
30862306a36Sopenharmony_ci		cvmx_fau_tagwait8_t t;
30962306a36Sopenharmony_ci	} result;
31062306a36Sopenharmony_ci	reg ^= SWIZZLE_8;
31162306a36Sopenharmony_ci	result.i8 = cvmx_read64_int8(__cvmx_fau_atomic_address(1, reg, value));
31262306a36Sopenharmony_ci	return result.t;
31362306a36Sopenharmony_ci}
31462306a36Sopenharmony_ci
31562306a36Sopenharmony_ci/**
31662306a36Sopenharmony_ci * Builds I/O data for async operations
31762306a36Sopenharmony_ci *
31862306a36Sopenharmony_ci * @scraddr: Scratch pad byte address to write to.  Must be 8 byte aligned
31962306a36Sopenharmony_ci * @value:   Signed value to add.
32062306a36Sopenharmony_ci *		  Note: When performing 32 and 64 bit access, only the low
32162306a36Sopenharmony_ci *		  22 bits are available.
32262306a36Sopenharmony_ci * @tagwait: Should the atomic add wait for the current tag switch
32362306a36Sopenharmony_ci *		  operation to complete.
32462306a36Sopenharmony_ci *		  - 0 = Don't wait
32562306a36Sopenharmony_ci *		  - 1 = Wait for tag switch to complete
32662306a36Sopenharmony_ci * @size:    The size of the operation:
32762306a36Sopenharmony_ci *		  - CVMX_FAU_OP_SIZE_8	(0) = 8 bits
32862306a36Sopenharmony_ci *		  - CVMX_FAU_OP_SIZE_16 (1) = 16 bits
32962306a36Sopenharmony_ci *		  - CVMX_FAU_OP_SIZE_32 (2) = 32 bits
33062306a36Sopenharmony_ci *		  - CVMX_FAU_OP_SIZE_64 (3) = 64 bits
33162306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
33262306a36Sopenharmony_ci *		  - Step by 2 for 16 bit access.
33362306a36Sopenharmony_ci *		  - Step by 4 for 32 bit access.
33462306a36Sopenharmony_ci *		  - Step by 8 for 64 bit access.
33562306a36Sopenharmony_ci * Returns Data to write using cvmx_send_single
33662306a36Sopenharmony_ci */
33762306a36Sopenharmony_cistatic inline uint64_t __cvmx_fau_iobdma_data(uint64_t scraddr, int64_t value,
33862306a36Sopenharmony_ci					      uint64_t tagwait,
33962306a36Sopenharmony_ci					      cvmx_fau_op_size_t size,
34062306a36Sopenharmony_ci					      uint64_t reg)
34162306a36Sopenharmony_ci{
34262306a36Sopenharmony_ci	return CVMX_FAU_LOAD_IO_ADDRESS |
34362306a36Sopenharmony_ci	       cvmx_build_bits(CVMX_FAU_BITS_SCRADDR, scraddr >> 3) |
34462306a36Sopenharmony_ci	       cvmx_build_bits(CVMX_FAU_BITS_LEN, 1) |
34562306a36Sopenharmony_ci	       cvmx_build_bits(CVMX_FAU_BITS_INEVAL, value) |
34662306a36Sopenharmony_ci	       cvmx_build_bits(CVMX_FAU_BITS_TAGWAIT, tagwait) |
34762306a36Sopenharmony_ci	       cvmx_build_bits(CVMX_FAU_BITS_SIZE, size) |
34862306a36Sopenharmony_ci	       cvmx_build_bits(CVMX_FAU_BITS_REGISTER, reg);
34962306a36Sopenharmony_ci}
35062306a36Sopenharmony_ci
35162306a36Sopenharmony_ci/**
35262306a36Sopenharmony_ci * Perform an async atomic 64 bit add. The old value is
35362306a36Sopenharmony_ci * placed in the scratch memory at byte address scraddr.
35462306a36Sopenharmony_ci *
35562306a36Sopenharmony_ci * @scraddr: Scratch memory byte address to put response in.
35662306a36Sopenharmony_ci *		  Must be 8 byte aligned.
35762306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
35862306a36Sopenharmony_ci *		  - Step by 8 for 64 bit access.
35962306a36Sopenharmony_ci * @value:   Signed value to add.
36062306a36Sopenharmony_ci *		  Note: Only the low 22 bits are available.
36162306a36Sopenharmony_ci * Returns Placed in the scratch pad register
36262306a36Sopenharmony_ci */
36362306a36Sopenharmony_cistatic inline void cvmx_fau_async_fetch_and_add64(uint64_t scraddr,
36462306a36Sopenharmony_ci						  cvmx_fau_reg_64_t reg,
36562306a36Sopenharmony_ci						  int64_t value)
36662306a36Sopenharmony_ci{
36762306a36Sopenharmony_ci	cvmx_send_single(__cvmx_fau_iobdma_data
36862306a36Sopenharmony_ci			 (scraddr, value, 0, CVMX_FAU_OP_SIZE_64, reg));
36962306a36Sopenharmony_ci}
37062306a36Sopenharmony_ci
37162306a36Sopenharmony_ci/**
37262306a36Sopenharmony_ci * Perform an async atomic 32 bit add. The old value is
37362306a36Sopenharmony_ci * placed in the scratch memory at byte address scraddr.
37462306a36Sopenharmony_ci *
37562306a36Sopenharmony_ci * @scraddr: Scratch memory byte address to put response in.
37662306a36Sopenharmony_ci *		  Must be 8 byte aligned.
37762306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
37862306a36Sopenharmony_ci *		  - Step by 4 for 32 bit access.
37962306a36Sopenharmony_ci * @value:   Signed value to add.
38062306a36Sopenharmony_ci *		  Note: Only the low 22 bits are available.
38162306a36Sopenharmony_ci * Returns Placed in the scratch pad register
38262306a36Sopenharmony_ci */
38362306a36Sopenharmony_cistatic inline void cvmx_fau_async_fetch_and_add32(uint64_t scraddr,
38462306a36Sopenharmony_ci						  cvmx_fau_reg_32_t reg,
38562306a36Sopenharmony_ci						  int32_t value)
38662306a36Sopenharmony_ci{
38762306a36Sopenharmony_ci	cvmx_send_single(__cvmx_fau_iobdma_data
38862306a36Sopenharmony_ci			 (scraddr, value, 0, CVMX_FAU_OP_SIZE_32, reg));
38962306a36Sopenharmony_ci}
39062306a36Sopenharmony_ci
39162306a36Sopenharmony_ci/**
39262306a36Sopenharmony_ci * Perform an async atomic 16 bit add. The old value is
39362306a36Sopenharmony_ci * placed in the scratch memory at byte address scraddr.
39462306a36Sopenharmony_ci *
39562306a36Sopenharmony_ci * @scraddr: Scratch memory byte address to put response in.
39662306a36Sopenharmony_ci *		  Must be 8 byte aligned.
39762306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
39862306a36Sopenharmony_ci *		  - Step by 2 for 16 bit access.
39962306a36Sopenharmony_ci * @value:   Signed value to add.
40062306a36Sopenharmony_ci * Returns Placed in the scratch pad register
40162306a36Sopenharmony_ci */
40262306a36Sopenharmony_cistatic inline void cvmx_fau_async_fetch_and_add16(uint64_t scraddr,
40362306a36Sopenharmony_ci						  cvmx_fau_reg_16_t reg,
40462306a36Sopenharmony_ci						  int16_t value)
40562306a36Sopenharmony_ci{
40662306a36Sopenharmony_ci	cvmx_send_single(__cvmx_fau_iobdma_data
40762306a36Sopenharmony_ci			 (scraddr, value, 0, CVMX_FAU_OP_SIZE_16, reg));
40862306a36Sopenharmony_ci}
40962306a36Sopenharmony_ci
41062306a36Sopenharmony_ci/**
41162306a36Sopenharmony_ci * Perform an async atomic 8 bit add. The old value is
41262306a36Sopenharmony_ci * placed in the scratch memory at byte address scraddr.
41362306a36Sopenharmony_ci *
41462306a36Sopenharmony_ci * @scraddr: Scratch memory byte address to put response in.
41562306a36Sopenharmony_ci *		  Must be 8 byte aligned.
41662306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
41762306a36Sopenharmony_ci * @value:   Signed value to add.
41862306a36Sopenharmony_ci * Returns Placed in the scratch pad register
41962306a36Sopenharmony_ci */
42062306a36Sopenharmony_cistatic inline void cvmx_fau_async_fetch_and_add8(uint64_t scraddr,
42162306a36Sopenharmony_ci						 cvmx_fau_reg_8_t reg,
42262306a36Sopenharmony_ci						 int8_t value)
42362306a36Sopenharmony_ci{
42462306a36Sopenharmony_ci	cvmx_send_single(__cvmx_fau_iobdma_data
42562306a36Sopenharmony_ci			 (scraddr, value, 0, CVMX_FAU_OP_SIZE_8, reg));
42662306a36Sopenharmony_ci}
42762306a36Sopenharmony_ci
42862306a36Sopenharmony_ci/**
42962306a36Sopenharmony_ci * Perform an async atomic 64 bit add after the current tag
43062306a36Sopenharmony_ci * switch completes.
43162306a36Sopenharmony_ci *
43262306a36Sopenharmony_ci * @scraddr: Scratch memory byte address to put response in.  Must be
43362306a36Sopenharmony_ci *	     8 byte aligned.  If a timeout occurs, the error bit (63)
43462306a36Sopenharmony_ci *	     will be set. Otherwise the value of the register before
43562306a36Sopenharmony_ci *	     the update will be returned
43662306a36Sopenharmony_ci *
43762306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
43862306a36Sopenharmony_ci *		  - Step by 8 for 64 bit access.
43962306a36Sopenharmony_ci * @value:   Signed value to add.
44062306a36Sopenharmony_ci *		  Note: Only the low 22 bits are available.
44162306a36Sopenharmony_ci * Returns Placed in the scratch pad register
44262306a36Sopenharmony_ci */
44362306a36Sopenharmony_cistatic inline void cvmx_fau_async_tagwait_fetch_and_add64(uint64_t scraddr,
44462306a36Sopenharmony_ci							  cvmx_fau_reg_64_t reg,
44562306a36Sopenharmony_ci							  int64_t value)
44662306a36Sopenharmony_ci{
44762306a36Sopenharmony_ci	cvmx_send_single(__cvmx_fau_iobdma_data
44862306a36Sopenharmony_ci			 (scraddr, value, 1, CVMX_FAU_OP_SIZE_64, reg));
44962306a36Sopenharmony_ci}
45062306a36Sopenharmony_ci
45162306a36Sopenharmony_ci/**
45262306a36Sopenharmony_ci * Perform an async atomic 32 bit add after the current tag
45362306a36Sopenharmony_ci * switch completes.
45462306a36Sopenharmony_ci *
45562306a36Sopenharmony_ci * @scraddr: Scratch memory byte address to put response in.  Must be
45662306a36Sopenharmony_ci *	     8 byte aligned.  If a timeout occurs, the error bit (63)
45762306a36Sopenharmony_ci *	     will be set. Otherwise the value of the register before
45862306a36Sopenharmony_ci *	     the update will be returned
45962306a36Sopenharmony_ci *
46062306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
46162306a36Sopenharmony_ci *		  - Step by 4 for 32 bit access.
46262306a36Sopenharmony_ci * @value:   Signed value to add.
46362306a36Sopenharmony_ci *		  Note: Only the low 22 bits are available.
46462306a36Sopenharmony_ci * Returns Placed in the scratch pad register
46562306a36Sopenharmony_ci */
46662306a36Sopenharmony_cistatic inline void cvmx_fau_async_tagwait_fetch_and_add32(uint64_t scraddr,
46762306a36Sopenharmony_ci							  cvmx_fau_reg_32_t reg,
46862306a36Sopenharmony_ci							  int32_t value)
46962306a36Sopenharmony_ci{
47062306a36Sopenharmony_ci	cvmx_send_single(__cvmx_fau_iobdma_data
47162306a36Sopenharmony_ci			 (scraddr, value, 1, CVMX_FAU_OP_SIZE_32, reg));
47262306a36Sopenharmony_ci}
47362306a36Sopenharmony_ci
47462306a36Sopenharmony_ci/**
47562306a36Sopenharmony_ci * Perform an async atomic 16 bit add after the current tag
47662306a36Sopenharmony_ci * switch completes.
47762306a36Sopenharmony_ci *
47862306a36Sopenharmony_ci * @scraddr: Scratch memory byte address to put response in.  Must be
47962306a36Sopenharmony_ci *	     8 byte aligned.  If a timeout occurs, the error bit (63)
48062306a36Sopenharmony_ci *	     will be set. Otherwise the value of the register before
48162306a36Sopenharmony_ci *	     the update will be returned
48262306a36Sopenharmony_ci *
48362306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
48462306a36Sopenharmony_ci *		  - Step by 2 for 16 bit access.
48562306a36Sopenharmony_ci * @value:   Signed value to add.
48662306a36Sopenharmony_ci *
48762306a36Sopenharmony_ci * Returns Placed in the scratch pad register
48862306a36Sopenharmony_ci */
48962306a36Sopenharmony_cistatic inline void cvmx_fau_async_tagwait_fetch_and_add16(uint64_t scraddr,
49062306a36Sopenharmony_ci							  cvmx_fau_reg_16_t reg,
49162306a36Sopenharmony_ci							  int16_t value)
49262306a36Sopenharmony_ci{
49362306a36Sopenharmony_ci	cvmx_send_single(__cvmx_fau_iobdma_data
49462306a36Sopenharmony_ci			 (scraddr, value, 1, CVMX_FAU_OP_SIZE_16, reg));
49562306a36Sopenharmony_ci}
49662306a36Sopenharmony_ci
49762306a36Sopenharmony_ci/**
49862306a36Sopenharmony_ci * Perform an async atomic 8 bit add after the current tag
49962306a36Sopenharmony_ci * switch completes.
50062306a36Sopenharmony_ci *
50162306a36Sopenharmony_ci * @scraddr: Scratch memory byte address to put response in.  Must be
50262306a36Sopenharmony_ci *	     8 byte aligned.  If a timeout occurs, the error bit (63)
50362306a36Sopenharmony_ci *	     will be set. Otherwise the value of the register before
50462306a36Sopenharmony_ci *	     the update will be returned
50562306a36Sopenharmony_ci *
50662306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
50762306a36Sopenharmony_ci * @value:   Signed value to add.
50862306a36Sopenharmony_ci *
50962306a36Sopenharmony_ci * Returns Placed in the scratch pad register
51062306a36Sopenharmony_ci */
51162306a36Sopenharmony_cistatic inline void cvmx_fau_async_tagwait_fetch_and_add8(uint64_t scraddr,
51262306a36Sopenharmony_ci							 cvmx_fau_reg_8_t reg,
51362306a36Sopenharmony_ci							 int8_t value)
51462306a36Sopenharmony_ci{
51562306a36Sopenharmony_ci	cvmx_send_single(__cvmx_fau_iobdma_data
51662306a36Sopenharmony_ci			 (scraddr, value, 1, CVMX_FAU_OP_SIZE_8, reg));
51762306a36Sopenharmony_ci}
51862306a36Sopenharmony_ci
51962306a36Sopenharmony_ci/**
52062306a36Sopenharmony_ci * Perform an atomic 64 bit add
52162306a36Sopenharmony_ci *
52262306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
52362306a36Sopenharmony_ci *		  - Step by 8 for 64 bit access.
52462306a36Sopenharmony_ci * @value:   Signed value to add.
52562306a36Sopenharmony_ci */
52662306a36Sopenharmony_cistatic inline void cvmx_fau_atomic_add64(cvmx_fau_reg_64_t reg, int64_t value)
52762306a36Sopenharmony_ci{
52862306a36Sopenharmony_ci	cvmx_write64_int64(__cvmx_fau_store_address(0, reg), value);
52962306a36Sopenharmony_ci}
53062306a36Sopenharmony_ci
53162306a36Sopenharmony_ci/**
53262306a36Sopenharmony_ci * Perform an atomic 32 bit add
53362306a36Sopenharmony_ci *
53462306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
53562306a36Sopenharmony_ci *		  - Step by 4 for 32 bit access.
53662306a36Sopenharmony_ci * @value:   Signed value to add.
53762306a36Sopenharmony_ci */
53862306a36Sopenharmony_cistatic inline void cvmx_fau_atomic_add32(cvmx_fau_reg_32_t reg, int32_t value)
53962306a36Sopenharmony_ci{
54062306a36Sopenharmony_ci	reg ^= SWIZZLE_32;
54162306a36Sopenharmony_ci	cvmx_write64_int32(__cvmx_fau_store_address(0, reg), value);
54262306a36Sopenharmony_ci}
54362306a36Sopenharmony_ci
54462306a36Sopenharmony_ci/**
54562306a36Sopenharmony_ci * Perform an atomic 16 bit add
54662306a36Sopenharmony_ci *
54762306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
54862306a36Sopenharmony_ci *		  - Step by 2 for 16 bit access.
54962306a36Sopenharmony_ci * @value:   Signed value to add.
55062306a36Sopenharmony_ci */
55162306a36Sopenharmony_cistatic inline void cvmx_fau_atomic_add16(cvmx_fau_reg_16_t reg, int16_t value)
55262306a36Sopenharmony_ci{
55362306a36Sopenharmony_ci	reg ^= SWIZZLE_16;
55462306a36Sopenharmony_ci	cvmx_write64_int16(__cvmx_fau_store_address(0, reg), value);
55562306a36Sopenharmony_ci}
55662306a36Sopenharmony_ci
55762306a36Sopenharmony_ci/**
55862306a36Sopenharmony_ci * Perform an atomic 8 bit add
55962306a36Sopenharmony_ci *
56062306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
56162306a36Sopenharmony_ci * @value:   Signed value to add.
56262306a36Sopenharmony_ci */
56362306a36Sopenharmony_cistatic inline void cvmx_fau_atomic_add8(cvmx_fau_reg_8_t reg, int8_t value)
56462306a36Sopenharmony_ci{
56562306a36Sopenharmony_ci	reg ^= SWIZZLE_8;
56662306a36Sopenharmony_ci	cvmx_write64_int8(__cvmx_fau_store_address(0, reg), value);
56762306a36Sopenharmony_ci}
56862306a36Sopenharmony_ci
56962306a36Sopenharmony_ci/**
57062306a36Sopenharmony_ci * Perform an atomic 64 bit write
57162306a36Sopenharmony_ci *
57262306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
57362306a36Sopenharmony_ci *		  - Step by 8 for 64 bit access.
57462306a36Sopenharmony_ci * @value:   Signed value to write.
57562306a36Sopenharmony_ci */
57662306a36Sopenharmony_cistatic inline void cvmx_fau_atomic_write64(cvmx_fau_reg_64_t reg, int64_t value)
57762306a36Sopenharmony_ci{
57862306a36Sopenharmony_ci	cvmx_write64_int64(__cvmx_fau_store_address(1, reg), value);
57962306a36Sopenharmony_ci}
58062306a36Sopenharmony_ci
58162306a36Sopenharmony_ci/**
58262306a36Sopenharmony_ci * Perform an atomic 32 bit write
58362306a36Sopenharmony_ci *
58462306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
58562306a36Sopenharmony_ci *		  - Step by 4 for 32 bit access.
58662306a36Sopenharmony_ci * @value:   Signed value to write.
58762306a36Sopenharmony_ci */
58862306a36Sopenharmony_cistatic inline void cvmx_fau_atomic_write32(cvmx_fau_reg_32_t reg, int32_t value)
58962306a36Sopenharmony_ci{
59062306a36Sopenharmony_ci	reg ^= SWIZZLE_32;
59162306a36Sopenharmony_ci	cvmx_write64_int32(__cvmx_fau_store_address(1, reg), value);
59262306a36Sopenharmony_ci}
59362306a36Sopenharmony_ci
59462306a36Sopenharmony_ci/**
59562306a36Sopenharmony_ci * Perform an atomic 16 bit write
59662306a36Sopenharmony_ci *
59762306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
59862306a36Sopenharmony_ci *		  - Step by 2 for 16 bit access.
59962306a36Sopenharmony_ci * @value:   Signed value to write.
60062306a36Sopenharmony_ci */
60162306a36Sopenharmony_cistatic inline void cvmx_fau_atomic_write16(cvmx_fau_reg_16_t reg, int16_t value)
60262306a36Sopenharmony_ci{
60362306a36Sopenharmony_ci	reg ^= SWIZZLE_16;
60462306a36Sopenharmony_ci	cvmx_write64_int16(__cvmx_fau_store_address(1, reg), value);
60562306a36Sopenharmony_ci}
60662306a36Sopenharmony_ci
60762306a36Sopenharmony_ci/**
60862306a36Sopenharmony_ci * Perform an atomic 8 bit write
60962306a36Sopenharmony_ci *
61062306a36Sopenharmony_ci * @reg:     FAU atomic register to access. 0 <= reg < 2048.
61162306a36Sopenharmony_ci * @value:   Signed value to write.
61262306a36Sopenharmony_ci */
61362306a36Sopenharmony_cistatic inline void cvmx_fau_atomic_write8(cvmx_fau_reg_8_t reg, int8_t value)
61462306a36Sopenharmony_ci{
61562306a36Sopenharmony_ci	reg ^= SWIZZLE_8;
61662306a36Sopenharmony_ci	cvmx_write64_int8(__cvmx_fau_store_address(1, reg), value);
61762306a36Sopenharmony_ci}
61862306a36Sopenharmony_ci
61962306a36Sopenharmony_ci#endif /* __CVMX_FAU_H__ */
620