xref: /freebsd/sys/contrib/ncsw/Peripherals/FM/Pcd/fm_cc.h (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
1 /*
2  * Copyright 2008-2012 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 
34 /******************************************************************************
35  @File          fm_cc.h
36 
37  @Description   FM PCD CC ...
38 *//***************************************************************************/
39 #ifndef __FM_CC_H
40 #define __FM_CC_H
41 
42 #include "std_ext.h"
43 #include "error_ext.h"
44 #include "list_ext.h"
45 
46 #include "fm_pcd.h"
47 
48 
49 /***********************************************************************/
50 /*          Coarse classification defines                              */
51 /***********************************************************************/
52 
53 #define CC_MAX_NUM_OF_KEYS                  (FM_PCD_MAX_NUM_OF_KEYS + 1)
54 
55 #define CC_PC_FF_MACDST                     0x00
56 #define CC_PC_FF_MACSRC                     0x01
57 #define CC_PC_FF_ETYPE                      0x02
58 
59 #define CC_PC_FF_TCI1                       0x03
60 #define CC_PC_FF_TCI2                       0x04
61 
62 #define CC_PC_FF_MPLS1                      0x06
63 #define CC_PC_FF_MPLS_LAST                  0x07
64 
65 #define CC_PC_FF_IPV4DST1                   0x08
66 #define CC_PC_FF_IPV4DST2                   0x16
67 #define CC_PC_FF_IPV4IPTOS_TC1              0x09
68 #define CC_PC_FF_IPV4IPTOS_TC2              0x17
69 #define CC_PC_FF_IPV4PTYPE1                 0x0A
70 #define CC_PC_FF_IPV4PTYPE2                 0x18
71 #define CC_PC_FF_IPV4SRC1                   0x0b
72 #define CC_PC_FF_IPV4SRC2                   0x19
73 #define CC_PC_FF_IPV4SRC1_IPV4DST1          0x0c
74 #define CC_PC_FF_IPV4SRC2_IPV4DST2          0x1a
75 #define CC_PC_FF_IPV4TTL                    0x29
76 
77 
78 #define CC_PC_FF_IPTOS_IPV6TC1_IPV6FLOW1    0x0d /*TODO - CLASS - what is it? TOS*/
79 #define CC_PC_FF_IPTOS_IPV6TC2_IPV6FLOW2    0x1b
80 #define CC_PC_FF_IPV6PTYPE1                 0x0e
81 #define CC_PC_FF_IPV6PTYPE2                 0x1c
82 #define CC_PC_FF_IPV6DST1                   0x0f
83 #define CC_PC_FF_IPV6DST2                   0x1d
84 #define CC_PC_FF_IPV6SRC1                   0x10
85 #define CC_PC_FF_IPV6SRC2                   0x1e
86 #define CC_PC_FF_IPV6HOP_LIMIT              0x2a
87 #define CC_PC_FF_IPPID                      0x24
88 #define CC_PC_FF_IPDSCP                     0x76
89 
90 #define CC_PC_FF_GREPTYPE                   0x11
91 
92 #define CC_PC_FF_MINENCAP_PTYPE             0x12
93 #define CC_PC_FF_MINENCAP_IPDST             0x13
94 #define CC_PC_FF_MINENCAP_IPSRC             0x14
95 #define CC_PC_FF_MINENCAP_IPSRC_IPDST       0x15
96 
97 #define CC_PC_FF_L4PSRC                     0x1f
98 #define CC_PC_FF_L4PDST                     0x20
99 #define CC_PC_FF_L4PSRC_L4PDST              0x21
100 
101 #define CC_PC_FF_PPPPID                     0x05
102 
103 #define CC_PC_PR_SHIM1                      0x22
104 #define CC_PC_PR_SHIM2                      0x23
105 
106 #define CC_PC_GENERIC_WITHOUT_MASK          0x27
107 #define CC_PC_GENERIC_WITH_MASK             0x28
108 #define CC_PC_GENERIC_IC_GMASK              0x2B
109 #define CC_PC_GENERIC_IC_HASH_INDEXED       0x2C
110 #define CC_PC_GENERIC_IC_AGING_MASK         0x2D
111 
112 #define CC_PR_OFFSET                        0x25
113 #define CC_PR_WITHOUT_OFFSET                0x26
114 
115 #define CC_PC_PR_ETH_OFFSET                 19
116 #define CC_PC_PR_USER_DEFINED_SHIM1_OFFSET  16
117 #define CC_PC_PR_USER_DEFINED_SHIM2_OFFSET  17
118 #define CC_PC_PR_USER_LLC_SNAP_OFFSET       20
119 #define CC_PC_PR_VLAN1_OFFSET               21
120 #define CC_PC_PR_VLAN2_OFFSET               22
121 #define CC_PC_PR_PPPOE_OFFSET               24
122 #define CC_PC_PR_MPLS1_OFFSET               25
123 #define CC_PC_PR_MPLS_LAST_OFFSET           26
124 #define CC_PC_PR_IP1_OFFSET                 27
125 #define CC_PC_PR_IP_LAST_OFFSET             28
126 #define CC_PC_PR_MINENC_OFFSET              28
127 #define CC_PC_PR_L4_OFFSET                  30
128 #define CC_PC_PR_GRE_OFFSET                 29
129 #define CC_PC_PR_ETYPE_LAST_OFFSET          23
130 #define CC_PC_PR_NEXT_HEADER_OFFSET         31
131 
132 #define CC_PC_ILLEGAL                       0xff
133 #define CC_SIZE_ILLEGAL                     0
134 
135 #define FM_PCD_CC_KEYS_MATCH_TABLE_ALIGN    16
136 #define FM_PCD_CC_AD_TABLE_ALIGN            16
137 #define FM_PCD_CC_AD_ENTRY_SIZE             16
138 #define FM_PCD_CC_NUM_OF_KEYS               255
139 #define FM_PCD_CC_TREE_ADDR_ALIGN           256
140 
141 #define FM_PCD_AD_RESULT_CONTRL_FLOW_TYPE   0x00000000
142 #define FM_PCD_AD_RESULT_DATA_FLOW_TYPE     0x80000000
143 #define FM_PCD_AD_RESULT_PLCR_DIS           0x20000000
144 #define FM_PCD_AD_RESULT_EXTENDED_MODE      0x80000000
145 #define FM_PCD_AD_RESULT_NADEN              0x20000000
146 #define FM_PCD_AD_RESULT_STATISTICS_EN      0x40000000
147 
148 #define FM_PCD_AD_CONT_LOOKUP_TYPE          0x40000000
149 #define FM_PCD_AD_CONT_LOOKUP_LCL_MASK      0x00800000
150 
151 #define FM_PCD_AD_STATS_TYPE                0x40000000
152 #define FM_PCD_AD_STATS_FLR_ADDR_MASK       0x00FFFFFF
153 #define FM_PCD_AD_STATS_COUNTERS_ADDR_MASK  0x00FFFFFF
154 #define FM_PCD_AD_STATS_NEXT_ACTION_MASK    0xFFFF0000
155 #define FM_PCD_AD_STATS_NEXT_ACTION_SHIFT   12
156 #define FM_PCD_AD_STATS_NAD_EN              0x00008000
157 #define FM_PCD_AD_STATS_OP_CODE             0x00000036
158 #define FM_PCD_AD_STATS_FLR_EN              0x00004000
159 #define FM_PCD_AD_STATS_COND_EN             0x00002000
160 
161 
162 
163 #define FM_PCD_AD_BYPASS_TYPE               0xc0000000
164 
165 #define FM_PCD_AD_TYPE_MASK                 0xc0000000
166 #define FM_PCD_AD_OPCODE_MASK               0x0000000f
167 
168 #define FM_PCD_AD_PROFILEID_FOR_CNTRL_SHIFT 16
169 #if (DPAA_VERSION >= 11)
170 #define FM_PCD_AD_RESULT_VSP_SHIFT           24
171 #define FM_PCD_AD_RESULT_NO_OM_VSPE          0x02000000
172 #define FM_PCD_AD_RESULT_VSP_MASK            0x3f
173 #define FM_PCD_AD_NCSPFQIDM_MASK             0x80000000
174 #endif /* (DPAA_VERSION >= 11) */
175 
176 #define GLBL_MASK_FOR_HASH_INDEXED          0xfff00000
177 #define CC_GLBL_MASK_SIZE                   4
178 #define CC_AGING_MASK_SIZE                  4
179 
180 typedef uint32_t ccPrivateInfo_t; /**< private info of CC: */
181 
182 #define CC_PRIVATE_INFO_NONE                       0
183 #define CC_PRIVATE_INFO_IC_HASH_INDEX_LOOKUP       0x80000000
184 #define CC_PRIVATE_INFO_IC_HASH_EXACT_MATCH        0x40000000
185 #define CC_PRIVATE_INFO_IC_KEY_EXACT_MATCH         0x20000000
186 #define CC_PRIVATE_INFO_IC_DEQ_FQID_INDEX_LOOKUP   0x10000000
187 
188 #define CC_BUILD_AGING_MASK(numOfKeys)      ((((1LL << ((numOfKeys) + 1)) - 1)) << (31 - (numOfKeys)))
189 /***********************************************************************/
190 /*          Memory map                                                 */
191 /***********************************************************************/
192 #if defined(__MWERKS__) && !defined(__GNUC__)
193 #pragma pack(push,1)
194 #endif /* defined(__MWERKS__) && ... */
195 
196 typedef struct
197 {
198     volatile uint32_t fqid;
199     volatile uint32_t plcrProfile;
200     volatile uint32_t nia;
201     volatile uint32_t res;
202 } t_AdOfTypeResult;
203 
204 typedef struct
205 {
206     volatile uint32_t ccAdBase;
207     volatile uint32_t matchTblPtr;
208     volatile uint32_t pcAndOffsets;
209     volatile uint32_t gmask;
210 } t_AdOfTypeContLookup;
211 
212 typedef struct
213 {
214     volatile uint32_t profileTableAddr;
215     volatile uint32_t reserved;
216     volatile uint32_t nextActionIndx;
217     volatile uint32_t statsTableAddr;
218 } t_AdOfTypeStats;
219 
220 typedef union
221 {
222     volatile t_AdOfTypeResult        adResult;
223     volatile t_AdOfTypeContLookup    adContLookup;
224 } t_Ad;
225 
226 #if defined(__MWERKS__) && !defined(__GNUC__)
227 #pragma pack(pop)
228 #endif /* defined(__MWERKS__) && ... */
229 
230 
231 /***********************************************************************/
232 /*  Driver's internal structures                                       */
233 /***********************************************************************/
234 
235 typedef struct t_FmPcdStatsObj
236 {
237     t_Handle        h_StatsAd;
238     t_Handle        h_StatsCounters;
239     t_List          node;
240 } t_FmPcdStatsObj;
241 
242 typedef struct
243 {
244     uint8_t                     key[FM_PCD_MAX_SIZE_OF_KEY];
245     uint8_t                     mask[FM_PCD_MAX_SIZE_OF_KEY];
246 
247     t_FmPcdCcNextEngineParams   nextEngineParams;
248     uint32_t                    requiredAction;
249     uint32_t                    shadowAction;
250 
251     t_FmPcdStatsObj             *p_StatsObj;
252 
253 } t_FmPcdCcKeyAndNextEngineParams;
254 
255 typedef struct
256 {
257     t_Handle        p_Ad;
258     e_FmPcdEngine   fmPcdEngine;
259     bool            adAllocated;
260     bool            isTree;
261 
262     uint32_t        myInfo;
263     t_List          *h_CcNextNodesLst;
264     t_Handle        h_AdditionalInfo;
265     t_Handle        h_Node;
266 } t_FmPcdModifyCcAdditionalParams;
267 
268 typedef struct
269 {
270     t_Handle            p_AdTableNew;
271     t_Handle            p_KeysMatchTableNew;
272     t_Handle            p_AdTableOld;
273     t_Handle            p_KeysMatchTableOld;
274     uint16_t            numOfKeys;
275     t_Handle            h_CurrentNode;
276     uint16_t            savedKeyIndex;
277     t_Handle            h_NodeForAdd;
278     t_Handle            h_NodeForRmv;
279     t_Handle            h_ManipForRmv;
280     t_Handle            h_ManipForAdd;
281     t_FmPcdStatsObj     *p_StatsObjForRmv;
282 #if (DPAA_VERSION >= 11)
283     t_Handle            h_FrmReplicForAdd;
284     t_Handle            h_FrmReplicForRmv;
285 #endif /* (DPAA_VERSION >= 11) */
286     bool                tree;
287 
288     t_FmPcdCcKeyAndNextEngineParams  keyAndNextEngineParams[CC_MAX_NUM_OF_KEYS];
289 } t_FmPcdModifyCcKeyAdditionalParams;
290 
291 typedef struct
292 {
293     t_Handle    h_Manip;
294     t_Handle    h_CcNode;
295 } t_CcNextEngineInfo;
296 
297 typedef struct
298 {
299     uint16_t            numOfKeys;
300     uint16_t            maxNumOfKeys;
301 
302     bool                maskSupport;
303     uint32_t            keysMatchTableMaxSize;
304 
305     e_FmPcdCcStatsMode  statisticsMode;
306     uint32_t            numOfStatsFLRs;
307     uint32_t            countersArraySize;
308 
309     bool                isHashBucket;               /**< Valid for match table node that is a bucket of a hash table only */
310     t_Handle            h_MissStatsCounters;        /**< Valid for hash table node and match table that is a bucket;
311                                                          Holds the statistics counters allocated by the hash table and
312                                                          are shared by all hash table buckets; */
313     t_Handle            h_PrivMissStatsCounters;    /**< Valid for match table node that is a bucket of a hash table only;
314                                                          Holds the statistics counters that were allocated for this node
315                                                          and replaced by the shared counters (allocated by the hash table); */
316     bool                statsEnForMiss;             /**< Valid for hash table node only; TRUE is statistics are currently
317                                                          enabled for hash 'miss', FALSE otherwise; This parameter effects the
318                                                          returned statistics count to user, statistics AD always present for 'miss'
319                                                          for all hash buckets; */
320     bool                glblMaskUpdated;
321     t_Handle            p_GlblMask;
322     bool                lclMask;
323     uint8_t             parseCode;
324     uint8_t             offset;
325     uint8_t             prsArrayOffset;
326     bool                ctrlFlow;
327     uint16_t            owners;
328 
329     uint8_t             ccKeySizeAccExtraction;
330     uint8_t             sizeOfExtraction;
331     uint8_t             glblMaskSize;
332 
333     t_Handle            h_KeysMatchTable;
334     t_Handle            h_AdTable;
335     t_Handle            h_StatsAds;
336     t_Handle            h_TmpAd;
337     t_Handle            h_Ad;
338     t_Handle            h_StatsFLRs;
339 
340     t_List              availableStatsLst;
341 
342     t_List              ccPrevNodesLst;
343 
344     t_List              ccTreeIdLst;
345     t_List              ccTreesLst;
346 
347     t_Handle            h_FmPcd;
348     uint32_t            shadowAction;
349     uint8_t             userSizeOfExtraction;
350     uint8_t             userOffset;
351     uint8_t             kgHashShift;            /* used in hash-table */
352 
353     t_Handle            h_Spinlock;
354 
355     t_FmPcdCcKeyAndNextEngineParams keyAndNextEngineParams[CC_MAX_NUM_OF_KEYS];
356 } t_FmPcdCcNode;
357 
358 typedef struct
359 {
360     t_FmPcdCcNode       *p_FmPcdCcNode;
361     bool                occupied;
362     uint16_t            owners;
363     volatile bool       lock;
364 } t_FmPcdCcNodeArray;
365 
366 typedef struct
367 {
368     uint8_t             numOfEntriesInGroup;
369     uint32_t            totalBitsMask;
370     uint8_t             baseGroupEntry;
371 } t_FmPcdCcGroupParam;
372 
373 typedef struct
374 {
375     t_Handle            h_FmPcd;
376     uint8_t             netEnvId;
377     uintptr_t           ccTreeBaseAddr;
378     uint8_t             numOfGrps;
379     t_FmPcdCcGroupParam fmPcdGroupParam[FM_PCD_MAX_NUM_OF_CC_GROUPS];
380     t_List              fmPortsLst;
381     t_FmPcdLock         *p_Lock;
382     uint8_t             numOfEntries;
383     uint16_t            owners;
384     t_Handle            h_FmPcdCcSavedManipParams;
385     bool                modifiedState;
386     uint32_t            requiredAction;
387     t_Handle            h_IpReassemblyManip;
388     t_Handle            h_CapwapReassemblyManip;
389 
390     t_FmPcdCcKeyAndNextEngineParams keyAndNextEngineParams[FM_PCD_MAX_NUM_OF_CC_GROUPS];
391 } t_FmPcdCcTree;
392 
393 
394 t_Error     FmPcdCcNodeTreeTryLock(t_Handle h_FmPcd,t_Handle h_FmPcdCcNode, t_List *p_List);
395 void        FmPcdCcNodeTreeReleaseLock(t_Handle h_FmPcd, t_List *p_List);
396 t_Error     FmPcdUpdateCcShadow (t_FmPcd *p_FmPcd, uint32_t size, uint32_t align);
397 
398 
399 #endif /* __FM_CC_H */
400