1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
|
/*
* Copyright c Realtek Semiconductor Corporation, 2008
* All rights reserved.
*
* Program : Vlan driver
* Abstract :
* Author : hyking (hyking_liu@realsil.com.cn)
*/
/* @doc RTL_LAYEREDDRV_API
@module rtl865x_vlan.c - RTL865x Home gateway controller Layered driver API documentation |
This document explains the API interface of the table driver module. Functions with rtl865x prefix
are external functions.
@normal Hyking Liu (Hyking_liu@realsil.com.cn) <date>
Copyright <cp>2008 Realtek<tm> Semiconductor Cooperation, All Rights Reserved.
@head3 List of Symbols |
Here is a list of all functions and variables in this module.
@index | RTL_LAYEREDDRV_API
*/
#include <net/rtl/rtl_types.h>
#include <net/rtl/rtl_glue.h>
#include "rtl_errno.h"
//#include "rtl_utils.h"
//#include "rtl_glue.h"
#include "rtl865x_vlan.h"
#ifdef CONFIG_RTL_LAYERED_ASIC_DRIVER
#include "AsicDriver/rtl865x_asicCom.h"
#else
#include "AsicDriver/rtl865xC_tblAsicDrv.h"
#endif
#include "rtl865x_eventMgr.h"
static rtl865x_vlan_entry_t *vlanTbl = NULL;
static RTL_DECLARE_MUTEX(vlan_sem);
static int32 _rtl865x_delVlan(uint16 vid);
static int32 _rtl865x_setAsicVlan(uint16 vid,rtl865x_vlan_entry_t *vlanEntry)
{
int32 retval = FAILED;
rtl865x_tblAsicDrv_vlanParam_t asicEntry;
/*add this entry to asic table*/
asicEntry.fid = vlanEntry->fid;
asicEntry.memberPortMask = vlanEntry->memberPortMask;
asicEntry.untagPortMask = vlanEntry->untagPortMask;
retval = rtl8651_setAsicVlan(vid,&asicEntry);
return retval;
}
static int32 _rtl865x_referVlan(uint16 vid)
{
rtl865x_vlan_entry_t *entry;
/* vid should be legal vlan ID */
if(vid < 1 || vid > VLAN_NUMBER-1)
return RTL_EINVALIDVLANID;
entry = &vlanTbl[vid];
if(entry->valid != 1)
return RTL_EINVALIDVLANID;
entry->refCnt++;
return SUCCESS;
}
static int32 _rtl865x_deReferVlan(uint16 vid)
{
rtl865x_vlan_entry_t *entry;
/* vid should be legal vlan ID */
if(vid < 1 || vid > VLAN_NUMBER-1)
return RTL_EINVALIDVLANID;
entry = &vlanTbl[vid];
if(entry->valid != 1)
return RTL_EINVALIDVLANID;
entry->refCnt--;
return SUCCESS;
}
int32 _rtl865x_addVlan(uint16 vid)
{
int32 retval = FAILED;
rtl865x_vlan_entry_t *entry;
entry=&vlanTbl[vid];
if(1 == entry->valid)
return RTL_EVLANALREADYEXISTS;
/*add new vlan entry*/
memset(entry,0,sizeof(rtl865x_vlan_entry_t));
entry->vid = vid;
entry->valid = 1;
entry->refCnt = 1;
/*add this entry to asic table*/
retval = _rtl865x_setAsicVlan(vid,entry);
return retval;
}
static int32 _rtl865x_delVlan(uint16 vid)
{
int32 retval = FAILED;
rtl865x_vlan_entry_t *vlanEntry,org;
vlanEntry=&vlanTbl[vid];
if(0 == vlanEntry->valid)
return RTL_EINVALIDVLANID;
/*
if(vlanEntry->refCnt > 1)
{
printk("vid(%d),reference(%d)\n",vid,vlanEntry->refCnt);
return RTL_EREFERENCEDBYOTHER;
}
*/
memcpy(&org,vlanEntry,sizeof(rtl865x_vlan_entry_t));
/*delete vlan entry*/
vlanEntry->valid = 0;
/*ignor other member...*/
retval = rtl8651_delAsicVlan(vid);
if(SUCCESS == retval)
{
/*if vlan entry is deleted, this information should be noticed by uplayer module*/
#if 0
do_eventAction(EV_DEL_VLAN, (void *)&org);
#else
rtl865x_raiseEvent(EVENT_DEL_VLAN, (void *)&org);
#endif
}
return retval;
}
static int32 _rtl865x_addVlanPortMember(uint16 vid, uint32 portMask)
{
int32 retval = FAILED;
rtl865x_vlan_entry_t *vlanEntry;
vlanEntry = &vlanTbl[vid];
if(vlanEntry->valid == 0)
return RTL_EINVALIDVLANID;
/*add member port*/
vlanEntry->memberPortMask |= portMask;
vlanEntry->untagPortMask |= portMask;
/*update this entry to asic table*/
retval = _rtl865x_setAsicVlan(vid,vlanEntry);
return retval;
}
static int32 _rtl865x_delVlanPortMember(uint16 vid, uint32 portMask)
{
int32 retval = FAILED;
rtl865x_vlan_entry_t *vlanEntry;
//rtl865x_tblAsicDrv_vlanParam_t asicEntry;
vlanEntry = &vlanTbl[vid];
if(vlanEntry->valid == 0)
return RTL_EINVALIDVLANID;
/*add member port*/
vlanEntry->memberPortMask &= ~portMask;
vlanEntry->untagPortMask &=~portMask;
if(vlanEntry->memberPortMask == 0)
vlanEntry->valid = 0;
/*update this entry to asic table*/
retval = _rtl865x_setAsicVlan(vid,vlanEntry);
return retval;
}
static int32 _rtl865x_setVlanPortTag(uint16 vid, uint32 portMask, uint8 tag)
{
int32 retval = FAILED;
rtl865x_vlan_entry_t *vlanEntry;
vlanEntry = &vlanTbl[vid];
if(vlanEntry->valid == 0)
return RTL_EINVALIDVLANID;
if(tag == 0)
vlanEntry->untagPortMask |= vlanEntry->memberPortMask & portMask;
else
vlanEntry->untagPortMask &=~(vlanEntry->memberPortMask & portMask);
/*update this entry to asic table*/
retval = _rtl865x_setAsicVlan(vid,vlanEntry);
return retval;
}
static int32 _rtl865x_setVlanFID(uint16 vid, uint32 fid)
{
int32 retval = FAILED;
rtl865x_vlan_entry_t *vlanEntry;
if(fid >= RTL865X_FDB_NUMBER)
return RTL_EINVALIDFID;
vlanEntry = &vlanTbl[vid];
if(vlanEntry->valid == 0)
return RTL_EINVALIDVLANID;
vlanEntry->fid = fid;
/*update this entry to asic table*/
retval = _rtl865x_setAsicVlan(vid,vlanEntry);
return retval;
}
static int32 _rtl865x_getVlanFilterDatabaseId(uint16 vid, uint32 *fid)
{
int32 retval = 0;
if(vid < 1 || vid > VLAN_NUMBER -1)
return RTL_EINVALIDVLANID;
if(vlanTbl[vid].valid == 1)
{
*fid = vlanTbl[vid].fid;
retval = SUCCESS;
}
else
{
printk("%s(%d):the vlan is invalid!!!BUG!!!!\n",__FUNCTION__,__LINE__);
retval = FAILED;
}
return retval;
}
rtl865x_vlan_entry_t *_rtl8651_getVlanTableEntry(uint16 vid)
{
if(vlanTbl[vid].valid == 1)
return &vlanTbl[vid];
return NULL;
}
/*
@func int32 | rtl865x_referVlan | reference a VLAN entry.
@parm uint16 | vid | VLAN ID.
@rvalue SUCCESS | Success.
@rvalue RTL_EINVALIDVLANID | Invalid VLAN ID.
@comm
if a vlan entry is referenced, please call this API.
*/
int32 rtl865x_referVlan(uint16 vid)
{
int32 retval = FAILED;
unsigned long flags;
//rtl_down_interruptible(&vlan_sem);
local_irq_save(flags);
retval = _rtl865x_referVlan(vid);
//rtl_up(&vlan_sem);
local_irq_restore(flags);
return retval;
}
/*
@func int32 | rtl865x_deReferVlan | dereference a VLAN entry.
@parm uint16 | vid | VLAN ID.
@rvalue SUCCESS | Success.
@rvalue RTL_EINVALIDVLANID | Invalid VLAN ID.
@comm
if a vlan entry is dereferenced, please call this API.
NOTE: rtl865x_deReferVlan should be called after rtl865x_referVlan.
*/
int32 rtl865x_deReferVlan(uint16 vid)
{
int32 retval = FAILED;
unsigned long flags;
//rtl_down_interruptible(&vlan_sem);
local_irq_save(flags);
retval = _rtl865x_deReferVlan(vid);
//rtl_up(&vlan_sem);
local_irq_restore(flags);
return retval;
}
/*
@func int32 | rtl865x_addVlan | Add a VLAN.
@parm uint16 | vid | VLAN ID.
@rvalue SUCCESS | Success.
@rvalue RTL_EINVALIDVLANID | Invalid VLAN ID.
@rvalue RTL_EVLANALREADYEXISTS | Vlan already exists.
*/
int32 rtl865x_addVlan(uint16 vid)
{
int32 retval = FAILED;
unsigned long flags;
/* vid should be legal vlan ID */
if(vid < 1 || vid > VLAN_NUMBER-1)
return RTL_EINVALIDVLANID;
//rtl_down_interruptible(&vlan_sem);
local_irq_save(flags);
retval = _rtl865x_addVlan(vid);
//rtl_up(&vlan_sem);
local_irq_restore(flags);
return retval;
}
/*
@func int32 | rtl865x_delVlan | Delete a VLAN.
@parm uint16 | vid | VLAN ID.
@rvalue SUCCESS | Success.
@rvalue RTL_EINVALIDVLANID | Invalid VLAN ID.
@rvalue RTL_EREFERENCEDBYOTHER | the Vlan is referenced by other,please delete releated table entry first.
*/
int32 rtl865x_delVlan(uint16 vid)
{
int32 retval = FAILED;
unsigned long flags;
/* vid should be legal vlan ID */
if(vid < 1 || vid > VLAN_NUMBER -1)
return RTL_EINVALIDVLANID;
//rtl_down_interruptible(&vlan_sem);
local_irq_save(flags);
retval = _rtl865x_delVlan(vid);
//rtl_up(&vlan_sem);
local_irq_restore(flags);
return retval;
}
/*
@func int32 | rtl865x_addVlanPortMember | configure vlan member port
@parm uint16 | vid | VLAN ID.
@parm uint32 | portMask | Port mask.
@rvalue SUCCESS | Success.
@rvalue RTL_EINVALIDVLANID | Invalid VLAN ID.
@comm
the parm portMask is the MASK of port. bit0 mapping to physical port 0,bit1 mapping to physical port 1.
*/
int32 rtl865x_addVlanPortMember(uint16 vid, uint32 portMask)
{
int32 retval = FAILED;
unsigned long flags;
/* vid should be legal vlan ID */
if(vid < 1 || vid > VLAN_NUMBER -1)
return RTL_EINVALIDVLANID;
//rtl_down_interruptible(&vlan_sem);
local_irq_save(flags);
retval = _rtl865x_addVlanPortMember(vid,portMask);
//rtl_up(&vlan_sem);
local_irq_restore(flags);
return retval;
}
/*
@func int32 | rtl865x_delVlanPortMember | delete vlan's member port
@parm uint16 | vid | VLAN ID.
@parm uint32 | portMask | Port mask.
@rvalue SUCCESS | Success.
@rvalue RTL_EINVALIDVLANID | Invalid VLAN ID.
@comm
the parm portMask is the MASK of port. bit0 mapping to physical port 0,bit1 mapping to physical port 1.
*/
int32 rtl865x_delVlanPortMember(uint16 vid,uint32 portMask)
{
int32 retval = FAILED;
unsigned long flags;
/* vid should be legal vlan ID */
if(vid < 1 || vid > VLAN_NUMBER -1)
return RTL_EINVALIDVLANID;
//rtl_down_interruptible(&vlan_sem);
local_irq_save(flags);
retval = _rtl865x_delVlanPortMember(vid,portMask);
//rtl_up(&vlan_sem);
local_irq_restore(flags);
return retval;
}
/*
@func uint32 | rtl865x_getVlanPortMask | get the member portMask of a vlan
@parm uint16 | vid | VLAN ID.
@comm
if the retrun value is zero, it means vlan entry is invalid or no member port in this vlan.
*/
uint32 rtl865x_getVlanPortMask(uint32 vid)
{
rtl865x_vlan_entry_t *vlanEntry;
if((vid < 1) || (vid > VLAN_NUMBER -1))
{
return 0;
}
vlanEntry = &vlanTbl[vid];
if(vlanEntry->valid == 0)
{
return 0;
}
return vlanEntry->memberPortMask;
}
/*
@func int32 | rtl865x_setVlanPortTag | configure member port vlan tag attribute
@parm uint16 | vid | VLAN ID.
@parm uint32 | portMask | Port mask.
@parm uint8 | portMask | vlantag or untag.
@rvalue SUCCESS | Success.
@rvalue RTL_EINVALIDVLANID | Invalid VLAN ID.
@comm
the parm portMask is the MASK of port. bit0 mapping to physical port 0,bit1 mapping to physical port 1.
parm tag is used to indicated physical port is vlantag or untag. value 1 means vlan tagged, and vlan 0 means vlan untagged.
*/
int32 rtl865x_setVlanPortTag(uint16 vid,uint32 portMask,uint8 tag)
{
int32 retval = FAILED;
unsigned long flags;
/* vid should be legal vlan ID */
if(vid < 1 || vid > VLAN_NUMBER -1)
return RTL_EINVALIDVLANID;
//rtl_down_interruptible(&vlan_sem);
local_irq_save(flags);
retval = _rtl865x_setVlanPortTag(vid,portMask,tag);
//rtl_up(&vlan_sem);
local_irq_restore(flags);
return retval;
}
/*
@func int32 | rtl865x_setVlanFilterDatabase | configure the filter database for a vlan.
@parm uint16 | vid | VLAN ID.
@parm uint32 | fid | filter data base ID.
@rvalue SUCCESS | Success.
@rvalue RTL_EINVALIDVLANID | Invalid VLAN ID.
@rvalue RTL_EINVALIDFID | Invalid filter database ID.
@comm
in realtek 865x, 4 filter databases are support.
if you want to configure SVL for all vlan, please set the fid of vlan is same.
default configure is SVL.
*/
int32 rtl865x_setVlanFilterDatabase(uint16 vid, uint32 fid)
{
int32 retval = FAILED;
unsigned long flags;
/* vid should be legal vlan ID */
if(vid < 1 || vid > VLAN_NUMBER -1)
return RTL_EINVALIDVLANID;
//rtl_down_interruptible(&vlan_sem);//Lock resource
local_irq_save(flags);
retval = _rtl865x_setVlanFID(vid,fid);
//rtl_up(&vlan_sem);
local_irq_restore(flags);
return retval;
}
/*
@func int32 | rtl865x_getVlanFilterDatabaseId | get the vlan's filter database ID.
@parm uint16 | vid | VLAN ID.
@parm uint32 | fid | filter data base ID.
@rvalue SUCCESS | Success.
@rvalue RTL_EINVALIDVLANID | Invalid VLAN ID.
@comm
*/
int32 rtl865x_getVlanFilterDatabaseId(uint16 vid, uint32 *fid)
{
int32 retval = FAILED;
retval = _rtl865x_getVlanFilterDatabaseId(vid, fid);
return retval;
}
/*
@func int32 | rtl865x_initVlanTable | initialize vlan table.
@rvalue SUCCESS | Success.
@rvalue FAILED | Failed,system should be reboot.
*/
int32 rtl865x_initVlanTable(void)
{
TBL_MEM_ALLOC(vlanTbl, rtl865x_vlan_entry_t, VLAN_NUMBER);
memset(vlanTbl,0,sizeof(rtl865x_vlan_entry_t)*VLAN_NUMBER);
return SUCCESS;
}
/*
@func int32 | rtl865x_reinitVlantable | initialize vlan table.
@rvalue SUCCESS | Success.
*/
int32 rtl865x_reinitVlantable(void)
{
uint16 i;
for(i = 0; i < VLAN_NUMBER; i++)
{
if(vlanTbl[i].valid)
{
_rtl865x_delVlan(i);
}
}
return SUCCESS;
}
|