1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) */
2 /* Copyright(c) 2014 - 2020 Intel Corporation */
3 #ifndef ADF_TRANSPORT_ACCESS_MACROS_H
4 #define ADF_TRANSPORT_ACCESS_MACROS_H
5 
6 #include "adf_accel_devices.h"
7 #define ADF_RING_CONFIG_NEAR_FULL_WM 0x0A
8 #define ADF_RING_CONFIG_NEAR_EMPTY_WM 0x05
9 #define ADF_COALESCING_MIN_TIME 0x1FF
10 #define ADF_COALESCING_MAX_TIME 0xFFFFF
11 #define ADF_COALESCING_DEF_TIME 0x27FF
12 #define ADF_RING_NEAR_WATERMARK_512 0x08
13 #define ADF_RING_NEAR_WATERMARK_0 0x00
14 #define ADF_RING_EMPTY_SIG 0x7F7F7F7F
15 
16 /* Valid internal ring size values */
17 #define ADF_RING_SIZE_128 0x01
18 #define ADF_RING_SIZE_256 0x02
19 #define ADF_RING_SIZE_512 0x03
20 #define ADF_RING_SIZE_4K 0x06
21 #define ADF_RING_SIZE_16K 0x08
22 #define ADF_RING_SIZE_4M 0x10
23 #define ADF_MIN_RING_SIZE ADF_RING_SIZE_128
24 #define ADF_MAX_RING_SIZE ADF_RING_SIZE_4M
25 #define ADF_DEFAULT_RING_SIZE ADF_RING_SIZE_16K
26 
27 /* Valid internal msg size values */
28 #define ADF_MSG_SIZE_32 0x01
29 #define ADF_MSG_SIZE_64 0x02
30 #define ADF_MSG_SIZE_128 0x04
31 #define ADF_MIN_MSG_SIZE ADF_MSG_SIZE_32
32 #define ADF_MAX_MSG_SIZE ADF_MSG_SIZE_128
33 
34 /* Size to bytes conversion macros for ring and msg size values */
35 #define ADF_MSG_SIZE_TO_BYTES(SIZE) (SIZE << 5)
36 #define ADF_BYTES_TO_MSG_SIZE(SIZE) (SIZE >> 5)
37 #define ADF_SIZE_TO_RING_SIZE_IN_BYTES(SIZE) ((1 << (SIZE - 1)) << 7)
38 #define ADF_RING_SIZE_IN_BYTES_TO_SIZE(SIZE) ((1 << (SIZE - 1)) >> 7)
39 
40 /* Minimum ring buffer size for memory allocation */
41 #define ADF_RING_SIZE_BYTES_MIN(SIZE) \
42 	((SIZE < ADF_SIZE_TO_RING_SIZE_IN_BYTES(ADF_RING_SIZE_4K)) ? \
43 		ADF_SIZE_TO_RING_SIZE_IN_BYTES(ADF_RING_SIZE_4K) : SIZE)
44 #define ADF_RING_SIZE_MODULO(SIZE) (SIZE + 0x6)
45 #define ADF_SIZE_TO_POW(SIZE) ((((SIZE & 0x4) >> 1) | ((SIZE & 0x4) >> 2) | \
46 				SIZE) & ~0x4)
47 /* Max outstanding requests */
48 #define ADF_MAX_INFLIGHTS(RING_SIZE, MSG_SIZE) \
49 	((((1 << (RING_SIZE - 1)) << 3) >> ADF_SIZE_TO_POW(MSG_SIZE)) - 1)
50 #define BUILD_RING_CONFIG(size)	\
51 	((ADF_RING_NEAR_WATERMARK_0 << ADF_RING_CONFIG_NEAR_FULL_WM) \
52 	| (ADF_RING_NEAR_WATERMARK_0 << ADF_RING_CONFIG_NEAR_EMPTY_WM) \
53 	| size)
54 #define BUILD_RESP_RING_CONFIG(size, watermark_nf, watermark_ne) \
55 	((watermark_nf << ADF_RING_CONFIG_NEAR_FULL_WM)	\
56 	| (watermark_ne << ADF_RING_CONFIG_NEAR_EMPTY_WM) \
57 	| size)
58 #endif
59