os/boardsupport/emulator/emulatorbsp/wpdpack/include/tme.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2  * Copyright (c) 2001 - 2003
     3  * NetGroup, Politecnico di Torino (Italy)
     4  * All rights reserved.
     5  *
     6  * Redistribution and use in source and binary forms, with or without
     7  * modification, are permitted provided that the following conditions
     8  * are met:
     9  *
    10  * 1. Redistributions of source code must retain the above copyright
    11  * notice, this list of conditions and the following disclaimer.
    12  * 2. Redistributions in binary form must reproduce the above copyright
    13  * notice, this list of conditions and the following disclaimer in the
    14  * documentation and/or other materials provided with the distribution.
    15  * 3. Neither the name of the Politecnico di Torino nor the names of its
    16  * contributors may be used to endorse or promote products derived from
    17  * this software without specific prior written permission.
    18  *
    19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    30  *
    31  */
    32 
    33 #ifndef __tme_include_
    34 #define __tme_include_
    35 
    36 #ifdef WIN_NT_DRIVER
    37 #include "ndis.h"
    38 #else
    39 #include <windows.h>
    40 #endif /*WIN_NT_DRIVER*/
    41 
    42 #include "memory_t.h"
    43 #include "time_calls.h"
    44 
    45 
    46 /* error codes */
    47 #define		TME_ERROR			0	
    48 #define		TME_SUCCESS			1
    49 #define		TME_TRUE			2
    50 #define		TME_FALSE			3
    51 
    52 /* some constants */
    53 #define		DEFAULT_MEM_EX_SIZE		65536
    54 #define		MAX_TME_DATA_BLOCKS		4
    55 #define		TME_NONE_ACTIVE			0xffffffff
    56 #define		DELTA_READ				2  /* secs */
    57 
    58 #define		TME_LUT_ENTRIES					0x00000000  
    59 #define		TME_MAX_FILL_STATE				0x00000001  /*potrebbe servire per un thread a passive level!?!?! */
    60 #define		TME_REHASHING_VALUE				0x00000002	
    61 #define		TME_KEY_LEN  					0x00000003
    62 #define		TME_SHARED_MEMORY_BLOCKS		0x00000004
    63 #define		TME_FILLED_ENTRIES				0x00000005
    64 #define		TME_BLOCK_SIZE					0x00000006
    65 #define		TME_EXTRA_SEGMENT_SIZE			0x00000007
    66 #define		TME_LOOKUP_CODE					0x00000008
    67 #define		TME_OUT_LUT_EXEC				0x00000009
    68 #define		TME_FILLED_BLOCKS				0x0000000a
    69 #define		TME_DEFAULT_EXEC				0x0000000b
    70 #define		TME_LUT_BASE_ADDRESS			0x0000000c
    71 #define		TME_SHARED_MEMORY_BASE_ADDRESS	0x0000000d
    72 #define		TME_EXTRA_SEGMENT_BASE_ADDRESS	0x0000000e
    73 #define		TME_LAST_FOUND					0x0000000f   /* contains the offset of the last found entry */
    74 #define		TME_LAST_FOUND_BLOCK			0x00000010
    75 /* TME default values */
    76 #define		TME_LUT_ENTRIES_DEFAULT				32007
    77 #define		TME_REHASHING_VALUE_DEFAULT			1
    78 #define		TME_SHARED_MEMORY_BLOCKS_DEFAULT	16000
    79 #define		TME_BLOCK_SIZE_DEFAULT				64
    80 #define		TME_EXTRA_SEGMENT_SIZE_DEFAULT		0
    81 #define		TME_LOOKUP_CODE_DEFAULT				0
    82 #define		TME_OUT_LUT_EXEC_DEFAULT			0
    83 #define		TME_DEFAULT_EXEC_DEFAULT			0
    84 #define		TME_MAX_FILL_STATE_DEFAULT			15000
    85 
    86 #define IS_VALIDATED(src,index) (src&(1<<index))
    87 
    88 #define VALIDATE(src,index) src|=(1<<index);
    89 
    90 
    91 #define FORCE_NO_DELETION(timestamp)  (struct timeval*)(timestamp)->tv_sec=0x7fffffff;
    92 
    93 struct __TME_DATA;
    94 
    95 /* TME callback prototypes */
    96 typedef uint32 (*lut_fcn)(uint8 *key, struct __TME_DATA *data,MEM_TYPE *mem_ex, struct time_conv *time_ref );
    97 typedef uint32 (*exec_fcn)(uint8 *block, uint32 pkt_size, struct __TME_DATA *data, MEM_TYPE *mem_ex, uint8 *mem_data);
    98 
    99 /* DO NOT MODIFY THIS STRUCTURE!!!! GV */
   100 typedef struct __RECORD
   101 
   102 {
   103 	uint32 block;
   104 	uint32 exec_fcn;
   105 }
   106 	RECORD, *PRECORD;
   107 
   108 /* TME data registers */
   109 struct __TME_DATA
   110 {
   111 	uint32 lut_entries;
   112 	uint32 max_fill_state;
   113 	uint32 rehashing_value;
   114 	uint32 key_len;
   115 	uint32 shared_memory_blocks;
   116 	uint32 filled_entries;
   117 	uint32 block_size;
   118 	uint32 extra_segment_size;
   119 	uint32 filled_blocks;
   120 	lut_fcn lookup_code;
   121 	uint32 default_exec;
   122 	uint32 out_lut_exec;
   123 	uint8 *lut_base_address;
   124 	uint8 *shared_memory_base_address;
   125 	uint8 *extra_segment_base_address;
   126 	struct timeval last_read;
   127 	uint32	enable_deletion;
   128 	uint8 *last_found;
   129 };
   130 
   131 typedef struct __TME_DATA TME_DATA,*PTME_DATA;
   132 
   133 
   134 
   135 /* TME core */
   136 typedef struct __TME_CORE
   137 {
   138 	uint32      working;
   139 	uint32		active;
   140 	uint32		validated_blocks;
   141 	TME_DATA	block_data[MAX_TME_DATA_BLOCKS];
   142 	uint32		active_read;
   143 	
   144 } TME_CORE, *PTME_CORE;
   145 
   146 static __inline int32 IS_DELETABLE(void *timestamp, TME_DATA *data)
   147 {
   148 	struct timeval *ts=(struct timeval*)timestamp;
   149 
   150 	if (data->enable_deletion==FALSE)
   151 		return FALSE;
   152 	if (data->filled_entries<data->max_fill_state)
   153 		return FALSE;
   154 	if ((ts->tv_sec+DELTA_READ)<data->last_read.tv_sec)
   155 		return TRUE;
   156 	return FALSE;
   157 }
   158 
   159 /* functions to manage TME */
   160 uint32 init_tme_block(TME_CORE *tme, uint32 block);
   161 uint32 validate_tme_block(MEM_TYPE *mem_ex, TME_CORE *tme, uint32 block, uint32 mem_ex_offset);
   162 uint32 lookup_frontend(MEM_TYPE *mem_ex, TME_CORE *tme,uint32 mem_ex_offset, struct time_conv *time_ref);
   163 uint32 execute_frontend(MEM_TYPE *mem_ex, TME_CORE *tme, uint32 pkt_size,uint32 offset);
   164 uint32 set_active_tme_block(TME_CORE *tme, uint32 block);
   165 uint32 init_extended_memory(uint32 size, MEM_TYPE *mem_ex);
   166 uint32 reset_tme(TME_CORE *tme);
   167 uint32 get_tme_block_register(TME_DATA *data,MEM_TYPE *mem_ex,uint32 rgstr,uint32 *rval);
   168 uint32 set_tme_block_register(TME_DATA *data,MEM_TYPE *mem_ex,uint32 rgstr,uint32 value, int32 init);
   169 uint32 set_active_read_tme_block(TME_CORE *tme, uint32 block);
   170 uint32 set_autodeletion(TME_DATA *data, uint32 value);
   171 
   172 /* function mappers */
   173 lut_fcn lut_fcn_mapper(uint32 index);
   174 exec_fcn exec_fcn_mapper(uint32 index);
   175 
   176 #endif