New upstream version 18.02
[deb_dpdk.git] / drivers / crypto / qat / qat_adf / adf_transport_access_macros.h
1 /*
2  *  This file is provided under a dual BSD/GPLv2 license.  When using or
3  *  redistributing this file, you may do so under either license.
4  *
5  *  GPL LICENSE SUMMARY
6  *  Copyright(c) 2015 Intel Corporation.
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of version 2 of the GNU General Public License as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful, but
12  *  WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  General Public License for more details.
15  *
16  *  Contact Information:
17  *  qat-linux@intel.com
18  *
19  *  BSD LICENSE
20  *  Copyright(c) 2015 Intel Corporation.
21  *  Redistribution and use in source and binary forms, with or without
22  *  modification, are permitted provided that the following conditions
23  *  are met:
24  *
25  *    * Redistributions of source code must retain the above copyright
26  *      notice, this list of conditions and the following disclaimer.
27  *    * Redistributions in binary form must reproduce the above copyright
28  *      notice, this list of conditions and the following disclaimer in
29  *      the documentation and/or other materials provided with the
30  *      distribution.
31  *    * Neither the name of Intel Corporation nor the names of its
32  *      contributors may be used to endorse or promote products derived
33  *      from this software without specific prior written permission.
34  *
35  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46  */
47 #ifndef ADF_TRANSPORT_ACCESS_MACROS_H
48 #define ADF_TRANSPORT_ACCESS_MACROS_H
49
50 #include <rte_io.h>
51
52 /* CSR write macro */
53 #define ADF_CSR_WR(csrAddr, csrOffset, val)             \
54         rte_write32(val, (((uint8_t *)csrAddr) + csrOffset))
55
56 /* CSR read macro */
57 #define ADF_CSR_RD(csrAddr, csrOffset)                  \
58         rte_read32((((uint8_t *)csrAddr) + csrOffset))
59
60 #define ADF_BANK_INT_SRC_SEL_MASK_0 0x4444444CUL
61 #define ADF_BANK_INT_SRC_SEL_MASK_X 0x44444444UL
62 #define ADF_RING_CSR_RING_CONFIG 0x000
63 #define ADF_RING_CSR_RING_LBASE 0x040
64 #define ADF_RING_CSR_RING_UBASE 0x080
65 #define ADF_RING_CSR_RING_HEAD 0x0C0
66 #define ADF_RING_CSR_RING_TAIL 0x100
67 #define ADF_RING_CSR_E_STAT 0x14C
68 #define ADF_RING_CSR_INT_SRCSEL 0x174
69 #define ADF_RING_CSR_INT_SRCSEL_2 0x178
70 #define ADF_RING_CSR_INT_COL_EN 0x17C
71 #define ADF_RING_CSR_INT_COL_CTL 0x180
72 #define ADF_RING_CSR_INT_FLAG_AND_COL 0x184
73 #define ADF_RING_CSR_INT_COL_CTL_ENABLE 0x80000000
74 #define ADF_RING_BUNDLE_SIZE 0x1000
75 #define ADF_RING_CONFIG_NEAR_FULL_WM 0x0A
76 #define ADF_RING_CONFIG_NEAR_EMPTY_WM 0x05
77 #define ADF_COALESCING_MIN_TIME 0x1FF
78 #define ADF_COALESCING_MAX_TIME 0xFFFFF
79 #define ADF_COALESCING_DEF_TIME 0x27FF
80 #define ADF_RING_NEAR_WATERMARK_512 0x08
81 #define ADF_RING_NEAR_WATERMARK_0 0x00
82 #define ADF_RING_EMPTY_SIG 0x7F7F7F7F
83 #define ADF_RING_EMPTY_SIG_BYTE 0x7F
84
85 /* Valid internal ring size values */
86 #define ADF_RING_SIZE_128 0x01
87 #define ADF_RING_SIZE_256 0x02
88 #define ADF_RING_SIZE_512 0x03
89 #define ADF_RING_SIZE_4K 0x06
90 #define ADF_RING_SIZE_16K 0x08
91 #define ADF_RING_SIZE_4M 0x10
92 #define ADF_MIN_RING_SIZE ADF_RING_SIZE_128
93 #define ADF_MAX_RING_SIZE ADF_RING_SIZE_4M
94 #define ADF_DEFAULT_RING_SIZE ADF_RING_SIZE_16K
95
96 #define ADF_NUM_BUNDLES_PER_DEV         1
97 #define ADF_NUM_SYM_QPS_PER_BUNDLE      2
98
99 /* Valid internal msg size values */
100 #define ADF_MSG_SIZE_32 0x01
101 #define ADF_MSG_SIZE_64 0x02
102 #define ADF_MSG_SIZE_128 0x04
103 #define ADF_MIN_MSG_SIZE ADF_MSG_SIZE_32
104 #define ADF_MAX_MSG_SIZE ADF_MSG_SIZE_128
105
106 /* Size to bytes conversion macros for ring and msg size values */
107 #define ADF_MSG_SIZE_TO_BYTES(SIZE) (SIZE << 5)
108 #define ADF_BYTES_TO_MSG_SIZE(SIZE) (SIZE >> 5)
109 #define ADF_SIZE_TO_RING_SIZE_IN_BYTES(SIZE) ((1 << (SIZE - 1)) << 7)
110 #define ADF_RING_SIZE_IN_BYTES_TO_SIZE(SIZE) ((1 << (SIZE - 1)) >> 7)
111
112 /* Minimum ring bufer size for memory allocation */
113 #define ADF_RING_SIZE_BYTES_MIN(SIZE) ((SIZE < ADF_RING_SIZE_4K) ? \
114                                 ADF_RING_SIZE_4K : SIZE)
115 #define ADF_RING_SIZE_MODULO(SIZE) (SIZE + 0x6)
116 #define ADF_SIZE_TO_POW(SIZE) ((((SIZE & 0x4) >> 1) | ((SIZE & 0x4) >> 2) | \
117                                 SIZE) & ~0x4)
118 /* Max outstanding requests */
119 #define ADF_MAX_INFLIGHTS(RING_SIZE, MSG_SIZE) \
120         ((((1 << (RING_SIZE - 1)) << 3) >> ADF_SIZE_TO_POW(MSG_SIZE)) - 1)
121 #define BUILD_RING_CONFIG(size) \
122         ((ADF_RING_NEAR_WATERMARK_0 << ADF_RING_CONFIG_NEAR_FULL_WM) \
123         | (ADF_RING_NEAR_WATERMARK_0 << ADF_RING_CONFIG_NEAR_EMPTY_WM) \
124         | size)
125 #define BUILD_RESP_RING_CONFIG(size, watermark_nf, watermark_ne) \
126         ((watermark_nf << ADF_RING_CONFIG_NEAR_FULL_WM) \
127         | (watermark_ne << ADF_RING_CONFIG_NEAR_EMPTY_WM) \
128         | size)
129 #define BUILD_RING_BASE_ADDR(addr, size) \
130         ((addr >> 6) & (0xFFFFFFFFFFFFFFFFULL << size))
131 #define READ_CSR_RING_HEAD(csr_base_addr, bank, ring) \
132         ADF_CSR_RD(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \
133                         ADF_RING_CSR_RING_HEAD + (ring << 2))
134 #define READ_CSR_RING_TAIL(csr_base_addr, bank, ring) \
135         ADF_CSR_RD(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \
136                         ADF_RING_CSR_RING_TAIL + (ring << 2))
137 #define READ_CSR_E_STAT(csr_base_addr, bank) \
138         ADF_CSR_RD(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \
139                         ADF_RING_CSR_E_STAT)
140 #define WRITE_CSR_RING_CONFIG(csr_base_addr, bank, ring, value) \
141         ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \
142                 ADF_RING_CSR_RING_CONFIG + (ring << 2), value)
143 #define WRITE_CSR_RING_BASE(csr_base_addr, bank, ring, value) \
144 do { \
145         uint32_t l_base = 0, u_base = 0; \
146         l_base = (uint32_t)(value & 0xFFFFFFFF); \
147         u_base = (uint32_t)((value & 0xFFFFFFFF00000000ULL) >> 32); \
148         ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \
149                 ADF_RING_CSR_RING_LBASE + (ring << 2), l_base); \
150         ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \
151                 ADF_RING_CSR_RING_UBASE + (ring << 2), u_base); \
152 } while (0)
153 #define WRITE_CSR_RING_HEAD(csr_base_addr, bank, ring, value) \
154         ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \
155                 ADF_RING_CSR_RING_HEAD + (ring << 2), value)
156 #define WRITE_CSR_RING_TAIL(csr_base_addr, bank, ring, value) \
157         ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \
158                 ADF_RING_CSR_RING_TAIL + (ring << 2), value)
159 #define WRITE_CSR_INT_SRCSEL(csr_base_addr, bank) \
160 do { \
161         ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \
162         ADF_RING_CSR_INT_SRCSEL, ADF_BANK_INT_SRC_SEL_MASK_0);  \
163         ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \
164         ADF_RING_CSR_INT_SRCSEL_2, ADF_BANK_INT_SRC_SEL_MASK_X); \
165 } while (0)
166 #define WRITE_CSR_INT_COL_EN(csr_base_addr, bank, value) \
167         ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \
168                         ADF_RING_CSR_INT_COL_EN, value)
169 #define WRITE_CSR_INT_COL_CTL(csr_base_addr, bank, value) \
170         ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \
171                         ADF_RING_CSR_INT_COL_CTL, \
172                         ADF_RING_CSR_INT_COL_CTL_ENABLE | value)
173 #define WRITE_CSR_INT_FLAG_AND_COL(csr_base_addr, bank, value) \
174         ADF_CSR_WR(csr_base_addr, (ADF_RING_BUNDLE_SIZE * bank) + \
175                         ADF_RING_CSR_INT_FLAG_AND_COL, value)
176 #endif