]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/net/npe/IxEthDBSearch.c
imx6 SION bit has to be on for the pins that are used as ENET_REF_CLK
[karo-tx-uboot.git] / drivers / net / npe / IxEthDBSearch.c
1 /**
2  * @file IxEthDBSearch.c
3  * 
4  * @par
5  * IXP400 SW Release version 2.0
6  * 
7  * -- Copyright Notice --
8  * 
9  * @par
10  * Copyright 2001-2005, Intel Corporation.
11  * All rights reserved.
12  * 
13  * @par
14  * SPDX-License-Identifier:     BSD-3-Clause
15  * @par
16  * -- End of Copyright Notice --
17  */
18
19 #include "IxEthDB_p.h"
20
21 extern HashTable dbHashtable;
22
23 /**
24  * @brief matches two database records based on their MAC addresses
25  *
26  * @param untypedReference record to match against
27  * @param untypedEntry record to match
28  *
29  * @return true if the match is successful or false otherwise
30  *
31  * @internal
32  */
33 IX_ETH_DB_PUBLIC
34 BOOL ixEthDBAddressRecordMatch(void *untypedReference, void *untypedEntry)
35 {
36     MacDescriptor *entry     = (MacDescriptor *) untypedEntry;
37     MacDescriptor *reference = (MacDescriptor *) untypedReference;
38     
39     /* check accepted record types */
40     if ((entry->type & reference->type) == 0) return false;
41        
42     return (ixEthDBAddressCompare((UINT8 *) entry->macAddress, (UINT8 *) reference->macAddress) == 0);
43 }
44
45 /**
46  * @brief matches two database records based on their MAC addresses
47  * and VLAN IDs
48  *
49  * @param untypedReference record to match against
50  * @param untypedEntry record to match
51  *
52  * @return true if the match is successful or false otherwise
53  *
54  * @internal
55  */
56 IX_ETH_DB_PUBLIC
57 BOOL ixEthDBVlanRecordMatch(void *untypedReference, void *untypedEntry)
58 {
59     MacDescriptor *entry     = (MacDescriptor *) untypedEntry;
60     MacDescriptor *reference = (MacDescriptor *) untypedReference;
61     
62     /* check accepted record types */
63     if ((entry->type & reference->type) == 0) return false;
64     
65     return (IX_ETH_DB_GET_VLAN_ID(entry->recordData.filteringVlanData.ieee802_1qTag) ==
66         IX_ETH_DB_GET_VLAN_ID(reference->recordData.filteringVlanData.ieee802_1qTag)) &&
67         (ixEthDBAddressCompare(entry->macAddress, reference->macAddress) == 0);
68 }
69
70 /**
71  * @brief matches two database records based on their MAC addresses
72  * and port IDs
73  *
74  * @param untypedReference record to match against
75  * @param untypedEntry record to match
76  *
77  * @return true if the match is successful or false otherwise
78  *
79  * @internal
80  */
81 IX_ETH_DB_PUBLIC
82 BOOL ixEthDBPortRecordMatch(void *untypedReference, void *untypedEntry)
83 {
84     MacDescriptor *entry     = (MacDescriptor *) untypedEntry;
85     MacDescriptor *reference = (MacDescriptor *) untypedReference;
86     
87     /* check accepted record types */
88     if ((entry->type & reference->type) == 0) return false;
89     
90     return (entry->portID == reference->portID) &&
91         (ixEthDBAddressCompare(entry->macAddress, reference->macAddress) == 0);
92 }
93
94 /**
95  * @brief dummy matching function, registered for safety
96  *
97  * @param reference record to match against (unused)
98  * @param entry record to match (unused)
99  *
100  * This function is registered in the matching functions
101  * array on invalid types. Calling it will display an 
102  * error message, indicating an error in the component logic.
103  *
104  * @return false
105  *
106  * @internal
107  */
108 IX_ETH_DB_PUBLIC
109 BOOL ixEthDBNullMatch(void *reference, void *entry)
110 {
111     /* display an error message */
112
113     ixOsalLog(IX_OSAL_LOG_LVL_WARNING, IX_OSAL_LOG_DEV_STDOUT, "DB: (Search) The NullMatch function was called, wrong key type?\n", 0, 0, 0, 0, 0, 0);
114
115
116     return false;
117 }
118
119 /**
120  * @brief registers hash matching methods
121  *
122  * @param matchFunctions table of match functions to be populated
123  *
124  * This function registers the available record matching functions
125  * by indexing them on record types into the given function array.
126  * 
127  * Note that it is compulsory to call this in ixEthDBInit(), 
128  * otherwise hashtable searching and removal will not work
129  *
130  * @return number of registered functions
131  *
132  * @internal
133  */
134 IX_ETH_DB_PUBLIC
135 UINT32 ixEthDBMatchMethodsRegister(MatchFunction *matchFunctions)
136 {
137     UINT32 i;
138     
139     /* safety first */
140     for ( i = 0 ; i < IX_ETH_DB_MAX_KEY_INDEX + 1 ; i++)
141     {
142         matchFunctions[i] = ixEthDBNullMatch;
143     }
144     
145     /* register MAC search method */
146     matchFunctions[IX_ETH_DB_MAC_KEY] = ixEthDBAddressRecordMatch;
147     
148     /* register MAC/PortID search method */
149     matchFunctions[IX_ETH_DB_MAC_PORT_KEY] = ixEthDBPortRecordMatch;
150     
151     /* register MAC/VLAN ID search method */
152     matchFunctions[IX_ETH_DB_MAC_VLAN_KEY] = ixEthDBVlanRecordMatch;
153     
154     return 3; /* three methods */
155 }
156
157 /**
158  * @brief search a record in the Ethernet datbase
159  *
160  * @param macAddress MAC address to perform the search on
161  * @param typeFilter type of records to consider for matching
162  *
163  * @warning if searching is successful an implicit write lock
164  * to the search result is granted, therefore unlock the 
165  * entry using @ref ixEthDBReleaseHashNode() as soon as possible.
166  *
167  * @see ixEthDBReleaseHashNode()
168  *
169  * @return the search result, or NULL if a record with the given
170  * MAC address was not found
171  *
172  * @internal
173  */
174 IX_ETH_DB_PUBLIC
175 HashNode* ixEthDBSearch(IxEthDBMacAddr *macAddress, IxEthDBRecordType typeFilter)
176 {
177     HashNode *searchResult = NULL;
178     MacDescriptor reference;
179     
180     TEST_FIXTURE_INCREMENT_DB_CORE_ACCESS_COUNTER;
181
182     if (macAddress == NULL)
183     {
184         return NULL;
185     }
186
187     /* fill search fields */
188     memcpy(reference.macAddress, macAddress, sizeof (IxEthDBMacAddr));
189     
190     /* set acceptable record types */
191     reference.type = typeFilter;
192     
193     BUSY_RETRY(ixEthDBSearchHashEntry(&dbHashtable, IX_ETH_DB_MAC_KEY, &reference, &searchResult));
194
195     return searchResult;
196 }
197
198 IX_ETH_DB_PUBLIC
199 IxEthDBStatus ixEthDBPeek(IxEthDBMacAddr *macAddress, IxEthDBRecordType typeFilter)
200 {
201     MacDescriptor reference;
202     IxEthDBStatus result;
203     
204     TEST_FIXTURE_INCREMENT_DB_CORE_ACCESS_COUNTER;
205
206     if (macAddress == NULL)
207     {
208         return IX_ETH_DB_INVALID_ARG;
209     }
210
211     /* fill search fields */
212     memcpy(reference.macAddress, macAddress, sizeof (IxEthDBMacAddr));
213     
214     /* set acceptable record types */
215     reference.type = typeFilter;
216     
217     result = ixEthDBPeekHashEntry(&dbHashtable, IX_ETH_DB_MAC_KEY, &reference);
218
219     return result;
220 }
221
222 /**
223  * @brief search a record in the Ethernet datbase
224  *
225  * @param macAddress MAC address to perform the search on
226  * @param portID port ID to perform the search on
227  * @param typeFilter type of records to consider for matching
228  *
229  * @warning if searching is successful an implicit write lock
230  * to the search result is granted, therefore unlock the 
231  * entry using @ref ixEthDBReleaseHashNode() as soon as possible.
232  *
233  * @see ixEthDBReleaseHashNode()
234  *
235  * @return the search result, or NULL if a record with the given
236  * MAC address/port ID combination was not found
237  *
238  * @internal
239  */
240 IX_ETH_DB_PUBLIC
241 HashNode* ixEthDBPortSearch(IxEthDBMacAddr *macAddress, IxEthDBPortId portID, IxEthDBRecordType typeFilter)
242 {
243     HashNode *searchResult = NULL;
244     MacDescriptor reference;
245     
246     if (macAddress == NULL)
247     {
248         return NULL;
249     }
250     
251     /* fill search fields */
252     memcpy(reference.macAddress, macAddress, sizeof (IxEthDBMacAddr));
253     reference.portID = portID;
254     
255     /* set acceptable record types */
256     reference.type = typeFilter;
257
258     BUSY_RETRY(ixEthDBSearchHashEntry(&dbHashtable, IX_ETH_DB_MAC_PORT_KEY, &reference, &searchResult));
259
260     return searchResult;
261 }
262
263 /**
264  * @brief search a record in the Ethernet datbase
265  *
266  * @param macAddress MAC address to perform the search on
267  * @param vlanID VLAN ID to perform the search on
268  * @param typeFilter type of records to consider for matching
269  *
270  * @warning if searching is successful an implicit write lock
271  * to the search result is granted, therefore unlock the 
272  * entry using @ref ixEthDBReleaseHashNode() as soon as possible.
273  *
274  * @see ixEthDBReleaseHashNode()
275  *
276  * @return the search result, or NULL if a record with the given
277  * MAC address/VLAN ID combination was not found
278  *
279  * @internal
280  */
281 IX_ETH_DB_PUBLIC
282 HashNode* ixEthDBVlanSearch(IxEthDBMacAddr *macAddress, IxEthDBVlanId vlanID, IxEthDBRecordType typeFilter)
283 {
284     HashNode *searchResult = NULL;
285     MacDescriptor reference;
286     
287     if (macAddress == NULL)
288     {
289         return NULL;
290     }
291     
292     /* fill search fields */
293     memcpy(reference.macAddress, macAddress, sizeof (IxEthDBMacAddr));
294     reference.recordData.filteringVlanData.ieee802_1qTag = 
295             IX_ETH_DB_SET_VLAN_ID(reference.recordData.filteringVlanData.ieee802_1qTag, vlanID);
296     
297     /* set acceptable record types */
298     reference.type = typeFilter;
299
300     BUSY_RETRY(ixEthDBSearchHashEntry(&dbHashtable, IX_ETH_DB_MAC_VLAN_KEY, &reference, &searchResult));
301
302     return searchResult;
303 }