1*8585bdadSSean Anderson // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-or-later
2e81edc38SIgal Liberman /*
3e81edc38SIgal Liberman * Copyright 2008 - 2015 Freescale Semiconductor Inc.
4e81edc38SIgal Liberman */
5e81edc38SIgal Liberman
6e81edc38SIgal Liberman #include "fman_sp.h"
7e81edc38SIgal Liberman #include "fman.h"
8e81edc38SIgal Liberman
fman_sp_set_buf_pools_in_asc_order_of_buf_sizes(struct fman_ext_pools * fm_ext_pools,u8 * ordered_array,u16 * sizes_array)9e81edc38SIgal Liberman void fman_sp_set_buf_pools_in_asc_order_of_buf_sizes(struct fman_ext_pools
10e81edc38SIgal Liberman *fm_ext_pools,
11e81edc38SIgal Liberman u8 *ordered_array,
12e81edc38SIgal Liberman u16 *sizes_array)
13e81edc38SIgal Liberman {
14e81edc38SIgal Liberman u16 buf_size = 0;
15e81edc38SIgal Liberman int i = 0, j = 0, k = 0;
16e81edc38SIgal Liberman
17e81edc38SIgal Liberman /* First we copy the external buffers pools information
18e81edc38SIgal Liberman * to an ordered local array
19e81edc38SIgal Liberman */
20e81edc38SIgal Liberman for (i = 0; i < fm_ext_pools->num_of_pools_used; i++) {
21e81edc38SIgal Liberman /* get pool size */
22e81edc38SIgal Liberman buf_size = fm_ext_pools->ext_buf_pool[i].size;
23e81edc38SIgal Liberman
24e81edc38SIgal Liberman /* keep sizes in an array according to poolId
25e81edc38SIgal Liberman * for direct access
26e81edc38SIgal Liberman */
27e81edc38SIgal Liberman sizes_array[fm_ext_pools->ext_buf_pool[i].id] = buf_size;
28e81edc38SIgal Liberman
29e81edc38SIgal Liberman /* save poolId in an ordered array according to size */
30e81edc38SIgal Liberman for (j = 0; j <= i; j++) {
31e81edc38SIgal Liberman /* this is the next free place in the array */
32e81edc38SIgal Liberman if (j == i)
33e81edc38SIgal Liberman ordered_array[i] =
34e81edc38SIgal Liberman fm_ext_pools->ext_buf_pool[i].id;
35e81edc38SIgal Liberman else {
36e81edc38SIgal Liberman /* find the right place for this poolId */
37e81edc38SIgal Liberman if (buf_size < sizes_array[ordered_array[j]]) {
38e81edc38SIgal Liberman /* move the pool_ids one place ahead
39e81edc38SIgal Liberman * to make room for this poolId
40e81edc38SIgal Liberman */
41e81edc38SIgal Liberman for (k = i; k > j; k--)
42e81edc38SIgal Liberman ordered_array[k] =
43e81edc38SIgal Liberman ordered_array[k - 1];
44e81edc38SIgal Liberman
45e81edc38SIgal Liberman /* now k==j, this is the place for
46e81edc38SIgal Liberman * the new size
47e81edc38SIgal Liberman */
48e81edc38SIgal Liberman ordered_array[k] =
49e81edc38SIgal Liberman fm_ext_pools->ext_buf_pool[i].id;
50e81edc38SIgal Liberman break;
51e81edc38SIgal Liberman }
52e81edc38SIgal Liberman }
53e81edc38SIgal Liberman }
54e81edc38SIgal Liberman }
55e81edc38SIgal Liberman }
5629c4684eSIgal Liberman EXPORT_SYMBOL(fman_sp_set_buf_pools_in_asc_order_of_buf_sizes);
57e81edc38SIgal Liberman
fman_sp_build_buffer_struct(struct fman_sp_int_context_data_copy * int_context_data_copy,struct fman_buffer_prefix_content * buffer_prefix_content,struct fman_sp_buf_margins * buf_margins,struct fman_sp_buffer_offsets * buffer_offsets,u8 * internal_buf_offset)58e81edc38SIgal Liberman int fman_sp_build_buffer_struct(struct fman_sp_int_context_data_copy *
59e81edc38SIgal Liberman int_context_data_copy,
60e81edc38SIgal Liberman struct fman_buffer_prefix_content *
61e81edc38SIgal Liberman buffer_prefix_content,
62e81edc38SIgal Liberman struct fman_sp_buf_margins *buf_margins,
63e81edc38SIgal Liberman struct fman_sp_buffer_offsets *buffer_offsets,
64e81edc38SIgal Liberman u8 *internal_buf_offset)
65e81edc38SIgal Liberman {
66e81edc38SIgal Liberman u32 tmp;
67e81edc38SIgal Liberman
68e81edc38SIgal Liberman /* Align start of internal context data to 16 byte */
69e81edc38SIgal Liberman int_context_data_copy->ext_buf_offset = (u16)
70e81edc38SIgal Liberman ((buffer_prefix_content->priv_data_size & (OFFSET_UNITS - 1)) ?
71e81edc38SIgal Liberman ((buffer_prefix_content->priv_data_size + OFFSET_UNITS) &
72e81edc38SIgal Liberman ~(u16)(OFFSET_UNITS - 1)) :
73e81edc38SIgal Liberman buffer_prefix_content->priv_data_size);
74e81edc38SIgal Liberman
75e81edc38SIgal Liberman /* Translate margin and int_context params to FM parameters */
76e81edc38SIgal Liberman /* Initialize with illegal value. Later we'll set legal values. */
77e81edc38SIgal Liberman buffer_offsets->prs_result_offset = (u32)ILLEGAL_BASE;
78e81edc38SIgal Liberman buffer_offsets->time_stamp_offset = (u32)ILLEGAL_BASE;
79e81edc38SIgal Liberman buffer_offsets->hash_result_offset = (u32)ILLEGAL_BASE;
80e81edc38SIgal Liberman
81e81edc38SIgal Liberman /* Internally the driver supports 4 options
82e81edc38SIgal Liberman * 1. prsResult/timestamp/hashResult selection (in fact 8 options,
83e81edc38SIgal Liberman * but for simplicity we'll
84e81edc38SIgal Liberman * relate to it as 1).
85e81edc38SIgal Liberman * 2. All IC context (from AD) not including debug.
86e81edc38SIgal Liberman */
87e81edc38SIgal Liberman
88e81edc38SIgal Liberman /* This case covers the options under 1 */
89e81edc38SIgal Liberman /* Copy size must be in 16-byte granularity. */
90e81edc38SIgal Liberman int_context_data_copy->size =
91e81edc38SIgal Liberman (u16)((buffer_prefix_content->pass_prs_result ? 32 : 0) +
92e81edc38SIgal Liberman ((buffer_prefix_content->pass_time_stamp ||
93e81edc38SIgal Liberman buffer_prefix_content->pass_hash_result) ? 16 : 0));
94e81edc38SIgal Liberman
95e81edc38SIgal Liberman /* Align start of internal context data to 16 byte */
96e81edc38SIgal Liberman int_context_data_copy->int_context_offset =
97e81edc38SIgal Liberman (u8)(buffer_prefix_content->pass_prs_result ? 32 :
98e81edc38SIgal Liberman ((buffer_prefix_content->pass_time_stamp ||
99e81edc38SIgal Liberman buffer_prefix_content->pass_hash_result) ? 64 : 0));
100e81edc38SIgal Liberman
101e81edc38SIgal Liberman if (buffer_prefix_content->pass_prs_result)
102e81edc38SIgal Liberman buffer_offsets->prs_result_offset =
103e81edc38SIgal Liberman int_context_data_copy->ext_buf_offset;
104e81edc38SIgal Liberman if (buffer_prefix_content->pass_time_stamp)
105e81edc38SIgal Liberman buffer_offsets->time_stamp_offset =
106e81edc38SIgal Liberman buffer_prefix_content->pass_prs_result ?
107e81edc38SIgal Liberman (int_context_data_copy->ext_buf_offset +
108e81edc38SIgal Liberman sizeof(struct fman_prs_result)) :
109e81edc38SIgal Liberman int_context_data_copy->ext_buf_offset;
110e81edc38SIgal Liberman if (buffer_prefix_content->pass_hash_result)
111e81edc38SIgal Liberman /* If PR is not requested, whether TS is
112e81edc38SIgal Liberman * requested or not, IC will be copied from TS
113e81edc38SIgal Liberman */
114e81edc38SIgal Liberman buffer_offsets->hash_result_offset =
115e81edc38SIgal Liberman buffer_prefix_content->pass_prs_result ?
116e81edc38SIgal Liberman (int_context_data_copy->ext_buf_offset +
117e81edc38SIgal Liberman sizeof(struct fman_prs_result) + 8) :
118e81edc38SIgal Liberman int_context_data_copy->ext_buf_offset + 8;
119e81edc38SIgal Liberman
120e81edc38SIgal Liberman if (int_context_data_copy->size)
121e81edc38SIgal Liberman buf_margins->start_margins =
122e81edc38SIgal Liberman (u16)(int_context_data_copy->ext_buf_offset +
123e81edc38SIgal Liberman int_context_data_copy->size);
124e81edc38SIgal Liberman else
125e81edc38SIgal Liberman /* No Internal Context passing, STartMargin is
126e81edc38SIgal Liberman * immediately after private_info
127e81edc38SIgal Liberman */
128e81edc38SIgal Liberman buf_margins->start_margins =
129e81edc38SIgal Liberman buffer_prefix_content->priv_data_size;
130e81edc38SIgal Liberman
131e81edc38SIgal Liberman /* align data start */
132e81edc38SIgal Liberman tmp = (u32)(buf_margins->start_margins %
133e81edc38SIgal Liberman buffer_prefix_content->data_align);
134e81edc38SIgal Liberman if (tmp)
135e81edc38SIgal Liberman buf_margins->start_margins +=
136e81edc38SIgal Liberman (buffer_prefix_content->data_align - tmp);
137e81edc38SIgal Liberman buffer_offsets->data_offset = buf_margins->start_margins;
138e81edc38SIgal Liberman
139e81edc38SIgal Liberman return 0;
140e81edc38SIgal Liberman }
14129c4684eSIgal Liberman EXPORT_SYMBOL(fman_sp_build_buffer_struct);
14229c4684eSIgal Liberman
143