1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-or-later */
2 /*
3  * Copyright 2008 - 2015 Freescale Semiconductor Inc.
4  */
5 
6 #ifndef __FM_SP_H
7 #define __FM_SP_H
8 
9 #include "fman.h"
10 #include <linux/types.h>
11 
12 #define ILLEGAL_BASE    (~0)
13 
14 /* defaults */
15 #define DFLT_FM_SP_BUFFER_PREFIX_CONTEXT_DATA_ALIGN	64
16 
17 /* Registers bit fields */
18 #define FMAN_SP_EXT_BUF_POOL_EN_COUNTER		0x40000000
19 #define FMAN_SP_EXT_BUF_POOL_VALID			0x80000000
20 #define FMAN_SP_EXT_BUF_POOL_BACKUP			0x20000000
21 #define FMAN_SP_DMA_ATTR_WRITE_OPTIMIZE		0x00100000
22 #define FMAN_SP_SG_DISABLE				0x80000000
23 
24 /* shifts */
25 #define FMAN_SP_EXT_BUF_MARG_START_SHIFT		16
26 #define FMAN_SP_DMA_ATTR_SWP_SHIFT			30
27 #define FMAN_SP_IC_TO_EXT_SHIFT			16
28 #define FMAN_SP_IC_FROM_INT_SHIFT			8
29 
30 /* structure for defining internal context copying */
31 struct fman_sp_int_context_data_copy {
32 	/* < Offset in External buffer to which internal
33 	 *  context is copied to (Rx) or taken from (Tx, Op).
34 	 */
35 	u16 ext_buf_offset;
36 	/* Offset within internal context to copy from
37 	 * (Rx) or to copy to (Tx, Op).
38 	 */
39 	u8 int_context_offset;
40 	/* Internal offset size to be copied */
41 	u16 size;
42 };
43 
44 /*  struct for defining external buffer margins */
45 struct fman_sp_buf_margins {
46 	/* Number of bytes to be left at the beginning
47 	 * of the external buffer (must be divisible by 16)
48 	 */
49 	u16 start_margins;
50 	/* number of bytes to be left at the end
51 	 * of the external buffer(must be divisible by 16)
52 	 */
53 	u16 end_margins;
54 };
55 
56 struct fman_sp_buffer_offsets {
57 	u32 data_offset;
58 	u32 prs_result_offset;
59 	u32 time_stamp_offset;
60 	u32 hash_result_offset;
61 };
62 
63 int fman_sp_build_buffer_struct(struct fman_sp_int_context_data_copy
64 				*int_context_data_copy,
65 				struct fman_buffer_prefix_content
66 				*buffer_prefix_content,
67 				struct fman_sp_buf_margins *buf_margins,
68 				struct fman_sp_buffer_offsets
69 				*buffer_offsets,
70 				u8 *internal_buf_offset);
71 
72 void fman_sp_set_buf_pools_in_asc_order_of_buf_sizes(struct fman_ext_pools
73 						     *fm_ext_pools,
74 						     u8 *ordered_array,
75 						     u16 *sizes_array);
76 
77 #endif	/* __FM_SP_H */
78