net/ice/base: add parser runtime skeleton
[dpdk.git] / drivers / net / ice / base / ice_parser_rt.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2021 Intel Corporation
3  */
4
5 #include "ice_common.h"
6
7 #define GPR_HB_IDX      64
8 #define GPR_ERR_IDX     84
9 #define GPR_FLG_IDX     104
10 #define GPR_TSR_IDX     108
11 #define GPR_NN_IDX      109
12 #define GPR_HO_IDX      110
13 #define GPR_NP_IDX      111
14
15 static void _rt_tsr_set(struct ice_parser_rt *rt, u16 tsr)
16 {
17         rt->gpr[GPR_TSR_IDX] = tsr;
18 }
19
20 static void _rt_ho_set(struct ice_parser_rt *rt, u16 ho)
21 {
22         rt->gpr[GPR_HO_IDX] = ho;
23         ice_memcpy(&rt->gpr[GPR_HB_IDX], &rt->pkt_buf[ho], 32,
24                    ICE_NONDMA_TO_NONDMA);
25 }
26
27 static void _rt_np_set(struct ice_parser_rt *rt, u16 pc)
28 {
29         rt->gpr[GPR_NP_IDX] = pc;
30 }
31
32 static void _rt_nn_set(struct ice_parser_rt *rt, u16 node)
33 {
34         rt->gpr[GPR_NN_IDX] = node;
35 }
36
37 static void _rt_flag_set(struct ice_parser_rt *rt, int idx)
38 {
39         int y = idx / 16;
40         int x = idx % 16;
41
42         rt->gpr[GPR_FLG_IDX + y] |= (u16)(1 << x);
43 }
44
45 /**
46  * ice_parser_rt_reset - reset the parser runtime
47  * @rt: pointer to the parser runtime
48  */
49 void ice_parser_rt_reset(struct ice_parser_rt *rt)
50 {
51         struct ice_parser *psr = rt->psr;
52         struct ice_metainit_item *mi = &psr->mi_table[0];
53         int i;
54
55         ice_memset(rt, 0, sizeof(*rt), ICE_NONDMA_MEM);
56
57         _rt_tsr_set(rt, mi->tsr);
58         _rt_ho_set(rt, mi->ho);
59         _rt_np_set(rt, mi->pc);
60         _rt_nn_set(rt, mi->pg_rn);
61
62         for (i = 0; i < 64; i++) {
63                 if ((mi->flags & (1ul << i)) != 0ul)
64                         _rt_flag_set(rt, i);
65         }
66
67         rt->psr = psr;
68 }
69
70 /**
71  * ice_parser_rt_pktbuf_set - set a packet into parser runtime
72  * @rt: pointer to the parser runtime
73  * @pkt_buf: buffer with packet data
74  * @pkt_len: packet buffer length
75  */
76 void ice_parser_rt_pktbuf_set(struct ice_parser_rt *rt, const u8 *pkt_buf,
77                               int pkt_len)
78 {
79         int len = min(ICE_PARSER_MAX_PKT_LEN, pkt_len);
80         u16 ho = rt->gpr[GPR_HO_IDX];
81
82         ice_memcpy(rt->pkt_buf, pkt_buf, len, ICE_NONDMA_TO_NONDMA);
83         rt->pkt_len = pkt_len;
84
85         ice_memcpy(&rt->gpr[GPR_HB_IDX], &rt->pkt_buf[ho], 32,
86                    ICE_NONDMA_TO_NONDMA);
87 }
88
89 /**
90  * ice_parser_rt_execute - parser execution routine
91  * @rt: pointer to the parser runtime
92  * @rslt: input/output parameter to save parser result
93  */
94 enum ice_status ice_parser_rt_execute(struct ice_parser_rt *rt,
95                                       struct ice_parser_result *rslt)
96 {
97         return ICE_ERR_NOT_IMPL;
98 }