Skip to content

Commit e81edc3

Browse files
Igal Libermandavem330
authored andcommitted
fsl/fman: Add FMan SP support
The Storage Profiles contain parameters that are used by the FMan for frame reception and transmission. Signed-off-by: Igal Liberman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 57ba4c9 commit e81edc3

File tree

3 files changed

+270
-1
lines changed

3 files changed

+270
-1
lines changed

drivers/net/ethernet/freescale/fman/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ subdir-ccflags-y += -I$(srctree)/drivers/net/ethernet/freescale/fman
22

33
obj-y += fsl_fman.o fsl_fman_mac.o
44

5-
fsl_fman-objs := fman_muram.o fman.o
5+
fsl_fman-objs := fman_muram.o fman.o fman_sp.o
66
fsl_fman_mac-objs := fman_dtsec.o fman_memac.o fman_tgec.o
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/*
2+
* Copyright 2008 - 2015 Freescale Semiconductor Inc.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
* * Redistributions of source code must retain the above copyright
7+
* notice, this list of conditions and the following disclaimer.
8+
* * Redistributions in binary form must reproduce the above copyright
9+
* notice, this list of conditions and the following disclaimer in the
10+
* documentation and/or other materials provided with the distribution.
11+
* * Neither the name of Freescale Semiconductor nor the
12+
* names of its contributors may be used to endorse or promote products
13+
* derived from this software without specific prior written permission.
14+
*
15+
*
16+
* ALTERNATIVELY, this software may be distributed under the terms of the
17+
* GNU General Public License ("GPL") as published by the Free Software
18+
* Foundation, either version 2 of that License or (at your option) any
19+
* later version.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
* DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
33+
#include "fman_sp.h"
34+
#include "fman.h"
35+
36+
void fman_sp_set_buf_pools_in_asc_order_of_buf_sizes(struct fman_ext_pools
37+
*fm_ext_pools,
38+
u8 *ordered_array,
39+
u16 *sizes_array)
40+
{
41+
u16 buf_size = 0;
42+
int i = 0, j = 0, k = 0;
43+
44+
/* First we copy the external buffers pools information
45+
* to an ordered local array
46+
*/
47+
for (i = 0; i < fm_ext_pools->num_of_pools_used; i++) {
48+
/* get pool size */
49+
buf_size = fm_ext_pools->ext_buf_pool[i].size;
50+
51+
/* keep sizes in an array according to poolId
52+
* for direct access
53+
*/
54+
sizes_array[fm_ext_pools->ext_buf_pool[i].id] = buf_size;
55+
56+
/* save poolId in an ordered array according to size */
57+
for (j = 0; j <= i; j++) {
58+
/* this is the next free place in the array */
59+
if (j == i)
60+
ordered_array[i] =
61+
fm_ext_pools->ext_buf_pool[i].id;
62+
else {
63+
/* find the right place for this poolId */
64+
if (buf_size < sizes_array[ordered_array[j]]) {
65+
/* move the pool_ids one place ahead
66+
* to make room for this poolId
67+
*/
68+
for (k = i; k > j; k--)
69+
ordered_array[k] =
70+
ordered_array[k - 1];
71+
72+
/* now k==j, this is the place for
73+
* the new size
74+
*/
75+
ordered_array[k] =
76+
fm_ext_pools->ext_buf_pool[i].id;
77+
break;
78+
}
79+
}
80+
}
81+
}
82+
}
83+
84+
int fman_sp_build_buffer_struct(struct fman_sp_int_context_data_copy *
85+
int_context_data_copy,
86+
struct fman_buffer_prefix_content *
87+
buffer_prefix_content,
88+
struct fman_sp_buf_margins *buf_margins,
89+
struct fman_sp_buffer_offsets *buffer_offsets,
90+
u8 *internal_buf_offset)
91+
{
92+
u32 tmp;
93+
94+
/* Align start of internal context data to 16 byte */
95+
int_context_data_copy->ext_buf_offset = (u16)
96+
((buffer_prefix_content->priv_data_size & (OFFSET_UNITS - 1)) ?
97+
((buffer_prefix_content->priv_data_size + OFFSET_UNITS) &
98+
~(u16)(OFFSET_UNITS - 1)) :
99+
buffer_prefix_content->priv_data_size);
100+
101+
/* Translate margin and int_context params to FM parameters */
102+
/* Initialize with illegal value. Later we'll set legal values. */
103+
buffer_offsets->prs_result_offset = (u32)ILLEGAL_BASE;
104+
buffer_offsets->time_stamp_offset = (u32)ILLEGAL_BASE;
105+
buffer_offsets->hash_result_offset = (u32)ILLEGAL_BASE;
106+
107+
/* Internally the driver supports 4 options
108+
* 1. prsResult/timestamp/hashResult selection (in fact 8 options,
109+
* but for simplicity we'll
110+
* relate to it as 1).
111+
* 2. All IC context (from AD) not including debug.
112+
*/
113+
114+
/* This case covers the options under 1 */
115+
/* Copy size must be in 16-byte granularity. */
116+
int_context_data_copy->size =
117+
(u16)((buffer_prefix_content->pass_prs_result ? 32 : 0) +
118+
((buffer_prefix_content->pass_time_stamp ||
119+
buffer_prefix_content->pass_hash_result) ? 16 : 0));
120+
121+
/* Align start of internal context data to 16 byte */
122+
int_context_data_copy->int_context_offset =
123+
(u8)(buffer_prefix_content->pass_prs_result ? 32 :
124+
((buffer_prefix_content->pass_time_stamp ||
125+
buffer_prefix_content->pass_hash_result) ? 64 : 0));
126+
127+
if (buffer_prefix_content->pass_prs_result)
128+
buffer_offsets->prs_result_offset =
129+
int_context_data_copy->ext_buf_offset;
130+
if (buffer_prefix_content->pass_time_stamp)
131+
buffer_offsets->time_stamp_offset =
132+
buffer_prefix_content->pass_prs_result ?
133+
(int_context_data_copy->ext_buf_offset +
134+
sizeof(struct fman_prs_result)) :
135+
int_context_data_copy->ext_buf_offset;
136+
if (buffer_prefix_content->pass_hash_result)
137+
/* If PR is not requested, whether TS is
138+
* requested or not, IC will be copied from TS
139+
*/
140+
buffer_offsets->hash_result_offset =
141+
buffer_prefix_content->pass_prs_result ?
142+
(int_context_data_copy->ext_buf_offset +
143+
sizeof(struct fman_prs_result) + 8) :
144+
int_context_data_copy->ext_buf_offset + 8;
145+
146+
if (int_context_data_copy->size)
147+
buf_margins->start_margins =
148+
(u16)(int_context_data_copy->ext_buf_offset +
149+
int_context_data_copy->size);
150+
else
151+
/* No Internal Context passing, STartMargin is
152+
* immediately after private_info
153+
*/
154+
buf_margins->start_margins =
155+
buffer_prefix_content->priv_data_size;
156+
157+
/* align data start */
158+
tmp = (u32)(buf_margins->start_margins %
159+
buffer_prefix_content->data_align);
160+
if (tmp)
161+
buf_margins->start_margins +=
162+
(buffer_prefix_content->data_align - tmp);
163+
buffer_offsets->data_offset = buf_margins->start_margins;
164+
165+
return 0;
166+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright 2008 - 2015 Freescale Semiconductor Inc.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
* * Redistributions of source code must retain the above copyright
7+
* notice, this list of conditions and the following disclaimer.
8+
* * Redistributions in binary form must reproduce the above copyright
9+
* notice, this list of conditions and the following disclaimer in the
10+
* documentation and/or other materials provided with the distribution.
11+
* * Neither the name of Freescale Semiconductor nor the
12+
* names of its contributors may be used to endorse or promote products
13+
* derived from this software without specific prior written permission.
14+
*
15+
* ALTERNATIVELY, this software may be distributed under the terms of the
16+
* GNU General Public License ("GPL") as published by the Free Software
17+
* Foundation, either version 2 of that License or (at your option) any
18+
* later version.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
21+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
* DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
24+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
32+
#ifndef __FM_SP_H
33+
#define __FM_SP_H
34+
35+
#include "fman.h"
36+
#include <linux/types.h>
37+
38+
#define ILLEGAL_BASE (~0)
39+
40+
/* defaults */
41+
#define DFLT_FM_SP_BUFFER_PREFIX_CONTEXT_DATA_ALIGN 64
42+
43+
/* Registers bit fields */
44+
#define FMAN_SP_EXT_BUF_POOL_EN_COUNTER 0x40000000
45+
#define FMAN_SP_EXT_BUF_POOL_VALID 0x80000000
46+
#define FMAN_SP_EXT_BUF_POOL_BACKUP 0x20000000
47+
#define FMAN_SP_DMA_ATTR_WRITE_OPTIMIZE 0x00100000
48+
#define FMAN_SP_SG_DISABLE 0x80000000
49+
50+
/* shifts */
51+
#define FMAN_SP_EXT_BUF_MARG_START_SHIFT 16
52+
#define FMAN_SP_DMA_ATTR_SWP_SHIFT 30
53+
#define FMAN_SP_IC_TO_EXT_SHIFT 16
54+
#define FMAN_SP_IC_FROM_INT_SHIFT 8
55+
56+
/* structure for defining internal context copying */
57+
struct fman_sp_int_context_data_copy {
58+
/* < Offset in External buffer to which internal
59+
* context is copied to (Rx) or taken from (Tx, Op).
60+
*/
61+
u16 ext_buf_offset;
62+
/* Offset within internal context to copy from
63+
* (Rx) or to copy to (Tx, Op).
64+
*/
65+
u8 int_context_offset;
66+
/* Internal offset size to be copied */
67+
u16 size;
68+
};
69+
70+
/* struct for defining external buffer margins */
71+
struct fman_sp_buf_margins {
72+
/* Number of bytes to be left at the beginning
73+
* of the external buffer (must be divisible by 16)
74+
*/
75+
u16 start_margins;
76+
/* number of bytes to be left at the end
77+
* of the external buffer(must be divisible by 16)
78+
*/
79+
u16 end_margins;
80+
};
81+
82+
struct fman_sp_buffer_offsets {
83+
u32 data_offset;
84+
u32 prs_result_offset;
85+
u32 time_stamp_offset;
86+
u32 hash_result_offset;
87+
};
88+
89+
int fman_sp_build_buffer_struct(struct fman_sp_int_context_data_copy
90+
*int_context_data_copy,
91+
struct fman_buffer_prefix_content
92+
*buffer_prefix_content,
93+
struct fman_sp_buf_margins *buf_margins,
94+
struct fman_sp_buffer_offsets
95+
*buffer_offsets,
96+
u8 *internal_buf_offset);
97+
98+
void fman_sp_set_buf_pools_in_asc_order_of_buf_sizes(struct fman_ext_pools
99+
*fm_ext_pools,
100+
u8 *ordered_array,
101+
u16 *sizes_array);
102+
103+
#endif /* __FM_SP_H */

0 commit comments

Comments
 (0)