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