1 #ifndef __CB_BDK_LMT_H__
2 #define __CB_BDK_LMT_H__
3 /***********************license start***********************************
4 * Copyright (c) 2003-2017 Cavium Inc. ([email protected]). All rights
5 * reserved.
6 *
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 *
20 * * Neither the name of Cavium Inc. nor the names of
21 * its contributors may be used to endorse or promote products
22 * derived from this software without specific prior written
23 * permission.
24 *
25 * This Software, including technical data, may be subject to U.S. export
26 * control laws, including the U.S. Export Administration Act and its
27 * associated regulations, and may be subject to export or import
28 * regulations in other countries.
29 *
30 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
31 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
32 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
33 * TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
34 * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
35 * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
36 * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
37 * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
38 * QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
39 * ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
40 ***********************license end**************************************/
41
42 /**
43 * @file
44 *
45 * Defiens and functions for performing LMT operations, such as
46 * LMTST and LMTCANCEL
47 *
48 * @defgroup lmt Local Memory Transaction (LMT) support
49 * @{
50 */
51 #include "libbdk-arch/bdk-csrs-lmt.h"
52
53 /**
54 * Address of the LMT store area in physical memory
55 */
56 #define __BDK_LMTLINE_CN83XX 0x87F100000000ull
57
58 /**
59 * Flush the LMTLINE area of all previous writes and clear the valid flag
60 */
bdk_lmt_cancel(void)61 static inline void bdk_lmt_cancel(void)
62 {
63 if (CAVIUM_IS_MODEL(CAVIUM_CN83XX))
64 *(volatile uint64_t *)(__BDK_LMTLINE_CN83XX | (1 << 10)) = 0;
65 else
66 BDK_CSR_WRITE(bdk_numa_local(), BDK_LMT_LF_LMTCANCEL, 0);
67 }
68
69 /**
70 * Return a volatile pointer to the LMTLINE area in 64bit words. Good programming
71 * practice would to always store sequencially, incrementing the pointer for each
72 * word written.
73 *
74 * @return Voltaile uint64_t pointer to LMTLINE
75 */
bdk_lmt_store_ptr(void)76 static inline volatile uint64_t *bdk_lmt_store_ptr(void)
77 {
78 if (CAVIUM_IS_MODEL(CAVIUM_CN83XX))
79 return (volatile uint64_t *)__BDK_LMTLINE_CN83XX;
80 else
81 return (volatile uint64_t *)BDK_LMT_LF_LMTLINEX(0);
82 }
83
84 /**
85 * Send the data stored to LMTLINE to an IO block. This call may
86 * fail if the hardware has invalidated the LMTLINE area. If it
87 * fails, you must issue all LMT stores again and redo this
88 * call. Note the return status of this function is backwards
89 * to most BDK functions. It matches the LMTST hardware result.
90 *
91 * @param io_address 48 bit IO address where the LMTLINE data will be sent
92 *
93 * @return Zero on failure, non-zero on success
94 */
bdk_lmt_submit(uint64_t io_address)95 static inline int bdk_lmt_submit(uint64_t io_address)
96 {
97 int64_t result = 0;
98 asm volatile ("LDEOR xzr,%x[rf],[%[rs]]" : [rf] "=r"(result): [rs] "r"(io_address));
99 return bdk_le64_to_cpu(result);
100 }
101
102 /** @} */
103 #endif
104