2391e40168433e7f39e96e163ecf4d7450bcd5ee
[deb_dpdk.git] / drivers / net / dpaa2 / mc / fsl_dpkg.h
1 /*-
2  * This file is provided under a dual BSD/GPLv2 license. When using or
3  * redistributing this file, you may do so under either license.
4  *
5  *   BSD LICENSE
6  *
7  * Copyright 2013-2015 Freescale Semiconductor Inc.
8  * Copyright 2016 NXP.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  * * Neither the name of the above-listed copyright holders nor the
18  * names of any contributors may be used to endorse or promote products
19  * derived from this software without specific prior written permission.
20  *
21  *   GPL LICENSE SUMMARY
22  *
23  * ALTERNATIVELY, this software may be distributed under the terms of the
24  * GNU General Public License ("GPL") as published by the Free Software
25  * Foundation, either version 2 of that License or (at your option) any
26  * later version.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
32  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  */
40 #ifndef __FSL_DPKG_H_
41 #define __FSL_DPKG_H_
42
43 #include <fsl_net.h>
44
45 /* Data Path Key Generator API
46  * Contains initialization APIs and runtime APIs for the Key Generator
47  */
48
49 /** Key Generator properties */
50
51 /**
52  * Number of masks per key extraction
53  */
54 #define DPKG_NUM_OF_MASKS               4
55 /**
56  * Number of extractions per key profile
57  */
58 #define DPKG_MAX_NUM_OF_EXTRACTS        10
59
60 /**
61  * enum dpkg_extract_from_hdr_type - Selecting extraction by header types
62  * @DPKG_FROM_HDR: Extract selected bytes from header, by offset
63  * @DPKG_FROM_FIELD: Extract selected bytes from header, by offset from field
64  * @DPKG_FULL_FIELD: Extract a full field
65  */
66 enum dpkg_extract_from_hdr_type {
67         DPKG_FROM_HDR = 0,
68         DPKG_FROM_FIELD = 1,
69         DPKG_FULL_FIELD = 2
70 };
71
72 /**
73  * enum dpkg_extract_type - Enumeration for selecting extraction type
74  * @DPKG_EXTRACT_FROM_HDR: Extract from the header
75  * @DPKG_EXTRACT_FROM_DATA: Extract from data not in specific header
76  * @DPKG_EXTRACT_FROM_PARSE: Extract from parser-result;
77  *      e.g. can be used to extract header existence;
78  *      please refer to 'Parse Result definition' section in the parser BG
79  */
80 enum dpkg_extract_type {
81         DPKG_EXTRACT_FROM_HDR = 0,
82         DPKG_EXTRACT_FROM_DATA = 1,
83         DPKG_EXTRACT_FROM_PARSE = 3
84 };
85
86 /**
87  * struct dpkg_mask - A structure for defining a single extraction mask
88  * @mask: Byte mask for the extracted content
89  * @offset: Offset within the extracted content
90  */
91 struct dpkg_mask {
92         uint8_t mask;
93         uint8_t offset;
94 };
95
96 /**
97  * struct dpkg_extract - A structure for defining a single extraction
98  * @type: Determines how the union below is interpreted:
99  *              DPKG_EXTRACT_FROM_HDR: selects 'from_hdr';
100  *              DPKG_EXTRACT_FROM_DATA: selects 'from_data';
101  *              DPKG_EXTRACT_FROM_PARSE: selects 'from_parse'
102  * @extract: Selects extraction method
103  * @num_of_byte_masks: Defines the number of valid entries in the array below;
104  *              This is also the number of bytes to be used as masks
105  * @masks: Masks parameters
106  */
107 struct dpkg_extract {
108         enum dpkg_extract_type type;
109         /**
110          * union extract - Selects extraction method
111          * @from_hdr - Used when 'type = DPKG_EXTRACT_FROM_HDR'
112          * @from_data - Used when 'type = DPKG_EXTRACT_FROM_DATA'
113          * @from_parse - Used when 'type = DPKG_EXTRACT_FROM_PARSE'
114          */
115         union {
116                 /**
117                  * struct from_hdr - Used when 'type = DPKG_EXTRACT_FROM_HDR'
118                  * @prot: Any of the supported headers
119                  * @type: Defines the type of header extraction:
120                  *      DPKG_FROM_HDR: use size & offset below;
121                  *      DPKG_FROM_FIELD: use field, size and offset below;
122                  *      DPKG_FULL_FIELD: use field below
123                  * @field: One of the supported fields (NH_FLD_)
124                  *
125                  * @size: Size in bytes
126                  * @offset: Byte offset
127                  * @hdr_index: Clear for cases not listed below;
128                  *      Used for protocols that may have more than a single
129                  *      header, 0 indicates an outer header;
130                  *      Supported protocols (possible values):
131                  *      NET_PROT_VLAN (0, HDR_INDEX_LAST);
132                  *      NET_PROT_MPLS (0, 1, HDR_INDEX_LAST);
133                  *      NET_PROT_IP(0, HDR_INDEX_LAST);
134                  *      NET_PROT_IPv4(0, HDR_INDEX_LAST);
135                  *      NET_PROT_IPv6(0, HDR_INDEX_LAST);
136                  */
137
138                 struct {
139                         enum net_prot                   prot;
140                         enum dpkg_extract_from_hdr_type type;
141                         uint32_t                        field;
142                         uint8_t                         size;
143                         uint8_t                         offset;
144                         uint8_t                         hdr_index;
145                 } from_hdr;
146                 /**
147                  * struct from_data
148                  *      Used when 'type = DPKG_EXTRACT_FROM_DATA'
149                  * @size: Size in bytes
150                  * @offset: Byte offset
151                  */
152                 struct {
153                         uint8_t size;
154                         uint8_t offset;
155                 } from_data;
156
157                 /**
158                  * struct from_parse
159                  *      Used when 'type = DPKG_EXTRACT_FROM_PARSE'
160                  * @size: Size in bytes
161                  * @offset: Byte offset
162                  */
163                 struct {
164                         uint8_t size;
165                         uint8_t offset;
166                 } from_parse;
167         } extract;
168
169         uint8_t                 num_of_byte_masks;
170         struct dpkg_mask        masks[DPKG_NUM_OF_MASKS];
171 };
172
173 /**
174  * struct dpkg_profile_cfg - A structure for defining a full Key Generation
175  *                              profile (rule)
176  * @num_extracts: Defines the number of valid entries in the array below
177  * @extracts: Array of required extractions
178  */
179 struct dpkg_profile_cfg {
180         uint8_t num_extracts;
181         struct dpkg_extract extracts[DPKG_MAX_NUM_OF_EXTRACTS];
182 };
183
184 #endif /* __FSL_DPKG_H_ */