]> CyberLeo.Net >> Repos - FreeBSD/releng/8.2.git/blob - sys/mips/cavium/dev/rgmii/octeon_fau.h
Copy stable/8 to releng/8.2 in preparation for FreeBSD-8.2 release.
[FreeBSD/releng/8.2.git] / sys / mips / cavium / dev / rgmii / octeon_fau.h
1 /***********************license start***************
2  *  Copyright (c) 2003-2008 Cavium Networks (support@cavium.com). All rights
3  *  reserved.
4  *
5  *
6  *  Redistribution and use in source and binary forms, with or without
7  *  modification, are permitted provided that the following conditions are
8  *  met:
9  *
10  *      * Redistributions of source code must retain the above copyright
11  *        notice, this list of conditions and the following disclaimer.
12  *
13  *      * Redistributions in binary form must reproduce the above
14  *        copyright notice, this list of conditions and the following
15  *        disclaimer in the documentation and/or other materials provided
16  *        with the distribution.
17  *
18  *      * Neither the name of Cavium Networks nor the names of
19  *        its contributors may be used to endorse or promote products
20  *        derived from this software without specific prior written
21  *        permission.
22  *
23  *  TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
24  *  AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS
25  *  OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH
26  *  RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
27  *  REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
28  *  DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
29  *  OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
30  *  PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET
31  *  POSSESSION OR CORRESPONDENCE TO DESCRIPTION.  THE ENTIRE RISK ARISING OUT
32  *  OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
33  *
34  *
35  *  For any questions regarding licensing please contact marketing@caviumnetworks.com
36  *
37  ***********************license end**************************************/
38
39 /* $FreeBSD$ */
40
41 /*------------------------------------------------------------------
42  * octeon_fau.h        Fetch & Add Unit
43  *
44  *------------------------------------------------------------------
45  */
46
47
48 #ifndef ___OCTEON_FAU__H___
49 #define ___OCTEON_FAU__H___
50
51
52
53
54 typedef enum {
55    OCTEON_FAU_OP_SIZE_8  = 0,
56    OCTEON_FAU_OP_SIZE_16 = 1,
57    OCTEON_FAU_OP_SIZE_32 = 2,
58    OCTEON_FAU_OP_SIZE_64 = 3
59 } octeon_fau_op_size_t;
60
61
62
63 #define OCTEON_FAU_LOAD_IO_ADDRESS    octeon_build_io_address(0x1e, 0)
64 #define OCTEON_FAU_BITS_SCRADDR       63,56
65 #define OCTEON_FAU_BITS_LEN           55,48
66 #define OCTEON_FAU_BITS_INEVAL        35,14
67 #define OCTEON_FAU_BITS_TAGWAIT       13,13
68 #define OCTEON_FAU_BITS_NOADD         13,13
69 #define OCTEON_FAU_BITS_SIZE          12,11
70 #define OCTEON_FAU_BITS_REGISTER      10,0
71
72 #define OCTEON_FAU_REG_64_ADDR(x) ((x <<3) + OCTEON_FAU_REG_64_START)
73 typedef enum
74 {
75     OCTEON_FAU_REG_64_START             = 0, 
76     OCTEON_FAU_REG_OQ_ADDR_INDEX        = OCTEON_FAU_REG_64_ADDR(0),
77     OCTEON_FAU_REG_OQ_ADDR_END          = OCTEON_FAU_REG_64_ADDR(31),
78     OCTEON_FAU_REG_64_END               = OCTEON_FAU_REG_64_ADDR(39),
79 } octeon_fau_reg_64_t;
80
81 #define OCTEON_FAU_REG_32_ADDR(x) ((x <<2) + OCTEON_FAU_REG_32_START)
82 typedef enum
83 {
84     OCTEON_FAU_REG_32_START          = OCTEON_FAU_REG_64_END,
85     OCTEON_FAU_REG_32_END            = OCTEON_FAU_REG_32_ADDR(0),
86 } octeon_fau_reg_32_t;
87
88
89
90 /*
91  * octeon_fau_atomic_address
92  *
93  * Builds a I/O address for accessing the FAU
94  *
95  * @param tagwait Should the atomic add wait for the current tag switch
96  *                operation to complete.
97  *                - 0 = Don't wait
98  *                - 1 = Wait for tag switch to complete
99  * @param reg     FAU atomic register to access. 0 <= reg < 4096.
100  *                - Step by 2 for 16 bit access.
101  *                - Step by 4 for 32 bit access.
102  *                - Step by 8 for 64 bit access.
103  * @param value   Signed value to add.
104  *                Note: When performing 32 and 64 bit access, only the low
105  *                22 bits are available.
106  * @return Address to read from for atomic update
107  */
108 static inline uint64_t octeon_fau_atomic_address (uint64_t tagwait, uint64_t reg,
109                                                int64_t value)
110 {
111     return (OCTEON_ADD_IO_SEG(OCTEON_FAU_LOAD_IO_ADDRESS) |
112             octeon_build_bits(OCTEON_FAU_BITS_INEVAL, value) |
113             octeon_build_bits(OCTEON_FAU_BITS_TAGWAIT, tagwait) |
114             octeon_build_bits(OCTEON_FAU_BITS_REGISTER, reg));
115 }
116
117
118 /*
119  * octeon_fau_store_address
120  *
121  * Builds a store I/O address for writing to the FAU
122  *
123  * noadd  0 = Store value is atomically added to the current value
124  *               1 = Store value is atomically written over the current value
125  * reg    FAU atomic register to access. 0 <= reg < 4096.
126  *               - Step by 2 for 16 bit access.
127  *               - Step by 4 for 32 bit access.
128  *               - Step by 8 for 64 bit access.
129  * Returns Address to store for atomic update
130  */
131 static inline uint64_t octeon_fau_store_address (uint64_t noadd, uint64_t reg)
132 {
133     return (OCTEON_ADD_IO_SEG(OCTEON_FAU_LOAD_IO_ADDRESS) |
134             octeon_build_bits(OCTEON_FAU_BITS_NOADD, noadd) |
135             octeon_build_bits(OCTEON_FAU_BITS_REGISTER, reg));
136 }
137
138
139 /*
140  * octeon_fau_atomic_add32
141  *
142  * Perform an atomic 32 bit add
143  *
144  * @param reg     FAU atomic register to access. 0 <= reg < 4096.
145  *                - Step by 4 for 32 bit access.
146  * @param value   Signed value to add.
147  */
148 static inline void octeon_fau_atomic_add32 (octeon_fau_reg_32_t reg, int32_t value)
149 {
150     oct_write32(octeon_fau_store_address(0, reg), value);
151 }
152
153 /*
154  * octeon_fau_fetch_and_add
155  *
156  * reg     FAU atomic register to access. 0 <= reg < 4096.
157  *                - Step by 8 for 64 bit access.
158  * value   Signed value to add.
159  *                Note: Only the low 22 bits are available.
160  * returns Value of the register before the update
161  */
162 static inline int64_t octeon_fau_fetch_and_add64 (octeon_fau_reg_64_t reg,
163                                                int64_t  val64)
164 {
165
166     return (oct_read64(octeon_fau_atomic_address(0, reg, val64)));
167 }
168
169 /*
170  * octeon_fau_fetch_and_add32
171  *
172  * reg     FAU atomic register to access. 0 <= reg < 4096.
173  *                - Step by 8 for 64 bit access.
174  * value   Signed value to add.
175  *                Note: Only the low 22 bits are available.
176  * returns Value of the register before the update
177  */
178 static inline int32_t octeon_fau_fetch_and_add32 (octeon_fau_reg_64_t reg,
179                                                int32_t val32)
180 {
181     return (oct_read32(octeon_fau_atomic_address(0, reg, val32)));
182 }
183
184 /*
185  * octeon_fau_atomic_write32
186  *
187  * Perform an atomic 32 bit write
188  *
189  * @param reg     FAU atomic register to access. 0 <= reg < 4096.
190  *                - Step by 4 for 32 bit access.
191  * @param value   Signed value to write.
192  */
193 static inline void octeon_fau_atomic_write32(octeon_fau_reg_32_t reg, int32_t value)
194 {
195     oct_write32(octeon_fau_store_address(1, reg), value);
196 }
197
198
199 /*
200  * octeon_fau_atomic_write64
201  *
202  * Perform an atomic 32 bit write
203  *
204  * reg    FAU atomic register to access. 0 <= reg < 4096.
205  *                - Step by 8 for 64 bit access.
206  * value   Signed value to write.
207  */
208 static inline void octeon_fau_atomic_write64 (octeon_fau_reg_64_t reg, int64_t value)
209 {
210     oct_write64(octeon_fau_store_address(1, reg), value);
211 }
212
213
214 static inline void octeon_fau_atomic_add64 (octeon_fau_reg_64_t reg, int64_t value)
215 {
216     oct_write64_int64(octeon_fau_store_address(0, reg), value);
217 }
218
219
220 #endif  /* ___OCTEON_FAU__H___ */