Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cvmx-fau.h
Go to the documentation of this file.
1 /***********************license start***************
2  * Author: Cavium Networks
3  *
4  * Contact: [email protected]
5  * This file is part of the OCTEON SDK
6  *
7  * Copyright (c) 2003-2008 Cavium Networks
8  *
9  * This file is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License, Version 2, as
11  * published by the Free Software Foundation.
12  *
13  * This file is distributed in the hope that it will be useful, but
14  * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16  * NONINFRINGEMENT. See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this file; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22  * or visit http://www.gnu.org/licenses/.
23  *
24  * This file may also be available under a different license from Cavium.
25  * Contact Cavium Networks for more information
26  ***********************license end**************************************/
27 
28 /*
29  * Interface to the hardware Fetch and Add Unit.
30  */
31 
32 #ifndef __CVMX_FAU_H__
33 #define __CVMX_FAU_H__
34 
35 /*
36  * Octeon Fetch and Add Unit (FAU)
37  */
38 
39 #define CVMX_FAU_LOAD_IO_ADDRESS cvmx_build_io_address(0x1e, 0)
40 #define CVMX_FAU_BITS_SCRADDR 63, 56
41 #define CVMX_FAU_BITS_LEN 55, 48
42 #define CVMX_FAU_BITS_INEVAL 35, 14
43 #define CVMX_FAU_BITS_TAGWAIT 13, 13
44 #define CVMX_FAU_BITS_NOADD 13, 13
45 #define CVMX_FAU_BITS_SIZE 12, 11
46 #define CVMX_FAU_BITS_REGISTER 10, 0
47 
48 typedef enum {
54 
60 typedef struct {
62  int64_t value:63;
64 
70 typedef struct {
74 
80 typedef struct {
84 
90 typedef struct {
94 
100 typedef union {
102  struct {
104  uint64_t data:63; /* unpredictable if invalid is set */
105  } s;
107 
119 static inline uint64_t __cvmx_fau_store_address(uint64_t noadd, uint64_t reg)
120 {
122  cvmx_build_bits(CVMX_FAU_BITS_NOADD, noadd) |
123  cvmx_build_bits(CVMX_FAU_BITS_REGISTER, reg);
124 }
125 
142 static inline uint64_t __cvmx_fau_atomic_address(uint64_t tagwait, uint64_t reg,
143  int64_t value)
144 {
146  cvmx_build_bits(CVMX_FAU_BITS_INEVAL, value) |
147  cvmx_build_bits(CVMX_FAU_BITS_TAGWAIT, tagwait) |
148  cvmx_build_bits(CVMX_FAU_BITS_REGISTER, reg);
149 }
150 
160 static inline int64_t cvmx_fau_fetch_and_add64(cvmx_fau_reg_64_t reg,
161  int64_t value)
162 {
163  return cvmx_read64_int64(__cvmx_fau_atomic_address(0, reg, value));
164 }
165 
175 static inline int32_t cvmx_fau_fetch_and_add32(cvmx_fau_reg_32_t reg,
176  int32_t value)
177 {
178  return cvmx_read64_int32(__cvmx_fau_atomic_address(0, reg, value));
179 }
180 
189 static inline int16_t cvmx_fau_fetch_and_add16(cvmx_fau_reg_16_t reg,
190  int16_t value)
191 {
192  return cvmx_read64_int16(__cvmx_fau_atomic_address(0, reg, value));
193 }
194 
202 static inline int8_t cvmx_fau_fetch_and_add8(cvmx_fau_reg_8_t reg, int8_t value)
203 {
204  return cvmx_read64_int8(__cvmx_fau_atomic_address(0, reg, value));
205 }
206 
219 static inline cvmx_fau_tagwait64_t
220 cvmx_fau_tagwait_fetch_and_add64(cvmx_fau_reg_64_t reg, int64_t value)
221 {
222  union {
223  uint64_t i64;
225  } result;
226  result.i64 =
227  cvmx_read64_int64(__cvmx_fau_atomic_address(1, reg, value));
228  return result.t;
229 }
230 
243 static inline cvmx_fau_tagwait32_t
244 cvmx_fau_tagwait_fetch_and_add32(cvmx_fau_reg_32_t reg, int32_t value)
245 {
246  union {
247  uint64_t i32;
249  } result;
250  result.i32 =
251  cvmx_read64_int32(__cvmx_fau_atomic_address(1, reg, value));
252  return result.t;
253 }
254 
266 static inline cvmx_fau_tagwait16_t
267 cvmx_fau_tagwait_fetch_and_add16(cvmx_fau_reg_16_t reg, int16_t value)
268 {
269  union {
270  uint64_t i16;
272  } result;
273  result.i16 =
274  cvmx_read64_int16(__cvmx_fau_atomic_address(1, reg, value));
275  return result.t;
276 }
277 
288 static inline cvmx_fau_tagwait8_t
289 cvmx_fau_tagwait_fetch_and_add8(cvmx_fau_reg_8_t reg, int8_t value)
290 {
291  union {
292  uint64_t i8;
294  } result;
295  result.i8 = cvmx_read64_int8(__cvmx_fau_atomic_address(1, reg, value));
296  return result.t;
297 }
298 
321 static inline uint64_t __cvmx_fau_iobdma_data(uint64_t scraddr, int64_t value,
322  uint64_t tagwait,
324  uint64_t reg)
325 {
326  return CVMX_FAU_LOAD_IO_ADDRESS |
327  cvmx_build_bits(CVMX_FAU_BITS_SCRADDR, scraddr >> 3) |
328  cvmx_build_bits(CVMX_FAU_BITS_LEN, 1) |
329  cvmx_build_bits(CVMX_FAU_BITS_INEVAL, value) |
330  cvmx_build_bits(CVMX_FAU_BITS_TAGWAIT, tagwait) |
331  cvmx_build_bits(CVMX_FAU_BITS_SIZE, size) |
332  cvmx_build_bits(CVMX_FAU_BITS_REGISTER, reg);
333 }
334 
347 static inline void cvmx_fau_async_fetch_and_add64(uint64_t scraddr,
348  cvmx_fau_reg_64_t reg,
349  int64_t value)
350 {
351  cvmx_send_single(__cvmx_fau_iobdma_data
352  (scraddr, value, 0, CVMX_FAU_OP_SIZE_64, reg));
353 }
354 
367 static inline void cvmx_fau_async_fetch_and_add32(uint64_t scraddr,
368  cvmx_fau_reg_32_t reg,
369  int32_t value)
370 {
371  cvmx_send_single(__cvmx_fau_iobdma_data
372  (scraddr, value, 0, CVMX_FAU_OP_SIZE_32, reg));
373 }
374 
386 static inline void cvmx_fau_async_fetch_and_add16(uint64_t scraddr,
387  cvmx_fau_reg_16_t reg,
388  int16_t value)
389 {
390  cvmx_send_single(__cvmx_fau_iobdma_data
391  (scraddr, value, 0, CVMX_FAU_OP_SIZE_16, reg));
392 }
393 
404 static inline void cvmx_fau_async_fetch_and_add8(uint64_t scraddr,
405  cvmx_fau_reg_8_t reg,
406  int8_t value)
407 {
408  cvmx_send_single(__cvmx_fau_iobdma_data
409  (scraddr, value, 0, CVMX_FAU_OP_SIZE_8, reg));
410 }
411 
427 static inline void cvmx_fau_async_tagwait_fetch_and_add64(uint64_t scraddr,
428  cvmx_fau_reg_64_t reg,
429  int64_t value)
430 {
431  cvmx_send_single(__cvmx_fau_iobdma_data
432  (scraddr, value, 1, CVMX_FAU_OP_SIZE_64, reg));
433 }
434 
450 static inline void cvmx_fau_async_tagwait_fetch_and_add32(uint64_t scraddr,
451  cvmx_fau_reg_32_t reg,
452  int32_t value)
453 {
454  cvmx_send_single(__cvmx_fau_iobdma_data
455  (scraddr, value, 1, CVMX_FAU_OP_SIZE_32, reg));
456 }
457 
473 static inline void cvmx_fau_async_tagwait_fetch_and_add16(uint64_t scraddr,
474  cvmx_fau_reg_16_t reg,
475  int16_t value)
476 {
477  cvmx_send_single(__cvmx_fau_iobdma_data
478  (scraddr, value, 1, CVMX_FAU_OP_SIZE_16, reg));
479 }
480 
495 static inline void cvmx_fau_async_tagwait_fetch_and_add8(uint64_t scraddr,
496  cvmx_fau_reg_8_t reg,
497  int8_t value)
498 {
499  cvmx_send_single(__cvmx_fau_iobdma_data
500  (scraddr, value, 1, CVMX_FAU_OP_SIZE_8, reg));
501 }
502 
510 static inline void cvmx_fau_atomic_add64(cvmx_fau_reg_64_t reg, int64_t value)
511 {
512  cvmx_write64_int64(__cvmx_fau_store_address(0, reg), value);
513 }
514 
522 static inline void cvmx_fau_atomic_add32(cvmx_fau_reg_32_t reg, int32_t value)
523 {
524  cvmx_write64_int32(__cvmx_fau_store_address(0, reg), value);
525 }
526 
534 static inline void cvmx_fau_atomic_add16(cvmx_fau_reg_16_t reg, int16_t value)
535 {
536  cvmx_write64_int16(__cvmx_fau_store_address(0, reg), value);
537 }
538 
545 static inline void cvmx_fau_atomic_add8(cvmx_fau_reg_8_t reg, int8_t value)
546 {
547  cvmx_write64_int8(__cvmx_fau_store_address(0, reg), value);
548 }
549 
557 static inline void cvmx_fau_atomic_write64(cvmx_fau_reg_64_t reg, int64_t value)
558 {
559  cvmx_write64_int64(__cvmx_fau_store_address(1, reg), value);
560 }
561 
569 static inline void cvmx_fau_atomic_write32(cvmx_fau_reg_32_t reg, int32_t value)
570 {
571  cvmx_write64_int32(__cvmx_fau_store_address(1, reg), value);
572 }
573 
581 static inline void cvmx_fau_atomic_write16(cvmx_fau_reg_16_t reg, int16_t value)
582 {
583  cvmx_write64_int16(__cvmx_fau_store_address(1, reg), value);
584 }
585 
592 static inline void cvmx_fau_atomic_write8(cvmx_fau_reg_8_t reg, int8_t value)
593 {
594  cvmx_write64_int8(__cvmx_fau_store_address(1, reg), value);
595 }
596 
597 #endif /* __CVMX_FAU_H__ */