blob: e5ec4906d60a8d56201b1a67678c900cb398f5d0 [file] [log] [blame]
developer5c2422b2024-03-08 00:27:44 +08001/*
2* switch_fun.c: switch function sets
3*/
4#include <stdio.h>
5#include <stdlib.h>
6#include <unistd.h>
7#include <string.h>
8#include <stdbool.h>
9#include <sys/ioctl.h>
10#include <sys/socket.h>
11#include <linux/if.h>
12#include <stdbool.h>
13#include <time.h>
14
15#include "switch_extend.h"
16#include "switch_netlink.h"
17#include "switch_fun.h"
18#include "switch_fun_an8855.h"
19
20#define MAC_STR "%02X%02X%02X%02X%02X%02X"
21#define MAC2STR(m) (m)[0],(m)[1],(m)[2],(m)[3],(m)[4],(m)[5]
22
23const static C8_T *mac_address_forward_control_string[] = {
24 "Default",
25 "CPU include",
26 "CPU exclude",
27 "CPU only",
28 "Drop"
29};
30
31struct switch_func_s an8855_switch_func = {
32 .pf_table_dump = an8855_table_dump,
33 .pf_table_clear = an8855_table_clear,
34 .pf_switch_reset = an8855_switch_reset,
35 .pf_doArlAging = an8855_doArlAging,
36 .pf_read_mib_counters = an8855_read_mib_counters,
37 .pf_clear_mib_counters = an8855_clear_mib_counters,
38 .pf_read_output_queue_counters = an8855_read_output_queue_counters,
39 .pf_read_free_page_counters = an8855_read_free_page_counters,
40 .pf_rate_control = an8855_rate_control,
41 .pf_igress_rate_set = an8855_ingress_rate_set,
42 .pf_egress_rate_set = an8855_egress_rate_set,
43 .pf_table_add = an8855_table_add,
44 .pf_table_del_fid = an8855_table_del_fid,
45 .pf_table_del_vid = an8855_table_del_vid,
46 .pf_table_search_mac_fid = an8855_table_search_mac_fid,
47 .pf_table_search_mac_vid = an8855_table_search_mac_vid,
48 .pf_global_set_mac_fc = an8855_global_set_mac_fc,
49 .pf_set_mac_pfc = an8855_not_supported,
50 .pf_qos_sch_select = an8855_qos_sch_select,
51 .pf_qos_set_base = an8855_qos_set_base,
52 .pf_qos_wfq_set_weight = an8855_qos_wfq_set_weight,
53 .pf_qos_set_portpri = an8855_qos_set_portpri,
54 .pf_qos_set_dscppri = an8855_qos_set_dscppri,
55 .pf_qos_pri_mapping_queue = an8855_qos_pri_mapping_queue,
56 .pf_doStp = an8855_doStp,
57 .pf_sip_dump = an8855_not_supported,
58 .pf_sip_add = an8855_not_supported,
59 .pf_sip_del = an8855_not_supported,
60 .pf_sip_clear = an8855_not_supported,
61 .pf_dip_dump = an8855_not_supported,
62 .pf_dip_add = an8855_not_supported,
63 .pf_dip_del = an8855_not_supported,
64 .pf_dip_clear = an8855_not_supported,
65 .pf_set_mirror_to = an8855_set_mirror_to,
66 .pf_set_mirror_from = an8855_set_mirror_from,
67 .pf_doMirrorEn = an8855_doMirrorEn,
68 .pf_doMirrorPortBased = an8855_doMirrorPortBased,
69 .pf_acl_dip_add = an8855_not_supported,
70 .pf_acl_dip_modify = an8855_not_supported,
71 .pf_acl_dip_pppoe = an8855_not_supported,
72 .pf_acl_dip_trtcm = an8855_not_supported,
73 .pf_acl_dip_meter = an8855_not_supported,
74 .pf_acl_mac_add = an8855_not_supported,
75 .pf_acl_ethertype = an8855_not_supported,
76 .pf_acl_sp_add = an8855_not_supported,
77 .pf_acl_l4_add = an8855_not_supported,
78 .pf_acl_port_enable = an8855_not_supported,
79 .pf_acl_table_add = an8855_not_supported,
80 .pf_acl_mask_table_add = an8855_not_supported,
81 .pf_acl_rule_table_add = an8855_not_supported,
82 .pf_acl_rate_table_add = an8855_not_supported,
83 .pf_vlan_dump = an8855_vlan_dump,
84 .pf_vlan_set = an8855_vlan_set,
85 .pf_vlan_clear = an8855_vlan_clear,
86 .pf_doVlanSetVid = an8855_doVlanSetVid,
87 .pf_doVlanSetPvid = an8855_doVlanSetPvid,
88 .pf_doVlanSetAccFrm = an8855_doVlanSetAccFrm,
89 .pf_doVlanSetPortAttr = an8855_doVlanSetPortAttr,
90 .pf_doVlanSetPortMode = an8855_doVlanSetPortMode,
91 .pf_doVlanSetEgressTagPCR = an8855_doVlanSetEgressTagPCR,
92 .pf_doVlanSetEgressTagPVC = an8855_doVlanSetEgressTagPVC,
93 .pf_igmp_on = an8855_not_supported,
94 .pf_igmp_off = an8855_not_supported,
95 .pf_igmp_enable = an8855_not_supported,
96 .pf_igmp_disable = an8855_not_supported,
97 .pf_collision_pool_enable = an8855_not_supported,
98 .pf_collision_pool_mac_dump = an8855_not_supported,
99 .pf_collision_pool_dip_dump = an8855_not_supported,
100 .pf_collision_pool_sip_dump = an8855_not_supported,
101 .pf_pfc_get_rx_counter = an8855_not_supported,
102 .pf_pfc_get_tx_counter = an8855_not_supported,
103 .pf_eee_enable = an8855_eee_enable,
104 .pf_eee_dump = an8855_eee_dump,
105};
106
107AIR_ERROR_NO_T
108an8855_reg_read(const UI32_T unit, const UI32_T addr_offset, UI32_T * ptr_data)
109{
110 int ret;
111
112 ret = reg_read(addr_offset, ptr_data);
113 if (ret < 0) {
114 return AIR_E_OTHERS;
115 }
116
117 return AIR_E_OK;
118}
119
120AIR_ERROR_NO_T
121an8855_reg_write(const UI32_T unit, const UI32_T addr_offset, const UI32_T data)
122{
123 int ret;
124
125 ret = reg_write(addr_offset, data);
126 if (ret < 0) {
127 return AIR_E_OTHERS;
128 }
129
130 return AIR_E_OK;
131}
132
133AIR_ERROR_NO_T
134an8855_phy_cl22_read(const UI32_T unit,
135 const UI32_T port_id,
136 const UI32_T addr_offset, UI32_T * ptr_data)
137{
138 int ret;
139
140 ret = mii_mgr_read(port_id, addr_offset, ptr_data);
141 if (ret < 0) {
142 return AIR_E_OTHERS;
143 }
144
145 return AIR_E_OK;
146}
147
148AIR_ERROR_NO_T
149an8855_phy_cl22_write(const UI32_T unit,
150 const UI32_T port_id,
151 const UI32_T addr_offset, const UI32_T data)
152{
153 int ret;
154
155 ret = mii_mgr_write(port_id, addr_offset, data);
156 if (ret < 0) {
157 return AIR_E_OTHERS;
158 }
159
160 return AIR_E_OK;
161}
162
163AIR_ERROR_NO_T
164an8855_phy_cl45_read(const UI32_T unit,
165 const UI32_T port_id,
166 const UI32_T dev_type,
167 const UI32_T addr_offset, UI32_T * ptr_data)
168{
169 int ret;
170
171 ret = mii_mgr_c45_read(port_id, dev_type, addr_offset, ptr_data);
172 if (ret < 0) {
173 return AIR_E_OTHERS;
174 }
175
176 return AIR_E_OK;
177}
178
179AIR_ERROR_NO_T
180an8855_phy_cl45_write(const UI32_T unit,
181 const UI32_T port_id,
182 const UI32_T dev_type,
183 const UI32_T addr_offset, const UI32_T data)
184{
185 int ret;
186
187 ret = mii_mgr_c45_write(port_id, dev_type, addr_offset, data);
188 if (ret < 0) {
189 return AIR_E_OTHERS;
190 }
191
192 return AIR_E_OK;
193}
194
195void an8855_not_supported(int argc, char *argv[])
196{
197 printf("Cmd not supported by AN8855.\n");
198}
199
200static AIR_ERROR_NO_T
201_printMacEntry(AIR_MAC_ENTRY_T * mt, UI32_T age_unit, UI8_T count, UI8_T title)
202{
203 AIR_ERROR_NO_T ret = AIR_E_OK;
204 I32_T i = 0, j = 0;
205 UI8_T first = 0;
206 UI8_T find = 0;
207 if (title) {
208 printf("%-6s%-15s%-5s%-5s%-5s%-10s%-10s%-6s\n",
209 "unit",
210 "mac",
211 "ivl", "vid", "fid", "age-time", "forward", "port");
212 return ret;
213 }
214 for (i = 0; i < count; i++) {
215 printf("%-6d", age_unit);
216 printf(MAC_STR, MAC2STR(mt[i].mac));
217 printf("...");
218 if (mt[i].flags & AIR_L2_MAC_ENTRY_FLAGS_IVL) {
219 printf("%-3s..", "ivl");
220 printf("%-5d", mt[i].cvid);
221 printf("%-5s", ".....");
222 } else {
223 printf("%-3s..", "svl");
224 printf("%-5s", ".....");
225 printf("%-5d", mt[i].fid);
226 }
227 if (mt[i].flags & AIR_L2_MAC_ENTRY_FLAGS_STATIC) {
228 printf("%-7s.", "static");
229 } else {
230 printf("%d sec..", mt[i].timer);
231 }
232 printf("%-10s",
233 mac_address_forward_control_string[mt[i].sa_fwd]);
234 first = 0;
235 find = 0;
236 for (j = (AIR_MAX_NUM_OF_PORTS - 1); j >= 0; j--) {
237 if ((mt[i].port_bitmap[0]) & (1 << j)) {
238 first = j;
239 find = 1;
240 break;
241 }
242 }
243 if (find) {
244 for (j = 0; j < AIR_MAX_NUM_OF_PORTS; j++) {
245 if ((mt[i].port_bitmap[0]) & (1 << j)) {
246 if (j == first)
247 printf("%-2d", j);
248 else
249 printf("%-2d,", j);
250 }
251 }
252 } else
253 printf("no dst port");
254 printf("\n");
255 }
256 return ret;
257}
258
259static AIR_ERROR_NO_T _str2mac(C8_T * str, C8_T * mac)
260{
261 UI32_T i;
262 C8_T tmpstr[3];
263
264 for (i = 0; i < 6; i++) {
265 strncpy(tmpstr, str + (i * 2), 2);
266 tmpstr[2] = '\0';
267 mac[i] = strtoul(tmpstr, NULL, 16);
268 }
269
270 return AIR_E_OK;
271}
272
273static void an8855_table_dump_internal(int type)
274{
275 unsigned char count = 0;
276 unsigned int total_count = 0;
277 unsigned int bucket_size = 0;
278 AIR_ERROR_NO_T ret = 0;
279 AIR_MAC_ENTRY_T *ptr_mt;
280
281 bucket_size = AIR_L2_MAC_SET_NUM;
282 ptr_mt = malloc(sizeof(AIR_MAC_ENTRY_T) * bucket_size);
283 if (ptr_mt == NULL) {
284 printf("Error, malloc fail\n\r");
285 return;
286 }
287 memset(ptr_mt, 0, sizeof(AIR_MAC_ENTRY_T) * bucket_size);
288 _printMacEntry(ptr_mt, 0, count, TRUE);
289 /* get 1st entry of MAC table */
290 ret = air_l2_getMacAddr(0, &count, ptr_mt);
291 switch (ret) {
292 case AIR_E_ENTRY_NOT_FOUND:
293 printf("Not Found!\n");
294 goto DUMP_ERROR;
295 case AIR_E_TIMEOUT:
296 printf("Time Out!\n");
297 goto DUMP_ERROR;
298 case AIR_E_BAD_PARAMETER:
299 printf("Bad Parameter!\n");
300 goto DUMP_ERROR;
301 default:
302 break;
303 }
304 total_count += count;
305 _printMacEntry(ptr_mt, 0, count, FALSE);
306 /* get other entries of MAC table */
307 while (1) {
308 memset(ptr_mt, 0, sizeof(AIR_MAC_ENTRY_T) * bucket_size);
309 ret = air_l2_getNextMacAddr(0, &count, ptr_mt);
310 if (AIR_E_OK != ret) {
311 break;
312 }
313 total_count += count;
314 _printMacEntry(ptr_mt, 0, count, FALSE);
315 }
316 switch (ret) {
317 case AIR_E_TIMEOUT:
318 printf("Time Out!\n");
319 break;
320 case AIR_E_BAD_PARAMETER:
321 printf("Bad Parameter!\n");
322 break;
323 default:
324 printf("Found %u %s\n", total_count,
325 (total_count > 1) ? "entries" : "entry");
326 break;
327 }
328
329DUMP_ERROR:
330 free(ptr_mt);
331 return;
332}
333
334void an8855_table_dump(int argc, char *argv[])
335{
336 an8855_table_dump_internal(GENERAL_TABLE);
337}
338
339void an8855_table_add(int argc, char *argv[])
340{
341 AIR_ERROR_NO_T ret = AIR_E_OK;
342 AIR_MAC_ENTRY_T mt;
343 unsigned int i = 0;
344 unsigned int age_time = 0;
345 memset(&mt, 0, sizeof(AIR_MAC_ENTRY_T));
346 if (!argv[2] || strlen(argv[2]) != 12) {
347 printf("MAC address format error, should be of length 12\n");
348 return;
349 }
350 ret = _str2mac(argv[2], (C8_T *) mt.mac);
351 if (ret != AIR_E_OK) {
352 printf("Unrecognized command.\n");
353 return;
354 }
355 if (argc > 4) {
356 mt.cvid = strtoul(argv[4], NULL, 0);
357 if (4095 < mt.cvid) {
358 printf("wrong vid range, should be within 0~4095\n");
359 return;
360 }
361 mt.flags |= AIR_L2_MAC_ENTRY_FLAGS_IVL;
362 }
363 if (!argv[3] || strlen(argv[3]) != 6) {
364 /*bit0~5, each map port0~port5 */
365 printf("portmap format error, should be of length 6\n");
366 return;
367 }
368 for (i = 0; i < 6; i++) {
369 if (argv[3][i] != '0' && argv[3][i] != '1') {
370 printf
371 ("portmap format error, should be of combination of 0 or 1\n");
372 return;
373 }
374 mt.port_bitmap[0] |= ((argv[3][i] - '0') << i);
375 }
376 if (argc > 5) {
377 age_time = strtoul(argv[5], NULL, 0);
378 if (age_time < 1 || 1000000 < age_time) {
379 printf("wrong age range, should be within 1~1000000\n");
380 return;
381 }
382 } else {
383 mt.flags |= AIR_L2_MAC_ENTRY_FLAGS_STATIC;
384 }
385 mt.sa_fwd = AIR_L2_FWD_CTRL_DEFAULT;
386 ret = air_l2_addMacAddr(0, &mt);
387 if (ret == AIR_E_OK) {
388 printf("add mac address done.\n");
389 usleep(5000);
390 if (!(mt.flags & AIR_L2_MAC_ENTRY_FLAGS_STATIC)) {
391 ret = air_l2_setMacAddrAgeOut(0, age_time);
392 if (ret == AIR_E_OK) {
393 printf("set age out time done.\n");
394 } else {
395 printf("set age out time fail.\n");
396 }
397 }
398 } else {
399 printf("add mac address fail.\n");
400 }
401 return;
402}
403
404void an8855_table_search_mac_vid(int argc, char *argv[])
405{
406 AIR_ERROR_NO_T ret = AIR_E_OK;
407 unsigned char count = 0;
408 char tmpstr[9];
409 AIR_MAC_ENTRY_T *ptr_mt;
410
411 if (!argv[3] || strlen(argv[3]) != 12) {
412 printf("MAC address format error, should be of length 12\n");
413 return;
414 }
415
416 ptr_mt = malloc(sizeof(AIR_MAC_ENTRY_T));
417 if (NULL == ptr_mt) {
418 printf("Error, malloc fail\n");
419 return;
420 }
421 memset(ptr_mt, 0, sizeof(AIR_MAC_ENTRY_T));
422 ret = _str2mac(argv[3], (C8_T *) ptr_mt->mac);
423 if (ret != AIR_E_OK) {
424 printf("Unrecognized command.\n");
425 free(ptr_mt);
426 return;
427 }
428
429 /* get mac entry by MAC address & vid */
430 ptr_mt->cvid = strtoul(argv[5], NULL, 0);
431 ptr_mt->flags |= AIR_L2_MAC_ENTRY_FLAGS_IVL;
432 if (ptr_mt->cvid > 4095) {
433 printf("wrong vid range, should be within 0~4095\n");
434 free(ptr_mt);
435 return;
436 }
437
438 ret = air_l2_getMacAddr(0, &count, ptr_mt);
439 if (ret == AIR_E_OK) {
440 _printMacEntry(ptr_mt, 0, 1, TRUE);
441 _printMacEntry(ptr_mt, 0, 1, FALSE);
442 } else {
443 printf("\n Not found!\n");
444 }
445 free(ptr_mt);
446 return;
447}
448
449void an8855_table_search_mac_fid(int argc, char *argv[])
450{
451 AIR_ERROR_NO_T ret = AIR_E_OK;
452 unsigned char count = 0;
453 char tmpstr[9];
454 AIR_MAC_ENTRY_T *ptr_mt;
455
456 if (!argv[3] || strlen(argv[3]) != 12) {
457 printf("MAC address format error, should be of length 12\n");
458 return;
459 }
460
461 ptr_mt = malloc(sizeof(AIR_MAC_ENTRY_T));
462 if (NULL == ptr_mt) {
463 printf("Error, malloc fail\n");
464 return;
465 }
466 memset(ptr_mt, 0, sizeof(AIR_MAC_ENTRY_T));
467 ret = _str2mac(argv[3], (C8_T *) ptr_mt->mac);
468 if (ret != AIR_E_OK) {
469 printf("Unrecognized command.\n");
470 free(ptr_mt);
471 return;
472 }
473
474 /* get mac entry by MAC address & fid */
475 ptr_mt->fid = strtoul(argv[5], NULL, 0);
476 if (ptr_mt->fid > 7) {
477 printf("wrong fid range, should be within 0~7\n");
478 free(ptr_mt);
479 return;
480 }
481
482 ret = air_l2_getMacAddr(0, &count, ptr_mt);
483 if (ret == AIR_E_OK) {
484 _printMacEntry(ptr_mt, 0, 1, TRUE);
485 _printMacEntry(ptr_mt, 0, 1, FALSE);
486 } else {
487 printf("\n Not found!\n");
488 }
489 free(ptr_mt);
490 return;
491}
492
493void an8855_table_del_fid(int argc, char *argv[])
494{
495 AIR_ERROR_NO_T ret = AIR_E_OK;
496 char tmpstr[9];
497 AIR_MAC_ENTRY_T mt;
498
499 if (!argv[3] || strlen(argv[3]) != 12) {
500 printf("MAC address format error, should be of length 12\n");
501 return;
502 }
503
504 memset(&mt, 0, sizeof(AIR_MAC_ENTRY_T));
505 ret = _str2mac(argv[3], (C8_T *) mt.mac);
506 if (ret != AIR_E_OK) {
507 printf("Unrecognized command.\n");
508 return;
509 }
510
511 /* get mac entry by MAC address & fid */
512 mt.fid = strtoul(argv[5], NULL, 0);
513 if (mt.fid > 7) {
514 printf("wrong fid range, should be within 0~7\n");
515 return;
516 }
517
518 ret = air_l2_delMacAddr(0, &mt);
519 if (ret == AIR_E_OK) {
520 printf("Done.\n");
521 } else {
522 printf("Fail.\n");
523 }
524 return;
525}
526
527void an8855_table_del_vid(int argc, char *argv[])
528{
529 AIR_ERROR_NO_T ret = AIR_E_OK;
530 char tmpstr[9];
531 AIR_MAC_ENTRY_T mt;
532
533 if (!argv[3] || strlen(argv[3]) != 12) {
534 printf("MAC address format error, should be of length 12\n");
535 return;
536 }
537
538 memset(&mt, 0, sizeof(AIR_MAC_ENTRY_T));
539 ret = _str2mac(argv[3], (C8_T *) mt.mac);
540 if (ret != AIR_E_OK) {
541 printf("Unrecognized command.\n");
542 return;
543 }
544
545 /* get mac entry by MAC address & vid */
546 mt.cvid = strtoul(argv[5], NULL, 0);
547 mt.flags |= AIR_L2_MAC_ENTRY_FLAGS_IVL;
548 if (mt.cvid > 4095) {
549 printf("wrong vid range, should be within 0~4095\n");
550 return;
551 }
552
553 ret = air_l2_delMacAddr(0, &mt);
554 if (ret == AIR_E_OK) {
555 printf("Done.\n");
556 } else {
557 printf("Fail.\n");
558 }
559 return;
560}
561
562void an8855_table_clear(int argc, char *argv[])
563{
564 AIR_ERROR_NO_T ret = AIR_E_OK;
565
566 ret = air_l2_clearMacAddr(0);
567 if (ret == AIR_E_OK)
568 printf("Clear MAC Address Table Done.\n");
569 else
570 printf("Clear MAC Address Table Fail.\n");
571 return;
572}
573
574void an8855_set_mirror_to(int argc, char *argv[])
575{
576 int idx;
577 AIR_MIR_SESSION_T session = { 0 };
578
579 idx = strtoul(argv[3], NULL, 0);
580 if (idx < 0 || MAX_PORT < idx) {
581 printf("wrong port member, should be within 0~%d\n", MAX_PORT);
582 return;
583 }
584
585 memset(&session, 0, sizeof(AIR_MIR_SESSION_T));
586
587 air_mir_getSession(0, 0, &session);
588 session.dst_port = idx;
589 session.flags |= AIR_MIR_SESSION_FLAGS_ENABLE;
590 air_mir_addSession(0, 0, &session);
591}
592
593void an8855_set_mirror_from(int argc, char *argv[])
594{
595 int idx = 0, mirror = 0;
596 AIR_MIR_SESSION_T session = { 0 };
597
598 idx = _strtoul(argv[3], NULL, 0);
599 mirror = _strtoul(argv[4], NULL, 0);
600
601 if (idx < 0 || MAX_PORT < idx) {
602 printf("wrong port member, should be within 0~%d\n", MAX_PORT);
603 return;
604 }
605
606 if (mirror < 0 || 3 < mirror) {
607 printf("wrong mirror setting, should be within 0~3\n");
608 return;
609 }
610
611 memset(&session, 0, sizeof(AIR_MIR_SESSION_T));
612
613 if (mirror & 0x1) { // rx enable
614 session.src_port = idx;
615 air_mir_getMirrorPort(0, 0, &session);
616
617 session.flags |= AIR_MIR_SESSION_FLAGS_DIR_RX;
618 session.src_port = idx;
619 air_mir_setMirrorPort(0, 0, &session);
620 }
621
622 if (mirror & 0x2) { //tx enable
623 session.src_port = idx;
624 air_mir_getMirrorPort(0, 0, &session);
625
626 session.flags |= AIR_MIR_SESSION_FLAGS_DIR_TX;
627 session.src_port = idx;
628 air_mir_setMirrorPort(0, 0, &session);
629 }
630}
631
632void an8855_vlan_dump(int argc, char *argv[])
633{
634 AIR_VLAN_ENTRY_T vlan_entry = { 0 };
635 unsigned int i;
636 int eg_tag = 0;
637
638 if (argc == 4) {
639 if (!strncmp(argv[3], "egtag", 6))
640 eg_tag = 1;
641 }
642
643 if (eg_tag)
644 printf
645 (" vid fid portmap s-tag\teg_tag(0:untagged 2:tagged)\n");
646 else
647 printf(" vid fid portmap s-tag\n");
648
649 for (i = 1; i < 4096; i++) {
650 _air_vlan_readEntry(0, i, &vlan_entry);
651
652 if (vlan_entry.valid) {
653 printf(" %4d ", i);
654 printf(" %2d ", vlan_entry.vlan_entry_format.fid);
655 printf(" %c",
656 (vlan_entry.
657 vlan_entry_format.port_mem & 0b0000001) ? '1' :
658 '-');
659 printf("%c",
660 (vlan_entry.
661 vlan_entry_format.port_mem & 0b0000010) ? '1' :
662 '-');
663 printf("%c",
664 (vlan_entry.
665 vlan_entry_format.port_mem & 0b0000100) ? '1' :
666 '-');
667 printf("%c",
668 (vlan_entry.
669 vlan_entry_format.port_mem & 0b0001000) ? '1' :
670 '-');
671 printf("%c",
672 (vlan_entry.
673 vlan_entry_format.port_mem & 0b0010000) ? '1' :
674 '-');
675 printf("%c",
676 (vlan_entry.
677 vlan_entry_format.port_mem & 0b0100000) ? '1' :
678 '-');
679 printf("%c",
680 (vlan_entry.
681 vlan_entry_format.port_mem & 0b1000000) ? '1' :
682 '-');
683 printf(" %4d", vlan_entry.vlan_entry_format.eg_ctrl);
684 if (eg_tag) {
685 printf("\t");
686 if (vlan_entry.vlan_entry_format.eg_con
687 && vlan_entry.
688 vlan_entry_format.eg_ctrl_en) {
689 /* VTAG_EN=1 and EG_CON=1 */
690 printf("CONSISTENT");
691 } else if (vlan_entry.
692 vlan_entry_format.eg_ctrl_en) {
693 /* VTAG_EN=1 */
694 printf("%d",
695 (vlan_entry.
696 vlan_entry_format.eg_ctrl >> 0)
697 & 0x3);
698 printf("%d",
699 (vlan_entry.
700 vlan_entry_format.eg_ctrl >> 2)
701 & 0x3);
702 printf("%d",
703 (vlan_entry.
704 vlan_entry_format.eg_ctrl >> 4)
705 & 0x3);
706 printf("%d",
707 (vlan_entry.
708 vlan_entry_format.eg_ctrl >> 6)
709 & 0x3);
710 printf("%d",
711 (vlan_entry.
712 vlan_entry_format.eg_ctrl >> 8)
713 & 0x3);
714 printf("%d",
715 (vlan_entry.
716 vlan_entry_format.eg_ctrl >> 10)
717 & 0x3);
718 printf("%d",
719 (vlan_entry.
720 vlan_entry_format.eg_ctrl >> 12)
721 & 0x3);
722 } else {
723 /* VTAG_EN=0 */
724 printf("DISABLED");
725 }
726 }
727 printf("\n");
728 } else {
729 /*print 16 vid for reference information */
730 if (i <= 16) {
731 printf(" %4d ", i);
732 printf(" %2d ",
733 vlan_entry.vlan_entry_format.fid);
734 printf(" invalid\n");
735 }
736 }
737 }
738}
739
740void an8855_vlan_clear(int argc, char *argv[])
741{
742 air_vlan_destroyAll(0, 0);
743}
744
745void an8855_vlan_set(int argc, char *argv[])
746{
747 unsigned int vlan_mem = 0;
748 int i, vid, fid;
749 int stag = 0;
750 unsigned long eg_con = 0;
751 unsigned int eg_tag = 0;
752 AIR_VLAN_ENTRY_T vlan_entry = { 0 };
753
754 if (argc < 5) {
755 printf("insufficient arguments!\n");
756 return;
757 }
758
759 fid = strtoul(argv[3], NULL, 0);
760 if (fid < 0 || fid > 7) {
761 printf("wrong filtering db id range, should be within 0~7\n");
762 return;
763 }
764
765 vid = strtoul(argv[4], NULL, 0);
766 if (vid < 0 || MAX_VID_VALUE < vid) {
767 printf("wrong vlan id range, should be within 0~4095\n");
768 return;
769 }
770
771 if (strlen(argv[5]) != SWITCH_MAX_PORT) {
772 printf("portmap format error, should be of length %d\n",
773 SWITCH_MAX_PORT);
774 return;
775 }
776
777 vlan_mem = 0;
778 for (i = 0; i < SWITCH_MAX_PORT; i++) {
779 if (argv[5][i] != '0' && argv[5][i] != '1') {
780 printf
781 ("portmap format error, should be of combination of 0 or 1\n");
782 return;
783 }
784 vlan_mem += (argv[5][i] - '0') * (1 << i);
785 }
786
787 /* VLAN stag */
788 if (argc > 6) {
789 stag = strtoul(argv[6], NULL, 16);
790 if (stag < 0 || 0xfff < stag) {
791 printf
792 ("wrong stag id range, should be within 0~4095\n");
793 return;
794 }
795 }
796
797 /* set vlan member */
798 vlan_entry.vlan_entry_format.port_mem = vlan_mem;
799 vlan_entry.vlan_entry_format.ivl = 1;
800 vlan_entry.vlan_entry_format.stag = stag;
801 vlan_entry.valid = 1;
802
803 if (argc > 7) {
804 eg_con = strtoul(argv[7], NULL, 2);
805 eg_con = ! !eg_con;
806 vlan_entry.vlan_entry_format.eg_con = eg_con;
807 vlan_entry.vlan_entry_format.eg_ctrl_en = 1;
808 }
809
810 if (argc > 8 && !eg_con) {
811 if (strlen(argv[8]) != SWITCH_MAX_PORT) {
812 printf
813 ("egtag portmap format error, should be of length %d\n",
814 SWITCH_MAX_PORT);
815 return;
816 }
817
818 for (i = 0; i < SWITCH_MAX_PORT; i++) {
819 if (argv[8][i] < '0' || argv[8][i] > '3') {
820 printf
821 ("egtag portmap format error, should be of combination of 0 or 3\n");
822 return;
823 }
824 eg_tag |= (argv[8][i] - '0') << (i * 2);
825 }
826
827 vlan_entry.vlan_entry_format.eg_ctrl_en = 1;
828 vlan_entry.vlan_entry_format.eg_ctrl = eg_tag;
829 }
830
831 _air_vlan_writeEntry(0, vid, &vlan_entry);
832}
833
834void an8855_switch_reset(int argc, char *argv[])
835{
836 air_switch_reset(0);
837}
838
839void an8855_global_set_mac_fc(int argc, char *argv[])
840{
841 unsigned char enable = 0;
842 unsigned int reg = 0, value = 0;
843
844 enable = _strtoul(argv[3], NULL, 10);
845 printf("enable: %d\n", enable);
846
847 /* Check the input parameters is right or not. */
848 if (enable > 1) {
849 printf(HELP_MACCTL_FC);
850 return;
851 }
852 reg_read(0x10207e04, &value);
853 value &= (~(1 << 31));
854 value |= (enable << 31);
855 reg_write(0x10207e04, value);
856} /*end mac_set_fc */
857
858void an8855_qos_sch_select(int argc, char *argv[])
859{
860 unsigned char port, queue;
861 unsigned char type = 0;
862 unsigned int value, reg;
863
864 if (argc < 7)
865 return;
866
867 port = _strtoul(argv[3], NULL, 10);
868 queue = _strtoul(argv[4], NULL, 10);
869 type = _strtoul(argv[6], NULL, 10);
870
871 if (port > 6 || queue > 7) {
872 printf("\n Illegal input parameters\n");
873 return;
874 }
875
876 if ((type != 0 && type != 1 && type != 2)) {
877 printf(HELP_QOS_TYPE);
878 return;
879 }
880
881 printf("\r\nswitch qos type: %d.\n", type);
882
883 if (type == 0) {
884 air_qos_setScheduleAlgo(0, port, queue, AIR_QOS_SCH_MODE_WRR,
885 1);
886 } else if (type == 1) {
887 air_qos_setScheduleAlgo(0, port, queue, AIR_QOS_SCH_MODE_SP, 1);
888 } else {
889 air_qos_setScheduleAlgo(0, port, queue, AIR_QOS_SCH_MODE_WFQ,
890 1);
891 }
892}
893
894void an8855_get_upw(unsigned int *value, unsigned char base)
895{
896 *value &= (~((0x7 << 0) | (0x7 << 4) | (0x7 << 8) | (0x7 << 12) |
897 (0x7 << 16) | (0x7 << 20)));
898 switch (base) {
899 case 0: /* port-based 0x2x40[18:16] */
900 *value |= ((0x2 << 0) | (0x2 << 4) | (0x2 << 8) |
901 (0x2 << 12) | (0x7 << 16) | (0x2 << 20));
902 break;
903 case 1: /* tagged-based 0x2x40[10:8] */
904 *value |= ((0x2 << 0) | (0x2 << 4) | (0x7 << 8) |
905 (0x2 << 12) | (0x2 << 16) | (0x2 << 20));
906 break;
907 case 2: /* DSCP-based 0x2x40[14:12] */
908 *value |= ((0x2 << 0) | (0x2 << 4) | (0x2 << 8) |
909 (0x7 << 12) | (0x2 << 16) | (0x2 << 20));
910 break;
911 case 3: /* acl-based 0x2x40[2:0] */
912 *value |= ((0x7 << 0) | (0x2 << 4) | (0x2 << 8) |
913 (0x2 << 12) | (0x2 << 16) | (0x2 << 20));
914 break;
915 case 4: /* arl-based 0x2x40[22:20] */
916 *value |= ((0x2 << 0) | (0x2 << 4) | (0x2 << 8) |
917 (0x2 << 12) | (0x2 << 16) | (0x7 << 20));
918 break;
919 case 5: /* stag-based 0x2x40[6:4] */
920 *value |= ((0x2 << 0) | (0x7 << 4) | (0x2 << 8) |
921 (0x2 << 12) | (0x2 << 16) | (0x2 << 20));
922 break;
923 default:
924 break;
925 }
926}
927
928void an8855_qos_set_base(int argc, char *argv[])
929{
930 unsigned char base = 0;
931 unsigned char port;
932 unsigned int value;
933
934 if (argc < 5)
935 return;
936
937 port = _strtoul(argv[3], NULL, 10);
938 base = _strtoul(argv[4], NULL, 10);
939
940 if (base > 6) {
941 printf(HELP_QOS_BASE);
942 return;
943 }
944
945 if (port > 6) {
946 printf("Illegal port index:%d\n", port);
947 return;
948 }
949
950 printf("\r\nswitch qos base : %d. (port-based:0, tag-based:1,\
951 dscp-based:2, acl-based:3, arl-based:4, stag-based:5)\n", base);
952 reg_read(0x10208030 + 0x200 * port, &value);
953 an8855_get_upw(&value, base);
954 reg_write(0x10208030 + 0x200 * port, value);
955}
956
957void an8855_qos_wfq_set_weight(int argc, char *argv[])
958{
959 int port, weight[8], i;
960 unsigned char queue;
961 unsigned int reg = 0, value = 0;
962
963 port = _strtoul(argv[3], NULL, 10);
964
965 for (i = 0; i < 8; i++) {
966 weight[i] = _strtoul(argv[i + 4], NULL, 10);
967 }
968
969 /* MT7530 total 7 port */
970 if (port < 0 || port > 6) {
971 printf(HELP_QOS_PORT_WEIGHT);
972 return;
973 }
974
975 for (i = 0; i < 8; i++) {
976 if (weight[i] < 1 || weight[i] > 16) {
977 printf(HELP_QOS_PORT_WEIGHT);
978 return;
979 }
980 }
981 printf("port: %x, q0: %x, q1: %x, q2: %x, q3: %x, \
982 q4: %x, q5: %x, q6: %x, q7: %x\n", port, weight[0], weight[1], weight[2], weight[3], weight[4], weight[5], weight[6], weight[7]);
983
984 for (queue = 0; queue < 8; queue++) {
985 air_qos_setScheduleAlgo(0, port, queue, AIR_QOS_SCH_MODE_WFQ,
986 weight[queue]);
987 }
988}
989
990void an8855_qos_set_portpri(int argc, char *argv[])
991{
992 unsigned char port = 0, prio = 0;
993 unsigned int value = 0;
994
995 port = _strtoul(argv[3], NULL, 10);
996 prio = _strtoul(argv[4], NULL, 10);
997
998 if (port >= 7 || prio > 7) {
999 printf(HELP_QOS_PORT_PRIO);
1000 return;
1001 }
1002
1003 air_qos_setPortPriority(0, port, prio);
1004}
1005
1006void an8855_qos_set_dscppri(int argc, char *argv[])
1007{
1008 unsigned char prio = 0, dscp = 0, pim_n = 0, pim_offset = 0;
1009 unsigned int reg = 0, value = 0;
1010
1011 dscp = _strtoul(argv[3], NULL, 10);
1012 prio = _strtoul(argv[4], NULL, 10);
1013
1014 if (dscp > 63 || prio > 7) {
1015 printf(HELP_QOS_DSCP_PRIO);
1016 return;
1017 }
1018
1019 air_qos_setDscp2Pri(0, dscp, prio);
1020}
1021
1022void an8855_qos_pri_mapping_queue(int argc, char *argv[])
1023{
1024 unsigned char prio = 0, queue = 0, pem_n = 0, port = 0;
1025 unsigned int reg = 0, value = 0;
1026
1027 if (argc < 6)
1028 return;
1029
1030 port = _strtoul(argv[3], NULL, 10);
1031 prio = _strtoul(argv[4], NULL, 10);
1032 queue = _strtoul(argv[5], NULL, 10);
1033
1034 if (prio > 7 || queue > 7) {
1035 printf(HELP_QOS_PRIO_QMAP);
1036 return;
1037 }
1038
1039 air_qos_setPri2Queue(0, prio, queue);
1040}
1041
1042void an8855_doVlanSetPvid(int argc, char *argv[])
1043{
1044 unsigned char port = 0;
1045 unsigned short pvid = 0;
1046
1047 port = _strtoul(argv[3], NULL, 10);
1048 pvid = _strtoul(argv[4], NULL, 10);
1049 /*Check the input parameters is right or not. */
1050 if ((port >= SWITCH_MAX_PORT) || (pvid > MAX_VID_VALUE)) {
1051 printf(HELP_VLAN_PVID);
1052 return;
1053 }
1054
1055 air_vlan_setPortPVID(0, port, pvid);
1056
1057 printf("port:%d pvid:%d,vlancap: max_port:%d maxvid:%d\r\n",
1058 port, pvid, SWITCH_MAX_PORT, MAX_VID_VALUE);
1059} /*end doVlanSetPvid */
1060
1061void an8855_doVlanSetVid(int argc, char *argv[])
1062{
1063 unsigned char index = 0;
1064 unsigned char active = 0;
1065 unsigned char portMap = 0;
1066 unsigned char tagPortMap = 0;
1067 unsigned short vid = 0;
1068
1069 unsigned char ivl_en = 0;
1070 unsigned char fid = 0;
1071 unsigned short stag = 0;
1072 int i = 0;
1073 AIR_VLAN_ENTRY_T vlan_entry = { 0 };
1074
1075 index = _strtoul(argv[3], NULL, 10);
1076 active = _strtoul(argv[4], NULL, 10);
1077 vid = _strtoul(argv[5], NULL, 10);
1078
1079 /*Check the input parameters is right or not. */
1080 if ((index >= MAX_VLAN_RULE) || (vid >= 4096) || (active > ACTIVED)) {
1081 printf(HELP_VLAN_VID);
1082 return;
1083 }
1084
1085 /*CPU Port is always the membership */
1086 portMap = _strtoul(argv[6], NULL, 10);
1087 tagPortMap = _strtoul(argv[7], NULL, 10);
1088
1089 printf("subcmd parameter argc = %d\r\n", argc);
1090 if (argc >= 9) {
1091 ivl_en = _strtoul(argv[8], NULL, 10);
1092 if (argc >= 10) {
1093 fid = _strtoul(argv[9], NULL, 10);
1094 if (argc >= 11)
1095 stag = _strtoul(argv[10], NULL, 10);
1096 }
1097 }
1098
1099 printf("index: %x, active: %x, vid: %x, portMap: %x, \
1100 tagPortMap: %x, ivl_en: %x, fid: %x, stag: %x\n", index, active, vid, portMap, tagPortMap, ivl_en, fid, stag);
1101
1102 vlan_entry.valid = ! !active;
1103 vlan_entry.vlan_entry_format.port_mem = portMap;
1104 /* Total 6 ports */
1105 for (i = 0; i < SWITCH_MAX_PORT; i++) {
1106 if (tagPortMap & (1 << i))
1107 vlan_entry.vlan_entry_format.eg_ctrl |= 0x2 << (i * 2);
1108 }
1109 vlan_entry.vlan_entry_format.ivl = ! !ivl_en;
1110 vlan_entry.vlan_entry_format.fid = fid;
1111 vlan_entry.vlan_entry_format.stag = stag;
1112
1113 _air_vlan_writeEntry(0, vid, &vlan_entry);
1114
1115 printf("index:%d active:%d vid:%d\r\n", index, active, vid);
1116} /*end doVlanSetVid */
1117
1118void an8855_doVlanSetAccFrm(int argc, char *argv[])
1119{
1120 unsigned char port = 0;
1121 unsigned char type = 0;
1122 AIR_VLAN_ACCEPT_FRAME_TYPE_T type_t = AIR_VLAN_ACCEPT_FRAME_TYPE_ALL;
1123
1124 port = _strtoul(argv[3], NULL, 10);
1125 type = _strtoul(argv[4], NULL, 10);
1126
1127 printf("port: %d, type: %d\n", port, type);
1128
1129 /*Check the input parameters is right or not. */
1130 if ((port > SWITCH_MAX_PORT) || (type > REG_PVC_ACC_FRM_RELMASK)) {
1131 printf(HELP_VLAN_ACC_FRM);
1132 return;
1133 }
1134
1135 type_t = (AIR_VLAN_ACCEPT_FRAME_TYPE_T) type;
1136 air_vlan_setPortAcceptFrameType(0, port, type_t);
1137} /*end doVlanSetAccFrm */
1138
1139void an8855_doVlanSetPortAttr(int argc, char *argv[])
1140{
1141 unsigned char port = 0;
1142 unsigned char attr = 0;
1143 AIR_VLAN_PORT_ATTR_T attr_t = AIR_VLAN_PORT_ATTR_USER_PORT;
1144
1145 port = _strtoul(argv[3], NULL, 10);
1146 attr = _strtoul(argv[4], NULL, 10);
1147
1148 printf("port: %x, attr: %x\n", port, attr);
1149
1150 /*Check the input parameters is right or not. */
1151 if (port > SWITCH_MAX_PORT || attr > 3) {
1152 printf(HELP_VLAN_PORT_ATTR);
1153 return;
1154 }
1155
1156 attr_t = (AIR_VLAN_PORT_ATTR_T) attr;
1157 air_vlan_setPortAttr(0, port, attr_t);
1158}
1159
1160void an8855_doVlanSetPortMode(int argc, char *argv[])
1161{
1162 unsigned char port = 0;
1163 unsigned char mode = 0;
1164 AIR_PORT_VLAN_MODE_T mode_t = AIR_PORT_VLAN_MODE_PORT_MATRIX;
1165
1166 port = _strtoul(argv[3], NULL, 10);
1167 mode = _strtoul(argv[4], NULL, 10);
1168 printf("port: %x, mode: %x\n", port, mode);
1169
1170 /*Check the input parameters is right or not. */
1171 if (port > SWITCH_MAX_PORT || mode > 3) {
1172 printf(HELP_VLAN_PORT_MODE);
1173 return;
1174 }
1175
1176 mode_t = (AIR_PORT_VLAN_MODE_T) mode;
1177 air_port_setVlanMode(0, port, mode_t);
1178}
1179
1180void an8855_doVlanSetEgressTagPCR(int argc, char *argv[])
1181{
1182 unsigned char port = 0;
1183 unsigned char eg_tag = 0;
1184 AIR_PORT_EGS_TAG_ATTR_T eg_tag_t = AIR_PORT_EGS_TAG_ATTR_UNTAGGED;
1185
1186 port = _strtoul(argv[3], NULL, 10);
1187 eg_tag = _strtoul(argv[4], NULL, 10);
1188
1189 printf("port: %d, eg_tag: %d\n", port, eg_tag);
1190
1191 /*Check the input parameters is right or not. */
1192 if ((port > SWITCH_MAX_PORT) || (eg_tag > REG_PCR_EG_TAG_RELMASK)) {
1193 printf(HELP_VLAN_EGRESS_TAG_PCR);
1194 return;
1195 }
1196
1197 eg_tag_t = (AIR_PORT_EGS_TAG_ATTR_T) eg_tag;
1198 air_vlan_setPortEgsTagAttr(0, port, eg_tag_t);
1199} /*end doVlanSetEgressTagPCR */
1200
1201void an8855_doVlanSetEgressTagPVC(int argc, char *argv[])
1202{
1203 unsigned char port = 0;
1204 unsigned char eg_tag = 0;
1205 AIR_IGR_PORT_EG_TAG_ATTR_T eg_tag_t = 0;
1206
1207 port = _strtoul(argv[3], NULL, 10);
1208 eg_tag = _strtoul(argv[4], NULL, 10);
1209
1210 printf("port: %d, eg_tag: %d\n", port, eg_tag);
1211
1212 /*Check the input parameters is right or not. */
1213 if ((port > SWITCH_MAX_PORT) || (eg_tag > REG_PVC_EG_TAG_RELMASK)) {
1214 printf(HELP_VLAN_EGRESS_TAG_PVC);
1215 return;
1216 }
1217
1218 eg_tag_t = (AIR_IGR_PORT_EG_TAG_ATTR_T) eg_tag;
1219 air_vlan_setIgrPortTagAttr(0, port, eg_tag_t);
1220} /*end doVlanSetEgressTagPVC */
1221
1222void an8855_doArlAging(int argc, char *argv[])
1223{
1224 unsigned char aging_en = 0;
1225 unsigned int time = 0, port = 0;
1226
1227 aging_en = _strtoul(argv[3], NULL, 10);
1228 time = _strtoul(argv[4], NULL, 10);
1229 printf("aging_en: %x, aging time: %x\n", aging_en, time);
1230
1231 /*Check the input parameters is right or not. */
1232 if ((aging_en != 0 && aging_en != 1) || (time <= 0 || time > 65536)) {
1233 printf(HELP_ARL_AGING);
1234 return;
1235 }
1236
1237 for (port = 0; port < 6; port++) {
1238 air_l2_setAgeEnable(0, port, aging_en);
1239 }
1240
1241 air_l2_setMacAddrAgeOut(0, time);
1242}
1243
1244void an8855_doMirrorEn(int argc, char *argv[])
1245{
1246 unsigned char mirror_en = 0;
1247 unsigned char mirror_port = 0;
1248 AIR_MIR_SESSION_T session = { 0 };
1249
1250 mirror_en = _strtoul(argv[3], NULL, 10);
1251 mirror_port = _strtoul(argv[4], NULL, 10);
1252
1253 printf("mirror_en: %d, mirror_port: %d\n", mirror_en, mirror_port);
1254
1255 /*Check the input parameters is right or not. */
1256 if ((mirror_en > 1) || (mirror_port > REG_CFC_MIRROR_PORT_RELMASK)) {
1257 printf(HELP_MIRROR_EN);
1258 return;
1259 }
1260
1261 memset(&session, 0, sizeof(AIR_MIR_SESSION_T));
1262
1263 if (mirror_en) {
1264 session.dst_port = mirror_port;
1265 session.flags |= AIR_MIR_SESSION_FLAGS_ENABLE;
1266 air_mir_addSession(0, 0, &session);
1267 } else {
1268 air_mir_delSession(0, 0);
1269 }
1270
1271 air_mir_setSessionAdminMode(0, 0, (int)mirror_en);
1272} /*end doMirrorEn */
1273
1274void an8855_doMirrorPortBased(int argc, char *argv[])
1275{
1276 unsigned char port = 0, port_tx_mir = 0, port_rx_mir = 0, vlan_mis =
1277 0, acl_mir = 0, igmp_mir = 0;
1278 unsigned int reg = 0, value = 0;
1279 AIR_MIR_SESSION_T session = { 0 };
1280
1281 port = _strtoul(argv[3], NULL, 10);
1282 port_tx_mir = _strtoul(argv[4], NULL, 10);
1283 port_rx_mir = _strtoul(argv[5], NULL, 10);
1284 acl_mir = _strtoul(argv[6], NULL, 10);
1285 vlan_mis = _strtoul(argv[7], NULL, 10);
1286 igmp_mir = _strtoul(argv[8], NULL, 10);
1287
1288 printf
1289 ("port:%d, port_tx_mir:%d, port_rx_mir:%d, acl_mir:%d, vlan_mis:%d, igmp_mir:%d\n",
1290 port, port_tx_mir, port_rx_mir, acl_mir, vlan_mis, igmp_mir);
1291
1292 /*Check the input parameters is right or not. */
1293 //if((port >= vlanCap->max_port_no) || (port_tx_mir > 1) || (port_rx_mir > 1) || (acl_mir > 1) || (vlan_mis > 1)){
1294 if ((port >= SWITCH_MAX_PORT) || (port_tx_mir > 1) || (port_rx_mir > 1) || (acl_mir > 1) || (vlan_mis > 1)) { // also allow CPU port (port6)
1295 printf(HELP_MIRROR_PORTBASED);
1296 return;
1297 }
1298
1299 memset(&session, 0, sizeof(AIR_MIR_SESSION_T));
1300 air_mir_getSession(0, 0, &session);
1301 session.src_port = port;
1302
1303 if (port_tx_mir)
1304 session.flags |= AIR_MIR_SESSION_FLAGS_DIR_TX;
1305 else
1306 session.flags &= ~AIR_MIR_SESSION_FLAGS_DIR_TX;
1307
1308 if (port_rx_mir)
1309 session.flags |= AIR_MIR_SESSION_FLAGS_DIR_RX;
1310 else
1311 session.flags &= ~AIR_MIR_SESSION_FLAGS_DIR_RX;
1312
1313 air_mir_setMirrorPort(0, 0, &session);
1314
1315 /*
1316
1317 not support acl/vlan/igmp mismatch
1318
1319 */
1320} /*end doMirrorPortBased */
1321
1322void an8855_doStp(int argc, char *argv[])
1323{
1324 unsigned char port = 0;
1325 unsigned char fid = 0;
1326 unsigned char state = 0;
1327 unsigned int value = 0;
1328 unsigned int reg = 0;
1329
1330 port = _strtoul(argv[2], NULL, 10);
1331 fid = _strtoul(argv[3], NULL, 10);
1332 state = _strtoul(argv[4], NULL, 10);
1333
1334 printf("port: %d, fid: %d, state: %d\n", port, fid, state);
1335
1336 /*Check the input parameters is right or not. */
1337 if ((port > 5) || (fid > 16) || (state > 3)) {
1338 printf(HELP_STP);
1339 return;
1340 }
1341
1342 air_stp_setPortstate(0, port, fid, state);
1343}
1344
1345void _an8855_ingress_rate_set(int on_off, unsigned char port, unsigned int bw)
1346{
1347 AIR_ERROR_NO_T ret = AIR_E_OK;
1348 AIR_QOS_RATE_LIMIT_CFG_T rl = { 0 };
1349 if (on_off) {
1350 ret =
1351 air_qos_setRateLimitEnable(0, port,
1352 AIR_QOS_RATE_DIR_INGRESS, TRUE);
1353 if (AIR_E_OK != ret) {
1354 printf("an8855 set ingress ratelimit eanble fail\n");
1355 return;
1356 }
1357 rl.ingress_cir = bw;
1358 rl.flags |= AIR_QOS_RATE_LIMIT_CFG_FLAGS_ENABLE_INGRESS;
1359 ret = air_qos_setRateLimit(0, port, &rl);
1360 if (AIR_E_OK != ret) {
1361 printf("an8855 set ingress ratelimit value %d fail\n",
1362 bw);
1363 return;
1364 } else {
1365 printf("an8855 set ingress ratelimit value %d ok\n",
1366 bw);
1367 }
1368 } else {
1369 ret =
1370 air_qos_setRateLimitEnable(0, port,
1371 AIR_QOS_RATE_DIR_INGRESS, FALSE);
1372 if (AIR_E_OK != ret) {
1373 printf("an8855 set ingress ratelimit disable fail\n");
1374 return;
1375 } else {
1376 printf("an8855 set ingress ratelimit disable ok\n");
1377 }
1378 }
1379}
1380
1381void _an8855_egress_rate_set(int on_off, unsigned char port, unsigned int bw)
1382{
1383 AIR_ERROR_NO_T ret = AIR_E_OK;
1384 AIR_QOS_RATE_LIMIT_CFG_T rl = { 0 };
1385 if (on_off) {
1386 ret =
1387 air_qos_setRateLimitEnable(0, port, AIR_QOS_RATE_DIR_EGRESS,
1388 TRUE);
1389 if (AIR_E_OK != ret) {
1390 printf("an8855 set egress ratelimit eanble fail\n");
1391 return;
1392 }
1393 rl.egress_cir = bw;
1394 rl.flags |= AIR_QOS_RATE_LIMIT_CFG_FLAGS_ENABLE_EGRESS;
1395 ret = air_qos_setRateLimit(0, port, &rl);
1396 if (AIR_E_OK != ret) {
1397 printf("an8855 set egress ratelimit value %d fail\n",
1398 bw);
1399 return;
1400 } else {
1401 printf("an8855 set egress ratelimit value %d ok\n", bw);
1402 }
1403 } else {
1404 ret =
1405 air_qos_setRateLimitEnable(0, port, AIR_QOS_RATE_DIR_EGRESS,
1406 FALSE);
1407 if (AIR_E_OK != ret) {
1408 printf("an8855 set egress ratelimit disable fail\n");
1409 return;
1410 } else {
1411 printf("an8855 set egress ratelimit disable ok\n");
1412 }
1413 }
1414}
1415
1416void an8855_ingress_rate_set(int argc, char *argv[])
1417{
1418 int on_off = 0, port, bw = 0;
1419
1420 port = _strtoul(argv[3], NULL, 0);
1421 if (argv[2][1] == 'n') {
1422 bw = _strtoul(argv[4], NULL, 0);
1423 on_off = 1;
1424 } else if (argv[2][1] == 'f') {
1425 if (argc != 4) {
1426 return;
1427 }
1428 on_off = 0;
1429 }
1430
1431 _an8855_ingress_rate_set(on_off, port, bw);
1432}
1433
1434void an8855_egress_rate_set(int argc, char *argv[])
1435{
1436 unsigned int reg = 0, value = 0;
1437 int on_off = 0, port = 0, bw = 0;
1438
1439 port = _strtoul(argv[3], NULL, 0);
1440 if (argv[2][1] == 'n') {
1441 bw = _strtoul(argv[4], NULL, 0);
1442 on_off = 1;
1443 } else if (argv[2][1] == 'f') {
1444 if (argc != 4) {
1445 return;
1446 }
1447 on_off = 0;
1448 }
1449
1450 _an8855_egress_rate_set(on_off, port, bw);
1451}
1452
1453void an8855_rate_control(int argc, char *argv[])
1454{
1455 unsigned char dir = 0;
1456 unsigned char port = 0;
1457 unsigned int rate_cir = 0;
1458
1459 dir = _strtoul(argv[2], NULL, 10);
1460 port = _strtoul(argv[3], NULL, 10);
1461 rate_cir = _strtoul(argv[4], NULL, 10);
1462
1463 if (port > 5) {
1464 printf("Error, port %d is bigger than 5\n\r", port);
1465 return;
1466 }
1467 if (rate_cir > 80000) {
1468 printf("Error, rate_cir %d is bigger than 80000\n\r", rate_cir);
1469 return;
1470 }
1471
1472 if (dir == 1) //ingress
1473 _an8855_ingress_rate_set(1, port, rate_cir);
1474 else if (dir == 0) //egress
1475 _an8855_egress_rate_set(1, port, rate_cir);
1476 else
1477 printf("Error, dir %d is not 1(ingress) and 0(egress)\n\r",
1478 dir);
1479}
1480
1481void an8855_read_output_queue_counters(int argc, char *argv[])
1482{
1483 unsigned int port = 0;
1484 unsigned int value = 0, output_queue = 0;
1485
1486 for (port = 0; port < 7; port++) {
1487 reg_write(0x10207e48, 0x80000000 | (port << 8) | 0x0);
1488 reg_read(0x10207e4c, &output_queue);
1489 printf("\n port %d output queue 0 counter is %d.\n", port,
1490 output_queue);
1491 reg_write(0x10207e48, 0x80000000 | (port << 8) | 0x1);
1492 reg_read(0x10207e4c, &output_queue);
1493 printf("\n port %d output queue 1 counter is %d.\n", port,
1494 output_queue);
1495 reg_write(0x10207e48, 0x80000000 | (port << 8) | 0x2);
1496 reg_read(0x10207e4c, &output_queue);
1497 printf("\n port %d output queue 2 counter is %d.\n", port,
1498 output_queue);
1499 reg_write(0x10207e48, 0x80000000 | (port << 8) | 0x3);
1500 reg_read(0x10207e4c, &output_queue);
1501 printf("\n port %d output queue 3 counter is %d.\n", port,
1502 output_queue);
1503 reg_write(0x10207e48, 0x80000000 | (port << 8) | 0x4);
1504 reg_read(0x10207e4c, &output_queue);
1505 printf("\n port %d output queue 4 counter is %d.\n", port,
1506 output_queue);
1507 reg_write(0x10207e48, 0x80000000 | (port << 8) | 0x5);
1508 reg_read(0x10207e4c, &output_queue);
1509 printf("\n port %d output queue 5 counter is %d.\n", port,
1510 output_queue);
1511 reg_write(0x10207e48, 0x80000000 | (port << 8) | 0x6);
1512 reg_read(0x10207e4c, &output_queue);
1513 printf("\n port %d output queue 6 counter is %d.\n", port,
1514 output_queue);
1515 reg_write(0x10207e48, 0x80000000 | (port << 8) | 0x7);
1516 reg_read(0x10207e4c, &output_queue);
1517 printf("\n port %d output queue 7 counter is %d.\n", port,
1518 output_queue);
1519 }
1520}
1521
1522void an8855_read_free_page_counters(int argc, char *argv[])
1523{
1524 unsigned int value = 0;
1525 unsigned int free_page = 0, free_page_min = 0;
1526 unsigned int fc_free_blk_lothd = 0, fc_free_blk_hithd = 0;
1527 unsigned int fc_port_blk_thd = 0, fc_port_blk_hi_thd = 0;
1528 unsigned int queue[8] = { 0 };
1529
1530 /* get system free page link counter */
1531 reg_read(0x10207e00, &value);
1532 free_page = value & 0xFFF;
1533 free_page_min = (value & 0xFFF0000) >> 16;
1534
1535 /* get system flow control waterwark */
1536 reg_read(0x10207e04, &value);
1537 fc_free_blk_lothd = value & 0x3FF;
1538 fc_free_blk_hithd = (value & 0x1FF8000) >> 15;
1539
1540 /* get port flow control waterwark */
1541 reg_read(0x10207e08, &value);
1542 fc_port_blk_thd = (value & 0xFF00) >> 8;
1543 fc_port_blk_hi_thd = (value & 0xFF0000) >> 16;
1544
1545 /* get queue flow control waterwark */
1546 reg_read(0x10207e10, &value);
1547 queue[0] = value & 0x3F;
1548 queue[1] = (value & 0x3F00) >> 8;
1549 queue[2] = (value & 0x3F0000) >> 16;
1550 queue[3] = (value & 0x3F000000) >> 24;
1551 reg_read(0x10207e0c, &value);
1552 queue[4] = value & 0x3F;
1553 queue[5] = (value & 0x3F00) >> 8;
1554 queue[6] = (value & 0x3F0000) >> 16;
1555 queue[7] = (value & 0x3F000000) >> 24;
1556
1557 printf("<===Free Page=======Current============Minimal=========> \n ");
1558 printf(" \n ");
1559 printf(" page counter %u %u \n ",
1560 free_page, free_page_min);
1561 printf(" \n ");
1562 printf("========================================================= \n ");
1563 printf("<===Type=======High threshold======Low threshold=========\n ");
1564 printf(" \n ");
1565 printf(" system: %u %u \n",
1566 fc_free_blk_hithd * 2, fc_free_blk_lothd * 2);
1567 printf(" port: %u %u \n",
1568 fc_port_blk_hi_thd * 2, fc_port_blk_thd * 2);
1569 printf(" queue 0: %u NA \n",
1570 queue[0]);
1571 printf(" queue 1: %u NA \n",
1572 queue[1]);
1573 printf(" queue 2: %u NA \n",
1574 queue[2]);
1575 printf(" queue 3: %u NA \n",
1576 queue[3]);
1577 printf(" queue 4: %u NA \n",
1578 queue[4]);
1579 printf(" queue 5: %u NA \n",
1580 queue[5]);
1581 printf(" queue 6: %u NA \n",
1582 queue[6]);
1583 printf(" queue 7: %u NA \n",
1584 queue[7]);
1585 printf("=========================================================\n ");
1586}
1587
1588void an8855_eee_enable(int argc, char *argv[])
1589{
1590 unsigned long enable = 0;
1591 unsigned int value, mode = 0;
1592 unsigned int eee_cap = 0;
1593 unsigned int eee_en_bitmap = 0;
1594 unsigned long port_map = 0;
1595 long port_num = -1;
1596 int p = 0;
1597
1598 if (argc < 3)
1599 goto error;
1600
1601 /* Check the input parameters is right or not. */
1602 if (!strncmp(argv[2], "enable", 7))
1603 enable = 1;
1604 else if (!strncmp(argv[2], "disable", 8))
1605 enable = 0;
1606 else
1607 goto error;
1608
1609 if (argc > 3) {
1610 if (strlen(argv[3]) == 1) {
1611 port_num = strtol(argv[3], (char **)NULL, 10);
1612 if (port_num < 0 || port_num > MAX_PHY_PORT - 1) {
1613 printf("Illegal port index and port:0~4\n");
1614 goto error;
1615 }
1616 port_map = 1 << port_num;
1617 } else if (strlen(argv[3]) == 5) {
1618 port_map = 0;
1619 for (p = 0; p < MAX_PHY_PORT; p++) {
1620 if (argv[3][p] != '0' && argv[3][p] != '1') {
1621 printf
1622 ("portmap format error, should be combination of 0 or 1\n");
1623 goto error;
1624 }
1625 port_map |= ((argv[3][p] - '0') << p);
1626 }
1627 } else {
1628 printf
1629 ("port_no or portmap format error, should be length of 1 or 5\n");
1630 goto error;
1631 }
1632 } else {
1633 port_map = 0x1f;
1634 }
1635
1636 for (port_num = 0; port_num < MAX_PHY_PORT; port_num++) {
1637 if (port_map & (1 << port_num)) {
1638 air_port_getPsMode(0, port_num, &mode);
1639 if (enable) {
1640 mode |= AIR_PORT_PS_EEE;
1641 } else {
1642 mode &= ~AIR_PORT_PS_EEE;
1643 }
1644 air_port_setPsMode(0, port_num, mode);
1645 }
1646 }
1647 return;
1648
1649error:
1650 printf(HELP_EEE_EN);
1651 return;
1652}
1653
1654void an8855_eee_dump(int argc, char *argv[])
1655{
1656 unsigned int cap = 0, lp_cap = 0;
1657 long port = -1;
1658 int p = 0;
1659
1660 if (argc > 3) {
1661 if (strlen(argv[3]) > 1) {
1662 printf("port# format error, should be of length 1\n");
1663 return;
1664 }
1665
1666 port = strtol(argv[3], (char **)NULL, 0);
1667 if (port < 0 || port > MAX_PHY_PORT) {
1668 printf("port# format error, should be 0 to %d\n",
1669 MAX_PHY_PORT);
1670 return;
1671 }
1672 }
1673
1674 for (p = 0; p < MAX_PHY_PORT; p++) {
1675 if (port >= 0 && p != port)
1676 continue;
1677
1678 mii_mgr_c45_read(p, 0x7, 0x3c, &cap);
1679 mii_mgr_c45_read(p, 0x7, 0x3d, &lp_cap);
1680 printf("port%d EEE cap=0x%02x, link partner EEE cap=0x%02x",
1681 p, cap, lp_cap);
1682
1683 if (port >= 0 && p == port) {
1684 mii_mgr_c45_read(p, 0x3, 0x1, &cap);
1685 printf(", st=0x%03x", cap);
1686 }
1687 printf("\n");
1688 }
1689}
1690
1691void an8855_read_mib_counters(int argc, char *argv[])
1692{
1693 int port = 0;
1694 AIR_MIB_CNT_RX_T rx_mib[7];
1695 AIR_MIB_CNT_TX_T tx_mib[7];
1696
1697 printf("===================== %8s %8s %8s %8s %8s %8s %8s\n",
1698 "Port0", "Port1", "Port2", "Port3", "Port4", "Port5", "Port6");
1699
1700 for (port = 0; port < 7; port++) {
1701 air_mib_get(0, port, &rx_mib[port], &tx_mib[port]);
1702 }
1703
1704 printf("Tx Drop Packet :");
1705 for (port = 0; port < 7; port++) {
1706 printf("%8u ", tx_mib[port].TDPC);
1707 }
1708 printf("\n");
1709 printf("Tx CRC Error :");
1710 for (port = 0; port < 7; port++) {
1711 printf("%8u ", tx_mib[port].TCRC);
1712 }
1713 printf("\n");
1714 printf("Tx Unicast Packet :");
1715 for (port = 0; port < 7; port++) {
1716 printf("%8u ", tx_mib[port].TUPC);
1717 }
1718 printf("\n");
1719 printf("Tx Multicast Packet :");
1720 for (port = 0; port < 7; port++) {
1721 printf("%8u ", tx_mib[port].TMPC);
1722 }
1723 printf("\n");
1724 printf("Tx Broadcast Packet :");
1725 for (port = 0; port < 7; port++) {
1726 printf("%8u ", tx_mib[port].TBPC);
1727 }
1728 printf("\n");
1729 printf("Tx Collision Event :");
1730 for (port = 0; port < 7; port++) {
1731 printf("%8u ", tx_mib[port].TCEC);
1732 }
1733 printf("\n");
1734 printf("Tx Pause Packet :");
1735 for (port = 0; port < 7; port++) {
1736 printf("%8u ", tx_mib[port].TPPC);
1737 }
1738 printf("\n");
1739 printf("Rx Drop Packet :");
1740 for (port = 0; port < 7; port++) {
1741 printf("%8u ", rx_mib[port].RDPC);
1742 }
1743 printf("\n");
1744 printf("Rx Filtering Packet :");
1745 for (port = 0; port < 7; port++) {
1746 printf("%8u ", rx_mib[port].RFPC);
1747 }
1748 printf("\n");
1749 printf("Rx Unicast Packet :");
1750 for (port = 0; port < 7; port++) {
1751 printf("%8u ", rx_mib[port].RUPC);
1752 }
1753 printf("\n");
1754 printf("Rx Multicast Packet :");
1755 for (port = 0; port < 7; port++) {
1756 printf("%8u ", rx_mib[port].RMPC);
1757 }
1758 printf("\n");
1759 printf("Rx Broadcast Packet :");
1760 for (port = 0; port < 7; port++) {
1761 printf("%8u ", rx_mib[port].RBPC);
1762 }
1763 printf("\n");
1764 printf("Rx Alignment Error :");
1765 for (port = 0; port < 7; port++) {
1766 printf("%8u ", rx_mib[port].RAEPC);
1767 }
1768 printf("\n");
1769 printf("Rx CRC Error :");
1770 for (port = 0; port < 7; port++) {
1771 printf("%8u ", rx_mib[port].RCEPC);
1772 }
1773 printf("\n");
1774 printf("Rx Undersize Error :");
1775 for (port = 0; port < 7; port++) {
1776 printf("%8u ", rx_mib[port].RUSPC);
1777 }
1778 printf("\n");
1779 printf("Rx Fragment Error :");
1780 for (port = 0; port < 7; port++) {
1781 printf("%8u ", rx_mib[port].RFEPC);
1782 }
1783 printf("\n");
1784 printf("Rx Oversize Error :");
1785 for (port = 0; port < 7; port++) {
1786 printf("%8u ", rx_mib[port].ROSPC);
1787 }
1788 printf("\n");
1789 printf("Rx Jabber Error :");
1790 for (port = 0; port < 7; port++) {
1791 printf("%8u ", rx_mib[port].RJEPC);
1792 }
1793 printf("\n");
1794 printf("Rx Pause Packet :");
1795 for (port = 0; port < 7; port++) {
1796 printf("%8u ", rx_mib[port].RPPC);
1797 }
1798 printf("\n");
1799}
1800
1801void an8855_clear_mib_counters(int argc, char *argv[])
1802{
1803 air_mib_clear(0);
1804}