blob: 54d1fe620284951ef0208d22ede98e4d4fe9fa6e [file] [log] [blame]
developer880c8292022-07-11 11:52:59 +08001/*
2 * switch_753x.c: set for 753x switch
3 */
4#include <stdio.h>
5#include <stdlib.h>
6#include <unistd.h>
7#include <string.h>
8#include <sys/ioctl.h>
9#include <sys/socket.h>
10#include <linux/if.h>
11
12#include "switch_netlink.h"
13#include "switch_ioctl.h"
14#include "switch_fun.h"
15
16struct mt753x_attr *attres;
17int chip_name;
18bool nl_init_flag;
19
20static void usage(char *cmd)
21{
22 printf("==================Usage===============================================================================================================================\n");
23
24 /* 1. basic operations */
25 printf("1) mt753x switch Basic operations=================================================================================================================>>>>\n");
26 printf(" 1.1) %s devs - list switch device id and model name \n", cmd);
27 printf(" 1.2) %s sysctl - show the ways to access kenerl driver: netlink or ioctl \n", cmd);
28 printf(" 1.3) %s reset - sw reset switch fsm and registers\n", cmd);
29 printf(" 1.4) %s reg r [offset] - read the reg with default switch \n", cmd);
30 printf(" 1.5) %s reg w [offset] [value] - write the reg with default switch \n", cmd);
31 printf(" 1.6) %s reg d [offset] - dump the reg with default switch\n", cmd);
32 printf(" 1.7) %s dev [devid] reg r [addr] - read the reg with the switch devid \n", cmd);
33 printf(" 1.8) %s dev [devid] reg w [addr] [value] - write the regs with the switch devid \n", cmd);
34 printf(" 1.9) %s dev [devid] reg d [addr] - dump the regs with the switch devid \n", cmd);
35 printf(" \n");
36
37 /* 2. phy operations */
38 printf("2) mt753x switch PHY operations===================================================================================================================>>>>\n");
39 printf(" 2.1) %s phy - dump all phy registers (clause 22)\n", cmd);
40 printf(" 2.2) %s phy [phy_addr] - dump phy register of specific port (clause 22)\n", cmd);
41 printf(" 2.3) %s phy cl22 r [port_num] [phy_reg] - read specific phy register of specific port by clause 22\n", cmd);
42 printf(" 2.4) %s phy cl22 w [port_num] [phy_reg] [value] - write specific phy register of specific port by clause 22\n", cmd);
43 printf(" 2.5) %s phy cl45 r [port_num] [dev_num] [phy_reg] - read specific phy register of specific port by clause 45\n", cmd);
44 printf(" 2.6) %s phy cl45 w [port_num] [dev_num] [phy_reg] [value] - write specific phy register of specific port by clause 45\n", cmd);
45 printf(" 2.7) %s phy fc [port_num] [enable 0|1] - set switch phy flow control, port is 0~4, enable is 1, disable is 0 \n", cmd);
46 printf(" 2.8) %s phy an [port_num] [enable 0|1] - set switch phy auto-negotiation, port is 0~4, enable is 1, disable is 0 \n", cmd);
47 printf(" 2.9) %s trreg r [port_num] [ch_addr] [node_addr] [data_addr] - read phy token-ring of specific port\n", cmd);
48 printf(" 2.10) %s trreg w [port_num] [ch_addr] [node_addr] [data_addr] - write phy token-ring of specific port\n", cmd);
49 printf(" [high_value] [low_value] \n");
50 printf(" 2.11) %s crossover [port_num] [mode auto|mdi|mdix] - switch auto or force mdi/mdix mode for crossover cable\n", cmd);
51 printf(" \n");
52
53 /* 3. mac operations */
54 printf("3) mt753x switch MAC operations====================================================================================================================>>>>\n");
55 printf(" 3.1) %s dump - dump switch mac table\n", cmd);
56 printf(" 3.2) %s clear - clear switch mac table\n", cmd);
57 printf(" 3.3) %s add [mac] [portmap] - add an entry (with portmap) to switch mac table\n", cmd);
58 printf(" 3.4) %s add [mac] [portmap] [vlan id] - add an entry (with portmap, vlan id) to switch mac table\n", cmd);
59 printf(" 3.5) %s add [mac] [portmap] [vlan id] [age] - add an entry (with portmap, vlan id, age out time) to switch mac table\n", cmd);
60 printf(" 3.6) %s del mac [mac] vid [vid] - delete an entry from switch mac table\n", cmd);
61 printf(" 3.7) %s del mac [mac] fid [fid] - delete an entry from switch mac table\n", cmd);
62 printf(" 3.8) %s search mac [mac] vid [vid] - search an entry with specific mac and vid\n", cmd);
63 printf(" 3.9) %s search mac [mac] fid [fid] - search an entry with specific mac and fid\n", cmd);
64 printf(" 3.10) %s filt [mac] - add a SA filtering entry (with portmap 1111111) to switch mac table\n", cmd);
65 printf(" 3.11) %s filt [mac] [portmap] - add a SA filtering entry (with portmap)to switch mac table\n", cmd);
66 printf(" 3.12) %s filt [mac] [portmap] [vlan id - add a SA filtering entry (with portmap, vlan id)to switch mac table\n", cmd);
67 printf(" 3.13) %s filt [mac] [portmap] [vlan id] [age] - add a SA filtering entry (with portmap, vlan id, age out time) to switch table\n", cmd);
68 printf(" 3.14) %s arl aging [active:0|1] [time:1~65536] - set switch arl aging timeout value \n", cmd);
69 printf(" 3.15) %s macctl fc [enable|disable] - set switch mac global flow control,enable is 1, disable is 0 \n", cmd);
70 printf(" \n");
71
72 /* 4. mib counter operations */
73 printf("4) mt753x switch mib counter operations============================================================================================================>>>>\n");
74 printf(" 4.1) %s esw_cnt get -get switch mib counters \n", cmd);
75 printf(" 4.2) %s esw_cnt clear -clear switch mib counters \n", cmd);
76 printf(" 4.3) %s output_queue_cnt get -get switch output queue counters \n", cmd);
77 printf(" 4.4) %s free_page get -get switch system free page counters \n", cmd);
78 printf(" \n");
79
80 /* 5. acl function operations */
81 printf("5) mt753x switch acl function operations============================================================================================================>>>>\n");
82 printf(" 5.1) %s acl enable [port] [port_enable:0|1] - set switch acl function enabled, port is 0~6,enable is 1, disable is 0 \n", cmd);
83 printf(" 5.2) %s acl etype add [ethtype] [portmap] - drop L2 ethertype packets \n", cmd);
84 printf(" 5.3) %s acl dmac add [mac] [portmap] - drop L2 dest-Mac packets \n", cmd);
85 printf(" 5.4) %s acl dip add [dip] [portmap] - drop dip packets \n", cmd);
86 printf(" 5.5) %s acl port add [sport] [portmap] - drop L4 UDP/TCP source port packets\n", cmd);
87 printf(" 5.6) %s acl L4 add [2byes] [portmap] - drop L4 packets with 2bytes payload\n", cmd);
88 printf(" 5.7) %s acl acltbl-add [tbl_idx:0~63/255] [vawd1] [vawd2] - set switch acl table new entry, max index-7530:63,7531:255 \n", cmd);
89 printf(" 5.8) %s acl masktbl-add [tbl_idx:0~31/127] [vawd1] [vawd2] - set switch acl mask table new entry, max index-7530:31,7531:127 \n", cmd);
90 printf(" 5.9) %s acl ruletbl-add [tbl_idx:0~31/127] [vawd1] [vawd2] - set switch acl rule table new entry, max index-7530:31,7531:127 \n", cmd);
91 printf(" 5.10) %s acl ratetbl-add [tbl_idx:0~31] [vawd1] [vawd2] - set switch acl rate table new entry \n", cmd);
92 printf(" 5.11) %s acl dip meter [dip] [portmap][meter:kbps] - rate limit dip packets \n", cmd);
93 printf(" 5.12) %s acl dip trtcm [dip] [portmap][CIR:kbps][CBS][PIR][PBS]- TrTCM dip packets \n", cmd);
94 printf(" 5.13) %s acl dip modup [dip] [portmap][usr_pri] - modify usr priority from ACL \n", cmd);
95 printf(" 5.14) %s acl dip pppoe [dip] [portmap] - pppoe header removal \n", cmd);
96 printf(" \n");
97
98 /* 6. dip table operations */
99 printf("6) mt753x switch dip table operations=================================================================================================================>>>>\n");
100 printf(" 6.1) %s dip dump - dump switch dip table\n", cmd);
101 printf(" 6.2) %s dip clear - clear switch dip table\n", cmd);
102 printf(" 6.3) %s dip add [dip] [portmap] - add a dip entry to switch table\n", cmd);
103 printf(" 6.4) %s dip del [dip] - del a dip entry to switch table\n", cmd);
104 printf(" \n");
105
106 /* 7. sip table operations */
107 printf("7) mt753x switch sip table operations=================================================================================================================>>>>\n");
108 printf(" 7.1) %s sip dump - dump switch sip table\n", cmd);
109 printf(" 7.2) %s sip clear - clear switch sip table\n", cmd);
110 printf(" 7.3) %s sip add [sip] [dip] [portmap] - add a sip entry to switch table\n", cmd);
111 printf(" 7.4) %s sip del [sip] [dip] - del a sip entry to switch table\n", cmd);
112 printf(" \n");
113
114 /* 8. vlan table operations */
115 printf("8) mt753x switch sip table operations====================================================================================================================>>>>\n");
116 printf(" 8.1) %s vlan dump - dump switch vlan table\n", cmd);
117 printf(" 8.2) %s vlan set [vlan idx] [vid] [portmap] - set vlan id and associated member at switch vlan table\n", cmd);
118 printf(" 8.3) %s vlan vid [vlan idx] [active:0|1] [vid] [portMap] - set switch vlan vid elements \n", cmd);
119 printf(" [egtagPortMap] [ivl_en] [fid] [stag] \n");
120 printf(" 8.4) %s vlan pvid [port] [pvid] - set switch vlan pvid \n", cmd);
121 printf(" 8.5) %s vlan acc-frm [port] [acceptable_frame_type:0~3] - set switch vlan acceptable_frame type : admit all frames: 0, \n", cmd);
122 printf(" admit only vlan-taged frames: 1,admit only untagged or priority-tagged frames: 2, reserved:3 \n");
123 printf(" 8.6) %s vlan port-attr [port] [attr:0~3] - set switch vlan port attribute: user port: 0, statck port: 1, \n", cmd);
124 printf(" translation port: 2, transparent port:3 \n");
125 printf(" 8.7) %s vlan port-mode [port] [mode:0~3] - set switch vlan port mode : port matrix mode: 0, fallback mode: 1, \n", cmd);
126 printf(" check mode: 2, security mode:3 \n");
127 printf(" 8.8) %s vlan eg-tag-pvc [port] [eg_tag:0~7] - set switch vlan eg tag pvc : disable: 0, consistent: 1, reserved: 2, \n", cmd);
128 printf(" reserved:3,untagged:4,swap:5,tagged:6, stack:7 \n");
129 printf(" 8.9) %s vlan eg-tag-pcr [port] [eg_tag:0~3] - set switch vlan eg tag pcr : untagged: 0, swap: 1, tagged: 2, stack:3 \n", cmd);
130 printf(" \n");
131
132 /* 9. rate limit operations */
133 printf("9) mt753x switch rate limit operations=================================================================================================================>>>>\n");
134 printf(" 9.1) %s ratectl [in_ex_gress:0|1] [port] [rate] - set switch port ingress(1) or egress(0) rate \n", cmd);
135 printf(" 9.2) %s ingress-rate on [port] [Kbps] - set ingress rate limit on port n (n= 0~ switch max port) \n", cmd);
136 printf(" 9.3) %s egress-rate on [port] [Kbps] - set egress rate limit on port n (n= 0~ switch max port) \n", cmd);
137 printf(" 9.4) %s ingress-rate off [port] - disable ingress rate limit on port n (n= 0~ switch max port) \n", cmd);
138 printf(" 9.5) %s egress-rate off [port] - disable egress rate limit on port n (n= 0~ switch max port)\n", cmd);
139 printf(" \n");
140
141 /* 10. igmp operations */
142 printf("10) mt753x igmp operations===============================================================================================================================>>>>\n");
143 printf(" 10.1) %s igmpsnoop on [leaky_en] [wan_num] - turn on IGMP snoop and router port learning\n", cmd);
144 printf(" leaky_en: 1 or 0. default 0; wan_num: 0 or 4. default 4\n");
145 printf(" 10.2) %s igmpsnoop off - turn off IGMP snoop and router port learning\n", cmd);
146 printf(" 10.3) %s igmpsnoop enable [port#] - enable IGMP HW leave/join/Squery/Gquery\n", cmd);
147 printf(" 10.4) %s igmpsnoop disable [port#] - disable IGMP HW leave/join/Squery/Gquery\n", cmd);
148 printf(" \n");
149
150 /* 11. QoS operations */
151 printf("11) mt753x QoS operations================================================================================================================================>>>>\n");
152 printf(" 11.1) %s qos sch [port:0~6] [queue:0~7] [shaper:min|max] [type:rr:0|sp:1|wfq:2] - set switch qos sch type\n", cmd);
153 printf(" 11.2) %s qos base [port:0~6] [base] - set switch qos base(UPW); port-based:0, tag-based:1, \n", cmd);
154 printf(" dscp-based:2, acl-based:3, arl-based:4, stag-based:5 \n");
155 printf(" 11.3) %s qos port-weight [port:0~6] [q0] [q1][q2][q3] - set switch qos port queue weight; \n", cmd);
156 printf(" [q4][q5][q6][q7] [qn]: the weight of queue n, range: 1~16 \n");
157 printf(" 11.4) %s qos port-prio [port:0~6] [prio:0~7] - set switch port qos user priority; port is 0~6, priority is 0~7 \n", cmd);
158 printf(" 11.5) %s qos dscp-prio [dscp:0~63] [prio:0~7] - set switch qos dscp user priority; dscp is 0~63, priority is 0~7 \n", cmd);
159 printf(" 11.6) %s qos prio-qmap [port:0~6] [prio:0~7] [queue:0~7] - set switch qos priority queue map; priority is 0~7,queue is 0~7 \n", cmd);
160 printf(" \n");
161
162 /*12. port mirror operations*/
163 printf(" 12) mt753x port mirror operations========================================================================================================================>>>>\n");
164 printf(" 12.1) %s mirror monitor [port] - enable port mirror and indicate monitor port number\n", cmd);
165 printf(" 12.2) %s mirror target [port] - set port mirror target\n", cmd);
166 printf(" [direction| 0:off, 1:rx, 2:tx, 3:all] \n");
167 printf(" 12.3) %s mirror enable [mirror_en:0|1] [mirror_port: 0-6] - set switch mirror function enable(1) or disabled(0) for port 0~6 \n", cmd);
168 printf(" 12.4) %s mirror port-based [port] [port_tx_mir:0|1] - set switch mirror port: target tx/rx/acl/vlan/igmp\n", cmd);
169 printf(" [port_rx_mir:0|1] [acl_mir:0|1] \n");
170 printf(" [vlan_mis:0|1] [igmp_mir:0|1] \n");
171 printf(" \n");
172
173 /*13. stp function*/
174 printf(" 13) mt753x stp operations===============================================================================================================================>>>>\n");
175 printf(" 13.1) %s stp [port] [fid] [state] - set switch spanning tree state, port is 0~6, fid is 0~7, \n", cmd);
176 printf(" state is 0~3(Disable/Discarding:0,Blocking/Listening/Discarding:1,) \n");
177 printf(" Learning:2,Forwarding:3 \n");
178 printf(" \n");
179
180 /*14. collision pool operations*/
181 printf("14) mt753x collision pool operations========================================================================================================================>>>>\n");
182 printf(" 14.1) %s collision-pool enable [enable 0|1] - enable or disable collision pool\n", cmd);
183 printf(" 14.2) %s collision-pool mac dump - dump collision pool mac table\n", cmd);
184 printf(" 14.3) %s collision-pool dip dump - dump collision pool dip table\n", cmd);
185 printf(" 14.4) %s collision-pool sip dump - dump collision pool sip table\n", cmd);
186 printf(" \n");
187
188 /*15. pfc(priority flow control) operations*/
189 printf("15) mt753x pfc(priority flow control) operations==============================================================================================================>>>>\n");
190 printf(" 15.1) %s pfc enable [port] [enable 0|1] - enable or disable port's pfc \n", cmd);
191 printf(" 15.2) %s pfc rx_counter [port] - get port n pfc 8 up rx counter \n", cmd);
192 printf(" 15.3) %s pfc tx_counter [port] - get port n pfc 8 up rx counter \n", cmd);
193 printf(" \n");
194
195 exit_free();
196 exit(0);
197}
198
199static void parse_reg_cmd(int argc, char *argv[], int len)
200{
201 int off, val = -1;
202 int i, j;
203
204 if (!strncmp(argv[len - 3], "reg", 4)) {
205 if (argv[len - 2][0] == 'r') {
206 off = strtoul(argv[len - 1], NULL, 16);
207 reg_read(off, &val);
208 printf(" Read reg=%x, value=%x\n", off, val);
209 } else if (argv[len - 2][0] == 'w') {
210 off = strtoul(argv[len - 1], NULL, 16);
211 if (argc != len + 1)
212 usage(argv[0]);
213 val = strtoul(argv[len], NULL, 16);
214 reg_write(off, val);
215 printf(" Write reg=%x, value=%x\n", off, val);
216 } else if (argv[len - 2][0] == 'd') {
217 off = strtoul(argv[len - 1], NULL, 16);
218 for (i = 0; i < 16; i++) {
219 printf("0x%08x: ", off + 0x10 * i);
220 for (j = 0; j < 4; j++) {
221 reg_read(off + i * 0x10 + j * 0x4, &val);
222 printf(" 0x%08x", val);
223 }
224 printf("\n");
225 }
226 } else
227 usage(argv[0]);
228 } else
229 usage(argv[0]);
230}
231
232static int get_chip_name()
233{
234 int temp;
235 /*judge 7530*/
236 reg_read((0x7ffc), &temp);
237 temp = temp >> 16;
238 if (temp == 0x7530)
239 return temp;
240 /*judge 7531*/
241 reg_read(0x781c, &temp);
242 temp = temp >> 16;
243 if (temp == 0x7531)
244 return temp;
245 return -1;
246}
247
248static int phy_operate(int argc, char *argv[])
249{
250 char op;
251 int ret = 0;
252 int port_num, dev_num, reg, value=-1;
253
254 if (strncmp(argv[2], "cl22", 4) && strncmp(argv[2], "cl45", 4))
255 usage(argv[0]);
256
257 op = argv[3][0];
258
259 switch(op) {
260 case 'r':
261 reg = strtoul(argv[argc-1], NULL, 0);
262 if (argc == 6) {
263 port_num = strtoul(argv[argc-2], NULL, 0);
264 ret = mii_mgr_read(port_num, reg, &value);
265 if (value == -1)
266 printf(" Phy read reg fail\n");
267 else
268 printf(" Phy read reg=0x%x, value=0x%x\n", reg, value);
269 } else if (argc == 7) {
270 dev_num = strtoul(argv[argc-2], NULL, 0);
271 port_num = strtoul(argv[argc-3], NULL, 0);
272 ret = mii_mgr_c45_read(port_num, dev_num, reg, &value);
273 if (value == -1)
274 printf(" Phy read reg fail\n");
275 else
276 printf(" Phy read reg=0x%x, value=0x%x\n", reg, value);
277 } else
278 ret = phy_dump(32);
279 break;
280 case 'w':
281 reg = strtoul(argv[argc-2], NULL, 0);
282 value = strtoul(argv[argc-1], NULL, 0);
283 if (argc == 7) {
284 port_num = strtoul(argv[argc-3], NULL, 0);
285 ret = mii_mgr_write(port_num, reg, value);
286 }
287 else if (argc == 8) {
288 dev_num = strtoul(argv[argc-3], NULL, 0);
289 port_num = strtoul(argv[argc-4], NULL, 0);
290 ret = mii_mgr_c45_write(port_num, dev_num, reg, value);
291 }
292 else
293 usage(argv[0]);
294 break;
295 default:
296 break;
297 }
298
299 return ret;
300}
301
302
303int main(int argc, char *argv[])
304{
305 int i, j;
306 int err;
307
308 attres = (struct mt753x_attr *)malloc(sizeof(struct mt753x_attr));
309 attres->dev_id = -1;
310 attres->port_num = -1;
311 attres->phy_dev = -1;
312 nl_init_flag = true;
313
314 switch_ioctl_init();
315 err = mt753x_netlink_init();
316 if (err < 0)
317 nl_init_flag = false;
318
319 chip_name = get_chip_name();
320 if (chip_name < 0) {
321 printf("no chip unsupport or chip id is invalid!\n");
322 exit_free();
323 exit(0);
324 }
325
326 if (argc < 2)
327 usage(argv[0]);
328
329 if (!strcmp(argv[1], "dev")) {
330 attres->dev_id = strtoul(argv[2], NULL, 0);
331 argv += 2;
332 argc -= 2;
333 if (argc < 2)
334 usage(argv[0]);
335
336 }
337
338 if (argc == 2) {
339 if (!strcmp(argv[1], "devs")) {
340 attres->type = MT753X_ATTR_TYPE_MESG;
341 mt753x_list_swdev(attres, MT753X_CMD_REQUEST);
342 } else if (!strncmp(argv[1], "dump", 5)) {
343 table_dump();
344 } else if (!strncmp(argv[1], "clear", 6)) {
345 table_clear();
346 printf("done.\n");
347 } else if (!strncmp(argv[1], "reset", 5)) {
348 switch_reset(argc, argv);
349 } else if (!strncmp(argv[1], "phy", 4)) {
350 phy_dump(32); //dump all phy register
351 } else if (!strncmp(argv[1], "sysctl", 7)) {
352 if (nl_init_flag)
353 printf("netlink(%s)\n",MT753X_GENL_NAME);
354 else
355 printf("ioctl(%s)\n",ETH_DEVNAME);
356 } else
357 usage(argv[0]);
358 } else if (!strncmp(argv[1], "arl", 4)) {
359 if (!strncmp(argv[2], "aging", 6))
360 doArlAging(argc, argv);
361 } else if (!strncmp(argv[1], "esw_cnt", 8)) {
362 if (!strncmp(argv[2], "get", 4))
363 read_mib_counters();
364 else if (!strncmp(argv[2], "clear", 6))
365 clear_mib_counters();
366 else
367 usage(argv[0]);
368 }else if (!strncmp(argv[1], "output_queue_cnt", 17)) {
369 if (!strncmp(argv[2], "get", 4))
370 read_output_queue_counters();
371 else
372 usage(argv[0]);
373 }else if (!strncmp(argv[1], "free_page", 10)) {
374 if (!strncmp(argv[2], "get", 4))
375 read_free_page_counters();
376 else
377 usage(argv[0]);
378 }
379 else if (!strncmp(argv[1], "ratectl", 8))
380 rate_control(argc, argv);
381 else if (!strncmp(argv[1], "add", 4))
382 table_add(argc, argv);
383 else if (!strncmp(argv[1], "filt", 5))
384 table_add(argc, argv);
385 else if (!strncmp(argv[1], "del", 4)) {
386 if (!strncmp(argv[4], "fid", 4))
387 table_del_fid(argc, argv);
388 else if (!strncmp(argv[4], "vid", 4))
389 table_del_vid(argc, argv);
390 else
391 usage(argv[0]);
392 } else if (!strncmp(argv[1], "search", 7)) {
393 if (!strncmp(argv[4], "fid", 4))
394 table_search_mac_fid(argc, argv);
395 else if (!strncmp(argv[4], "vid", 4))
396 table_search_mac_vid(argc, argv);
397 else
398 usage(argv[0]);
399 } else if (!strncmp(argv[1], "phy", 4)) {
400 if (argc == 3) {
401 int phy_addr = strtoul(argv[2], NULL, 0);
402 if (phy_addr < 0 || phy_addr > 31)
403 usage(argv[0]);
404 phy_dump(phy_addr);
405 } else if (argc == 5) {
406 if (!strncmp(argv[2], "fc", 2))
407 phy_set_fc(argc, argv);
408 else if (!strncmp(argv[2], "an", 2))
409 phy_set_an(argc, argv);
410 else
411 phy_dump(32);
412 } else
413 phy_operate(argc, argv);
414 } else if (!strncmp(argv[1], "trreg", 4)) {
415 if (rw_phy_token_ring(argc, argv) < 0)
416 usage(argv[0]);
417 } else if (!strncmp(argv[1], "macctl", 7)) {
418 if (argc < 3)
419 usage(argv[0]);
420 if (!strncmp(argv[2], "fc", 3))
421 global_set_mac_fc(argc, argv);
422 else if (!strncmp(argv[2], "pfc", 4))
423 set_mac_pfc(argc, argv);
424 else
425 usage(argv[0]);
426 } else if (!strncmp(argv[1], "qos", 4)) {
427 if (argc < 3)
428 usage(argv[0]);
429 if (!strncmp(argv[2], "sch", 4))
430 qos_sch_select(argc, argv);
431 else if (!strncmp(argv[2], "base", 5))
432 qos_set_base(argc, argv);
433 else if (!strncmp(argv[2], "port-weight", 12))
434 qos_wfq_set_weight(argc, argv);
435 else if (!strncmp(argv[2], "port-prio", 10))
436 qos_set_portpri(argc, argv);
437 else if (!strncmp(argv[2], "dscp-prio", 10))
438 qos_set_dscppri(argc, argv);
439 else if (!strncmp(argv[2], "prio-qmap", 10))
440 qos_pri_mapping_queue(argc, argv);
441 else
442 usage(argv[0]);
443 } else if (!strncmp(argv[1], "stp", 3)) {
444 if (argc < 3)
445 usage(argv[0]);
446 else
447 doStp(argc, argv);
448 } else if (!strncmp(argv[1], "sip", 5)) {
449 if (argc < 3)
450 usage(argv[0]);
451 if (!strncmp(argv[2], "dump", 5))
452 sip_dump();
453 else if (!strncmp(argv[2], "add", 4))
454 sip_add(argc, argv);
455 else if (!strncmp(argv[2], "del", 4))
456 sip_del(argc, argv);
457 else if (!strncmp(argv[2], "clear", 6))
458 sip_clear();
459 else
460 usage(argv[0]);
461 } else if (!strncmp(argv[1], "dip", 4)) {
462 if (argc < 3)
463 usage(argv[0]);
464 if (!strncmp(argv[2], "dump", 5))
465 dip_dump();
466 else if (!strncmp(argv[2], "add", 4))
467 dip_add(argc, argv);
468 else if (!strncmp(argv[2], "del", 4))
469 dip_del(argc, argv);
470 else if (!strncmp(argv[2], "clear", 6))
471 dip_clear();
472 else
473 usage(argv[0]);
474 } else if (!strncmp(argv[1], "mirror", 7)) {
475 if (argc < 3)
476 usage(argv[0]);
477 if (!strncmp(argv[2], "monitor", 8))
478 set_mirror_to(argc, argv);
479 else if (!strncmp(argv[2], "target", 7))
480 set_mirror_from(argc, argv);
481 else if (!strncmp(argv[2], "enable", 7))
482 doMirrorEn(argc, argv);
483 else if (!strncmp(argv[2], "port-based", 11))
484 doMirrorPortBased(argc, argv);
485 else
486 usage(argv[0]);
487 } else if (!strncmp(argv[1], "acl", 4)) {
488 if (argc < 3)
489 usage(argv[0]);
490 if (!strncmp(argv[2], "dip", 4)) {
491 if (!strncmp(argv[3], "add", 4))
492 acl_dip_add(argc, argv);
493 else if (!strncmp(argv[3], "modup", 6))
494 acl_dip_modify(argc, argv);
495 else if (!strncmp(argv[3], "pppoe", 6))
496 acl_dip_pppoe(argc, argv);
497 else if (!strncmp(argv[3], "trtcm", 4))
498 acl_dip_trtcm(argc, argv);
499 else if (!strncmp(argv[3], "meter", 6))
500 acl_dip_meter(argc, argv);
501 else
502 usage(argv[0]);
503 } else if (!strncmp(argv[2], "dmac", 6)) {
504 if (!strncmp(argv[3], "add", 4))
505 acl_mac_add(argc, argv);
506 else
507 usage(argv[0]);
508 } else if (!strncmp(argv[2], "etype", 6)) {
509 if (!strncmp(argv[3], "add", 4))
510 acl_ethertype(argc, argv);
511 else
512 usage(argv[0]);
513 } else if (!strncmp(argv[2], "port", 5)) {
514 if (!strncmp(argv[3], "add", 4))
515 acl_sp_add(argc, argv);
516 else
517 usage(argv[0]);
518 } else if (!strncmp(argv[2], "L4", 5)) {
519 if (!strncmp(argv[3], "add", 4))
520 acl_l4_add(argc, argv);
521 else
522 usage(argv[0]);
523 } else if (!strncmp(argv[2], "enable", 7))
524 acl_port_enable(argc, argv);
525 else if (!strncmp(argv[2], "acltbl-add", 11))
526 acl_table_add(argc, argv);
527 else if (!strncmp(argv[2], "masktbl-add", 12))
528 acl_mask_table_add(argc, argv);
529 else if (!strncmp(argv[2], "ruletbl-add", 12))
530 acl_rule_table_add(argc, argv);
531 else if (!strncmp(argv[2], "ratetbl-add", 12))
532 acl_rate_table_add(argc, argv);
533 else
534 usage(argv[0]);
535 } else if (!strncmp(argv[1], "vlan", 5)) {
536 if (argc < 3)
537 usage(argv[0]);
538 if (!strncmp(argv[2], "dump", 5))
539 vlan_dump();
540 else if (!strncmp(argv[2], "set", 4))
541 vlan_set(argc, argv);
542 else if (!strncmp(argv[2], "clear", 6))
543 vlan_clear(argc, argv);
544 else if (!strncmp(argv[2], "vid", 4))
545 doVlanSetVid(argc, argv);
546 else if (!strncmp(argv[2], "pvid", 5))
547 doVlanSetPvid(argc, argv);
548 else if (!strncmp(argv[2], "acc-frm", 8))
549 doVlanSetAccFrm(argc, argv);
550 else if (!strncmp(argv[2], "port-attr", 10))
551 doVlanSetPortAttr(argc, argv);
552 else if (!strncmp(argv[2], "port-mode", 10))
553 doVlanSetPortMode(argc, argv);
554 else if (!strncmp(argv[2], "eg-tag-pcr", 11))
555 doVlanSetEgressTagPCR(argc, argv);
556 else if (!strncmp(argv[2], "eg-tag-pvc", 11))
557 doVlanSetEgressTagPVC(argc, argv);
558 else
559 usage(argv[0]);
560 } else if (!strncmp(argv[1], "reg", 4)) {
561 parse_reg_cmd(argc, argv, 4);
562 } else if (!strncmp(argv[1], "ingress-rate", 6)) {
563 int port = 0, bw = 0;
564 if (argv[2][1] == 'n') {
565 port = strtoul(argv[3], NULL, 0);
566 bw = strtoul(argv[4], NULL, 0);
567 if (ingress_rate_set(1, port, bw) == 0)
568 printf("switch port=%d, bw=%d\n", port, bw);
569 }
570 else if (argv[2][1] == 'f') {
571 if (argc != 4)
572 usage(argv[0]);
573 port = strtoul(argv[3], NULL, 0);
574 if (ingress_rate_set(0, port, bw) == 0)
575 printf("switch port=%d ingress rate limit off\n", port);
576 } else
577 usage(argv[0]);
578 } else if (!strncmp(argv[1], "egress-rate", 6)) {
579 int port = 0, bw = 0;
580 if (argv[2][1] == 'n') {
581 port = strtoul(argv[3], NULL, 0);
582 bw = strtoul(argv[4], NULL, 0);
583 if (egress_rate_set(1, port, bw) == 0)
584 printf("switch port=%d, bw=%d\n", port, bw);
585 } else if (argv[2][1] == 'f') {
586 if (argc != 4)
587 usage(argv[0]);
588 port = strtoul(argv[3], NULL, 0);
589 if (egress_rate_set(0, port, bw) == 0)
590 printf("switch port=%d egress rate limit off\n", port);
591 } else
592 usage(argv[0]);
593 } else if (!strncmp(argv[1], "igmpsnoop", 10)) {
594 if (argc < 3)
595 usage(argv[0]);
596 if (!strncmp(argv[2], "on", 3))
597 igmp_on(argc, argv);
598 else if (!strncmp(argv[2], "off", 4))
599 igmp_off();
600 else if (!strncmp(argv[2], "enable", 7))
601 igmp_enable(argc, argv);
602 else if (!strncmp(argv[2], "disable", 8))
603 igmp_disable(argc, argv);
604 else
605 usage(argv[0]);
606 } else if (!strncmp(argv[1], "collision-pool", 15)) {
607 if (argc < 3)
608 usage(argv[0]);
609 if (!strncmp(argv[2], "enable", 7))
610 collision_pool_enable(argc, argv);
611 else if (!strncmp(argv[2], "mac", 4)){
612 if (!strncmp(argv[3], "dump", 5))
613 collision_pool_mac_dump();
614 else
615 usage(argv[0]);
616 } else if (!strncmp(argv[2], "dip", 4)){
617 if (!strncmp(argv[3], "dump", 5))
618 collision_pool_dip_dump();
619 else
620 usage(argv[0]);
621 } else if (!strncmp(argv[2], "sip", 4)){
622 if (!strncmp(argv[3], "dump", 5))
623 collision_pool_sip_dump();
624 else
625 usage(argv[0]);
626 }
627 else
628 usage(argv[0]);
629 } else if (!strncmp(argv[1], "pfc", 15)) {
630 if (argc < 4 || argc > 5)
631 usage(argv[0]);
632 if (!strncmp(argv[2], "enable", 7))
633 set_mac_pfc(argc, argv);
634 else if (!strncmp(argv[2], "rx_counter", 11)){
635 pfc_get_rx_counter(argc, argv);
636 } else if (!strncmp(argv[2], "tx_counter", 11)){
637 pfc_get_tx_counter(argc, argv);
638 } else
639 usage(argv[0]);
640 } else if (!strncmp(argv[1], "crossover", 10)) {
641 if (argc < 4)
642 usage(argv[0]);
643 else
644 phy_crossover(argc, argv);
645 } else
646 usage(argv[0]);
647
648 exit_free();
649 return 0;
650}