update for HEAD-2003091401
[reactos.git] / drivers / net / npf / tme.h
1 /*
2  * Copyright (c) 2001
3  *  Politecnico di Torino.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that: (1) source code distributions
7  * retain the above copyright notice and this paragraph in its entirety, (2)
8  * distributions including binary code include the above copyright notice and
9  * this paragraph in its entirety in the documentation or other materials
10  * provided with the distribution, and (3) all advertising materials mentioning
11  * features or use of this software display the following acknowledgement:
12  * ``This product includes software developed by the Politecnico
13  * di Torino, and its contributors.'' Neither the name of
14  * the University nor the names of its contributors may be used to endorse
15  * or promote products derived from this software without specific prior
16  * written permission.
17  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20  */
21
22 #ifndef __tme_include_
23 #define __tme_include_
24
25 #ifdef WIN_NT_DRIVER
26
27 #include "ntddk.h"
28 #include "memory_t.h"
29 #include "time_calls.h"
30 #endif /*WIN_NT_DRIVER*/
31
32 #ifdef WIN32
33 #include "memory_t.h"
34 #include "time_calls.h"
35 #endif /*WIN32*/
36
37
38
39 #ifdef __FreeBSD__
40
41 #ifdef _KERNEL
42 #include <net/tme/time_calls.h>
43 #else
44 #include <tme/time_calls.h>
45 #endif
46
47 #endif
48
49 /* error codes */
50 #define     TME_ERROR           0   
51 #define     TME_SUCCESS         1
52 #define     TME_TRUE            2
53 #define     TME_FALSE           3
54
55 /* some constants */
56 #define     DEFAULT_MEM_EX_SIZE     65536
57 #define     MAX_TME_DATA_BLOCKS     4
58 #define     TME_NONE_ACTIVE         0xffffffff
59 #define     DELTA_READ              2  /* secs */
60
61 #define     TME_LUT_ENTRIES                 0x00000000  
62 #define     TME_MAX_FILL_STATE              0x00000001  /*potrebbe servire per un thread a passive level!?!?! */
63 #define     TME_REHASHING_VALUE             0x00000002  
64 #define     TME_KEY_LEN                     0x00000003
65 #define     TME_SHARED_MEMORY_BLOCKS        0x00000004
66 #define     TME_FILLED_ENTRIES              0x00000005
67 #define     TME_BLOCK_SIZE                  0x00000006
68 #define     TME_EXTRA_SEGMENT_SIZE          0x00000007
69 #define     TME_LOOKUP_CODE                 0x00000008
70 #define     TME_OUT_LUT_EXEC                0x00000009
71 #define     TME_FILLED_BLOCKS               0x0000000a
72 #define     TME_DEFAULT_EXEC                0x0000000b
73 #define     TME_LUT_BASE_ADDRESS            0x0000000c
74 #define     TME_SHARED_MEMORY_BASE_ADDRESS  0x0000000d
75 #define     TME_EXTRA_SEGMENT_BASE_ADDRESS  0x0000000e
76 #define     TME_LAST_FOUND                  0x0000000f   /* contains the offset of the last found entry */
77 #define     TME_LAST_FOUND_BLOCK            0x00000010
78 /* TME default values */
79 #define     TME_LUT_ENTRIES_DEFAULT             32007
80 #define     TME_REHASHING_VALUE_DEFAULT         1
81 #define     TME_SHARED_MEMORY_BLOCKS_DEFAULT    16000
82 #define     TME_BLOCK_SIZE_DEFAULT              64
83 #define     TME_EXTRA_SEGMENT_SIZE_DEFAULT      0
84 #define     TME_LOOKUP_CODE_DEFAULT             0
85 #define     TME_OUT_LUT_EXEC_DEFAULT            0
86 #define     TME_DEFAULT_EXEC_DEFAULT            0
87 #define     TME_MAX_FILL_STATE_DEFAULT          15000
88
89 #define IS_VALIDATED(src,index) (src&(1<<index))
90
91 #define VALIDATE(src,index) src|=(1<<index);
92
93
94 #define FORCE_NO_DELETION(timestamp)  (struct timeval*)(timestamp)->tv_sec=0x7fffffff;
95
96 /* TME callback prototypes */
97 #ifndef __GNUC__
98 typedef uint32 (*lut_fcn)(uint8 *key, struct __TME_DATA *data,MEM_TYPE *mem_ex, struct time_conv *time_ref );
99 typedef uint32 (*exec_fcn)(uint8 *block, uint32 pkt_size, struct __TME_DATA *data, MEM_TYPE *mem_ex, uint8 *mem_data);
100 #else
101 typedef uint32 (*lut_fcn)(uint8 *key, void *data,MEM_TYPE *mem_ex, struct time_conv *time_ref );
102 typedef uint32 (*exec_fcn)(uint8 *block, uint32 pkt_size, void *data, MEM_TYPE *mem_ex, uint8 *mem_data);
103 #endif
104
105 /* DO NOT MODIFY THIS STRUCTURE!!!! GV */
106 typedef struct __RECORD
107
108 {
109     uint32 block;
110     uint32 exec_fcn;
111 }
112     RECORD, *PRECORD;
113
114 /* TME data registers */
115 struct __TME_DATA
116 {
117     uint32 lut_entries;
118     uint32 max_fill_state;
119     uint32 rehashing_value;
120     uint32 key_len;
121     uint32 shared_memory_blocks;
122     uint32 filled_entries;
123     uint32 block_size;
124     uint32 extra_segment_size;
125     uint32 filled_blocks;
126     lut_fcn lookup_code;
127     uint32 default_exec;
128     uint32 out_lut_exec;
129     uint8 *lut_base_address;
130     uint8 *shared_memory_base_address;
131     uint8 *extra_segment_base_address;
132     struct timeval last_read;
133     uint32  enable_deletion;
134     uint8 *last_found;
135 };
136
137 typedef struct __TME_DATA TME_DATA,*PTME_DATA;
138
139
140
141 /* TME core */
142 typedef struct __TME_CORE
143 {
144     uint32      working;
145     uint32      active;
146     uint32      validated_blocks;
147     TME_DATA    block_data[MAX_TME_DATA_BLOCKS];
148     uint32      active_read;
149     
150 } TME_CORE, *PTME_CORE;
151
152 static __inline int32 IS_DELETABLE(void *timestamp, TME_DATA *data)
153 {
154     struct timeval *ts=(struct timeval*)timestamp;
155
156     if (data->enable_deletion==FALSE)
157         return FALSE;
158     if (data->filled_entries<data->max_fill_state)
159         return FALSE;
160     if ((ts->tv_sec+DELTA_READ)<data->last_read.tv_sec)
161         return TRUE;
162     return FALSE;
163 }
164
165 /* functions to manage TME */
166 uint32 init_tme_block(TME_CORE *tme, uint32 block);
167 uint32 validate_tme_block(MEM_TYPE *mem_ex, TME_CORE *tme, uint32 block, uint32 mem_ex_offset);
168 uint32 lookup_frontend(MEM_TYPE *mem_ex, TME_CORE *tme,uint32 mem_ex_offset, struct time_conv *time_ref);
169 uint32 execute_frontend(MEM_TYPE *mem_ex, TME_CORE *tme, uint32 pkt_size,uint32 offset);
170 uint32 set_active_tme_block(TME_CORE *tme, uint32 block);
171 uint32 init_extended_memory(uint32 size, MEM_TYPE *mem_ex);
172 uint32 reset_tme(TME_CORE *tme);
173 uint32 get_tme_block_register(TME_DATA *data,MEM_TYPE *mem_ex,uint32 rgstr,uint32 *rval);
174 uint32 set_tme_block_register(TME_DATA *data,MEM_TYPE *mem_ex,uint32 rgstr,uint32 value, int32 init);
175 uint32 set_active_read_tme_block(TME_CORE *tme, uint32 block);
176 uint32 set_autodeletion(TME_DATA *data, uint32 value);
177
178 /* function mappers */
179 lut_fcn lut_fcn_mapper(uint32 index);
180 exec_fcn exec_fcn_mapper(uint32 index);
181
182 #endif
183