blob: 4775516b4def7d37b4c168eefff35c4c6b385f87 [file] [log] [blame]
developerfd40db22021-04-29 10:08:25 +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 (egtag) - dump switch vlan table (with per port eg_tag setting)\n", cmd);
117 printf(" 8.2) %s vlan set [fid:0~7] [vid] [portmap] - set vlan id and associated member at switch vlan table\n", cmd);
118 printf(" ([stag:0~4095] [eg_con:0|1] [egtagPortMap 0:untagged 2:tagged]) \n");
119 printf(" Full Example: %s vlan set 0 3 10000100 0 0 20000200\n", cmd);
120 printf(" 8.3) %s vlan vid [vlan idx] [active:0|1] [vid] [portMap] - set switch vlan vid elements \n", cmd);
121 printf(" [egtagPortMap] [ivl_en] [fid] [stag] \n");
122 printf(" 8.4) %s vlan pvid [port] [pvid] - set switch vlan pvid \n", cmd);
123 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);
124 printf(" admit only vlan-taged frames: 1,admit only untagged or priority-tagged frames: 2, reserved:3 \n");
125 printf(" 8.6) %s vlan port-attr [port] [attr:0~3] - set switch vlan port attribute: user port: 0, statck port: 1, \n", cmd);
126 printf(" translation port: 2, transparent port:3 \n");
127 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);
128 printf(" check mode: 2, security mode:3 \n");
129 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);
130 printf(" reserved:3,untagged:4,swap:5,tagged:6, stack:7 \n");
131 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);
132 printf(" \n");
133
134 /* 9. rate limit operations */
135 printf("9) mt753x switch rate limit operations=================================================================================================================>>>>\n");
136 printf(" 9.1) %s ratectl [in_ex_gress:0|1] [port] [rate] - set switch port ingress(1) or egress(0) rate \n", cmd);
137 printf(" 9.2) %s ingress-rate on [port] [Kbps] - set ingress rate limit on port n (n= 0~ switch max port) \n", cmd);
138 printf(" 9.3) %s egress-rate on [port] [Kbps] - set egress rate limit on port n (n= 0~ switch max port) \n", cmd);
139 printf(" 9.4) %s ingress-rate off [port] - disable ingress rate limit on port n (n= 0~ switch max port) \n", cmd);
140 printf(" 9.5) %s egress-rate off [port] - disable egress rate limit on port n (n= 0~ switch max port)\n", cmd);
141 printf(" \n");
142
143 /* 10. igmp operations */
144 printf("10) mt753x igmp operations===============================================================================================================================>>>>\n");
145 printf(" 10.1) %s igmpsnoop on [leaky_en] [wan_num] - turn on IGMP snoop and router port learning\n", cmd);
146 printf(" leaky_en: 1 or 0. default 0; wan_num: 0 or 4. default 4\n");
147 printf(" 10.2) %s igmpsnoop off - turn off IGMP snoop and router port learning\n", cmd);
148 printf(" 10.3) %s igmpsnoop enable [port#] - enable IGMP HW leave/join/Squery/Gquery\n", cmd);
149 printf(" 10.4) %s igmpsnoop disable [port#] - disable IGMP HW leave/join/Squery/Gquery\n", cmd);
150 printf(" \n");
151
152 /* 11. QoS operations */
153 printf("11) mt753x QoS operations================================================================================================================================>>>>\n");
154 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);
155 printf(" 11.2) %s qos base [port:0~6] [base] - set switch qos base(UPW); port-based:0, tag-based:1, \n", cmd);
156 printf(" dscp-based:2, acl-based:3, arl-based:4, stag-based:5 \n");
157 printf(" 11.3) %s qos port-weight [port:0~6] [q0] [q1][q2][q3] - set switch qos port queue weight; \n", cmd);
158 printf(" [q4][q5][q6][q7] [qn]: the weight of queue n, range: 1~16 \n");
159 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);
160 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);
161 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);
162 printf(" \n");
163
164 /*12. port mirror operations*/
165 printf(" 12) mt753x port mirror operations========================================================================================================================>>>>\n");
166 printf(" 12.1) %s mirror monitor [port] - enable port mirror and indicate monitor port number\n", cmd);
167 printf(" 12.2) %s mirror target [port] - set port mirror target\n", cmd);
168 printf(" [direction| 0:off, 1:rx, 2:tx, 3:all] \n");
169 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);
170 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);
171 printf(" [port_rx_mir:0|1] [acl_mir:0|1] \n");
172 printf(" [vlan_mis:0|1] [igmp_mir:0|1] \n");
173 printf(" \n");
174
175 /*13. stp function*/
176 printf(" 13) mt753x stp operations===============================================================================================================================>>>>\n");
177 printf(" 13.1) %s stp [port] [fid] [state] - set switch spanning tree state, port is 0~6, fid is 0~7, \n", cmd);
178 printf(" state is 0~3(Disable/Discarding:0,Blocking/Listening/Discarding:1,) \n");
179 printf(" Learning:2,Forwarding:3 \n");
180 printf(" \n");
181
182 /*14. collision pool operations*/
183 printf("14) mt753x collision pool operations========================================================================================================================>>>>\n");
184 printf(" 14.1) %s collision-pool enable [enable 0|1] - enable or disable collision pool\n", cmd);
185 printf(" 14.2) %s collision-pool mac dump - dump collision pool mac table\n", cmd);
186 printf(" 14.3) %s collision-pool dip dump - dump collision pool dip table\n", cmd);
187 printf(" 14.4) %s collision-pool sip dump - dump collision pool sip table\n", cmd);
188 printf(" \n");
189
190 /*15. pfc(priority flow control) operations*/
191 printf("15) mt753x pfc(priority flow control) operations==============================================================================================================>>>>\n");
192 printf(" 15.1) %s pfc enable [port] [enable 0|1] - enable or disable port's pfc \n", cmd);
193 printf(" 15.2) %s pfc rx_counter [port] - get port n pfc 8 up rx counter \n", cmd);
194 printf(" 15.3) %s pfc tx_counter [port] - get port n pfc 8 up rx counter \n", cmd);
195 printf(" \n");
196
197 /*15. pfc(priority flow control) operations*/
198 printf("16) mt753x EEE(802.3az) operations==============================================================================================================>>>>\n");
199 printf(" 16.1) %s eee enable [enable 0|1] ([portMap]) - enable or disable EEE (by portMap)\n", cmd);
200 printf(" 16.2) %s eee dump ([port]) - dump EEE capability (by port)\n", cmd);
201 printf(" \n");
202
203 exit_free();
204 exit(0);
205}
206
207static void parse_reg_cmd(int argc, char *argv[], int len)
208{
209 unsigned int val;
210 unsigned int off;
211 int i, j;
212
213 if (!strncmp(argv[len - 3], "reg", 4)) {
214 if (argv[len - 2][0] == 'r') {
215 off = strtoul(argv[len - 1], NULL, 16);
216 reg_read(off, &val);
217 printf(" Read reg=%x, value=%x\n", off, val);
218 } else if (argv[len - 2][0] == 'w') {
219 off = strtoul(argv[len - 1], NULL, 16);
220 if (argc != len + 1)
221 usage(argv[0]);
222 val = strtoul(argv[len], NULL, 16);
223 reg_write(off, val);
224 printf(" Write reg=%x, value=%x\n", off, val);
225 } else if (argv[len - 2][0] == 'd') {
226 off = strtoul(argv[len - 1], NULL, 16);
227 for (i = 0; i < 16; i++) {
228 printf("0x%08x: ", off + 0x10 * i);
229 for (j = 0; j < 4; j++) {
230 reg_read(off + i * 0x10 + j * 0x4, &val);
231 printf(" 0x%08x", val);
232 }
233 printf("\n");
234 }
235 } else
236 usage(argv[0]);
237 } else
238 usage(argv[0]);
239}
240
241static int get_chip_name()
242{
243 unsigned int temp;
244 /*judge 7530*/
245 reg_read((0x7ffc), &temp);
246 temp = temp >> 16;
247 if (temp == 0x7530)
248 return temp;
249 /*judge 7531*/
250 reg_read(0x781c, &temp);
251 temp = temp >> 16;
252 if (temp == 0x7531)
253 return temp;
254 return -1;
255}
256
257static int phy_operate(int argc, char *argv[])
258{
259 unsigned int port_num;
260 unsigned int dev_num;
261 unsigned int value;
262 unsigned int reg;
263 int ret = 0;
264 char op;
265
266 if (strncmp(argv[2], "cl22", 4) && strncmp(argv[2], "cl45", 4))
267 usage(argv[0]);
268
269 op = argv[3][0];
270
271 switch(op) {
272 case 'r':
273 reg = strtoul(argv[argc-1], NULL, 0);
274 if (argc == 6) {
275 port_num = strtoul(argv[argc-2], NULL, 0);
276 ret = mii_mgr_read(port_num, reg, &value);
277 if (ret < 0)
278 printf(" Phy read reg fail\n");
279 else
280 printf(" Phy read reg=0x%x, value=0x%x\n", reg, value);
281 } else if (argc == 7) {
282 dev_num = strtoul(argv[argc-2], NULL, 0);
283 port_num = strtoul(argv[argc-3], NULL, 0);
284 ret = mii_mgr_c45_read(port_num, dev_num, reg, &value);
285 if (ret < 0)
286 printf(" Phy read reg fail\n");
287 else
288 printf(" Phy read reg=0x%x, value=0x%x\n", reg, value);
289 } else
290 ret = phy_dump(32);
291 break;
292 case 'w':
293 reg = strtoul(argv[argc-2], NULL, 0);
294 value = strtoul(argv[argc-1], NULL, 0);
295 if (argc == 7) {
296 port_num = strtoul(argv[argc-3], NULL, 0);
297 ret = mii_mgr_write(port_num, reg, value);
298 }
299 else if (argc == 8) {
300 dev_num = strtoul(argv[argc-3], NULL, 0);
301 port_num = strtoul(argv[argc-4], NULL, 0);
302 ret = mii_mgr_c45_write(port_num, dev_num, reg, value);
303 }
304 else
305 usage(argv[0]);
306 break;
307 default:
308 break;
309 }
310
311 return ret;
312}
313
314
315int main(int argc, char *argv[])
316{
317 int err;
318
319 attres = (struct mt753x_attr *)malloc(sizeof(struct mt753x_attr));
320 attres->dev_id = -1;
321 attres->port_num = -1;
322 attres->phy_dev = -1;
developer0c1ae572021-05-27 15:32:01 +0800323 nl_init_flag = false;
developerfd40db22021-04-29 10:08:25 +0800324
developer0c1ae572021-05-27 15:32:01 +0800325 err = switch_ioctl_init();
developerfd40db22021-04-29 10:08:25 +0800326 if (!err)
327 chip_name = get_chip_name();
328
329 /* dsa netlink family might not be enabled. Try gsw netlink family. */
330 if (err < 0 || chip_name < 0) {
developer0c1ae572021-05-27 15:32:01 +0800331 nl_init_flag = true;
332
333 err = mt753x_netlink_init(MT753X_DSA_GENL_NAME);
developerfd40db22021-04-29 10:08:25 +0800334 if (!err)
335 chip_name = get_chip_name();
336 }
337
338 if (err < 0 || chip_name < 0) {
developer0c1ae572021-05-27 15:32:01 +0800339 err = mt753x_netlink_init(MT753X_GENL_NAME);
340 if (!err)
341 chip_name = get_chip_name();
developerfd40db22021-04-29 10:08:25 +0800342
developerfd40db22021-04-29 10:08:25 +0800343 if (chip_name < 0) {
344 printf("no chip unsupport or chip id is invalid!\n");
345 exit_free();
346 exit(0);
347 }
348 }
349
350 if (argc < 2)
351 usage(argv[0]);
352
353 if (!strcmp(argv[1], "dev")) {
354 attres->dev_id = strtoul(argv[2], NULL, 0);
355 argv += 2;
356 argc -= 2;
357 if (argc < 2)
358 usage(argv[0]);
359
360 }
361
362 if (argc == 2) {
363 if (!strcmp(argv[1], "devs")) {
364 attres->type = MT753X_ATTR_TYPE_MESG;
365 mt753x_list_swdev(attres, MT753X_CMD_REQUEST);
366 } else if (!strncmp(argv[1], "dump", 5)) {
367 table_dump();
368 } else if (!strncmp(argv[1], "clear", 6)) {
369 table_clear();
370 printf("done.\n");
371 } else if (!strncmp(argv[1], "reset", 5)) {
372 switch_reset(argc, argv);
373 } else if (!strncmp(argv[1], "phy", 4)) {
374 phy_dump(32); //dump all phy register
375 } else if (!strncmp(argv[1], "sysctl", 7)) {
376 if (nl_init_flag)
377 printf("netlink(%s)\n",MT753X_GENL_NAME);
378 else
379 printf("ioctl(%s)\n",ETH_DEVNAME);
380 } else
381 usage(argv[0]);
382 } else if (!strncmp(argv[1], "arl", 4)) {
383 if (!strncmp(argv[2], "aging", 6))
384 doArlAging(argc, argv);
385 } else if (!strncmp(argv[1], "esw_cnt", 8)) {
386 if (!strncmp(argv[2], "get", 4))
387 read_mib_counters();
388 else if (!strncmp(argv[2], "clear", 6))
389 clear_mib_counters();
390 else
391 usage(argv[0]);
392 }else if (!strncmp(argv[1], "output_queue_cnt", 17)) {
393 if (!strncmp(argv[2], "get", 4))
394 read_output_queue_counters();
395 else
396 usage(argv[0]);
397 }else if (!strncmp(argv[1], "free_page", 10)) {
398 if (!strncmp(argv[2], "get", 4))
399 read_free_page_counters();
400 else
401 usage(argv[0]);
402 }
403 else if (!strncmp(argv[1], "ratectl", 8))
404 rate_control(argc, argv);
405 else if (!strncmp(argv[1], "add", 4))
406 table_add(argc, argv);
407 else if (!strncmp(argv[1], "filt", 5))
408 table_add(argc, argv);
409 else if (!strncmp(argv[1], "del", 4)) {
410 if (!strncmp(argv[4], "fid", 4))
411 table_del_fid(argc, argv);
412 else if (!strncmp(argv[4], "vid", 4))
413 table_del_vid(argc, argv);
414 else
415 usage(argv[0]);
416 } else if (!strncmp(argv[1], "search", 7)) {
417 if (!strncmp(argv[4], "fid", 4))
418 table_search_mac_fid(argc, argv);
419 else if (!strncmp(argv[4], "vid", 4))
420 table_search_mac_vid(argc, argv);
421 else
422 usage(argv[0]);
423 } else if (!strncmp(argv[1], "phy", 4)) {
424 if (argc == 3) {
425 int phy_addr = strtoul(argv[2], NULL, 0);
426 if (phy_addr < 0 || phy_addr > 31)
427 usage(argv[0]);
428 phy_dump(phy_addr);
429 } else if (argc == 5) {
430 if (!strncmp(argv[2], "fc", 2))
431 phy_set_fc(argc, argv);
432 else if (!strncmp(argv[2], "an", 2))
433 phy_set_an(argc, argv);
434 else
435 phy_dump(32);
436 } else
437 phy_operate(argc, argv);
438 } else if (!strncmp(argv[1], "trreg", 4)) {
439 if (rw_phy_token_ring(argc, argv) < 0)
440 usage(argv[0]);
441 } else if (!strncmp(argv[1], "macctl", 7)) {
442 if (argc < 3)
443 usage(argv[0]);
444 if (!strncmp(argv[2], "fc", 3))
445 global_set_mac_fc(argc, argv);
446 else if (!strncmp(argv[2], "pfc", 4))
447 set_mac_pfc(argc, argv);
448 else
449 usage(argv[0]);
450 } else if (!strncmp(argv[1], "qos", 4)) {
451 if (argc < 3)
452 usage(argv[0]);
453 if (!strncmp(argv[2], "sch", 4))
454 qos_sch_select(argc, argv);
455 else if (!strncmp(argv[2], "base", 5))
456 qos_set_base(argc, argv);
457 else if (!strncmp(argv[2], "port-weight", 12))
458 qos_wfq_set_weight(argc, argv);
459 else if (!strncmp(argv[2], "port-prio", 10))
460 qos_set_portpri(argc, argv);
461 else if (!strncmp(argv[2], "dscp-prio", 10))
462 qos_set_dscppri(argc, argv);
463 else if (!strncmp(argv[2], "prio-qmap", 10))
464 qos_pri_mapping_queue(argc, argv);
465 else
466 usage(argv[0]);
467 } else if (!strncmp(argv[1], "stp", 3)) {
468 if (argc < 3)
469 usage(argv[0]);
470 else
471 doStp(argc, argv);
472 } else if (!strncmp(argv[1], "sip", 5)) {
473 if (argc < 3)
474 usage(argv[0]);
475 if (!strncmp(argv[2], "dump", 5))
476 sip_dump();
477 else if (!strncmp(argv[2], "add", 4))
478 sip_add(argc, argv);
479 else if (!strncmp(argv[2], "del", 4))
480 sip_del(argc, argv);
481 else if (!strncmp(argv[2], "clear", 6))
482 sip_clear();
483 else
484 usage(argv[0]);
485 } else if (!strncmp(argv[1], "dip", 4)) {
486 if (argc < 3)
487 usage(argv[0]);
488 if (!strncmp(argv[2], "dump", 5))
489 dip_dump();
490 else if (!strncmp(argv[2], "add", 4))
491 dip_add(argc, argv);
492 else if (!strncmp(argv[2], "del", 4))
493 dip_del(argc, argv);
494 else if (!strncmp(argv[2], "clear", 6))
495 dip_clear();
496 else
497 usage(argv[0]);
498 } else if (!strncmp(argv[1], "mirror", 7)) {
499 if (argc < 3)
500 usage(argv[0]);
501 if (!strncmp(argv[2], "monitor", 8))
502 set_mirror_to(argc, argv);
503 else if (!strncmp(argv[2], "target", 7))
504 set_mirror_from(argc, argv);
505 else if (!strncmp(argv[2], "enable", 7))
506 doMirrorEn(argc, argv);
507 else if (!strncmp(argv[2], "port-based", 11))
508 doMirrorPortBased(argc, argv);
509 else
510 usage(argv[0]);
511 } else if (!strncmp(argv[1], "acl", 4)) {
512 if (argc < 3)
513 usage(argv[0]);
514 if (!strncmp(argv[2], "dip", 4)) {
515 if (!strncmp(argv[3], "add", 4))
516 acl_dip_add(argc, argv);
517 else if (!strncmp(argv[3], "modup", 6))
518 acl_dip_modify(argc, argv);
519 else if (!strncmp(argv[3], "pppoe", 6))
520 acl_dip_pppoe(argc, argv);
521 else if (!strncmp(argv[3], "trtcm", 4))
522 acl_dip_trtcm(argc, argv);
523 else if (!strncmp(argv[3], "meter", 6))
524 acl_dip_meter(argc, argv);
525 else
526 usage(argv[0]);
527 } else if (!strncmp(argv[2], "dmac", 6)) {
528 if (!strncmp(argv[3], "add", 4))
529 acl_mac_add(argc, argv);
530 else
531 usage(argv[0]);
532 } else if (!strncmp(argv[2], "etype", 6)) {
533 if (!strncmp(argv[3], "add", 4))
534 acl_ethertype(argc, argv);
535 else
536 usage(argv[0]);
537 } else if (!strncmp(argv[2], "port", 5)) {
538 if (!strncmp(argv[3], "add", 4))
539 acl_sp_add(argc, argv);
540 else
541 usage(argv[0]);
542 } else if (!strncmp(argv[2], "L4", 5)) {
543 if (!strncmp(argv[3], "add", 4))
544 acl_l4_add(argc, argv);
545 else
546 usage(argv[0]);
547 } else if (!strncmp(argv[2], "enable", 7))
548 acl_port_enable(argc, argv);
549 else if (!strncmp(argv[2], "acltbl-add", 11))
550 acl_table_add(argc, argv);
551 else if (!strncmp(argv[2], "masktbl-add", 12))
552 acl_mask_table_add(argc, argv);
553 else if (!strncmp(argv[2], "ruletbl-add", 12))
554 acl_rule_table_add(argc, argv);
555 else if (!strncmp(argv[2], "ratetbl-add", 12))
556 acl_rate_table_add(argc, argv);
557 else
558 usage(argv[0]);
559 } else if (!strncmp(argv[1], "vlan", 5)) {
560 if (argc < 3)
561 usage(argv[0]);
562 if (!strncmp(argv[2], "dump", 5))
563 vlan_dump(argc, argv);
564 else if (!strncmp(argv[2], "set", 4))
565 vlan_set(argc, argv);
566 else if (!strncmp(argv[2], "clear", 6))
567 vlan_clear(argc, argv);
568 else if (!strncmp(argv[2], "vid", 4))
569 doVlanSetVid(argc, argv);
570 else if (!strncmp(argv[2], "pvid", 5))
571 doVlanSetPvid(argc, argv);
572 else if (!strncmp(argv[2], "acc-frm", 8))
573 doVlanSetAccFrm(argc, argv);
574 else if (!strncmp(argv[2], "port-attr", 10))
575 doVlanSetPortAttr(argc, argv);
576 else if (!strncmp(argv[2], "port-mode", 10))
577 doVlanSetPortMode(argc, argv);
578 else if (!strncmp(argv[2], "eg-tag-pcr", 11))
579 doVlanSetEgressTagPCR(argc, argv);
580 else if (!strncmp(argv[2], "eg-tag-pvc", 11))
581 doVlanSetEgressTagPVC(argc, argv);
582 else
583 usage(argv[0]);
584 } else if (!strncmp(argv[1], "reg", 4)) {
585 parse_reg_cmd(argc, argv, 4);
586 } else if (!strncmp(argv[1], "ingress-rate", 6)) {
587 int port = 0, bw = 0;
588 if (argv[2][1] == 'n') {
589 port = strtoul(argv[3], NULL, 0);
590 bw = strtoul(argv[4], NULL, 0);
591 if (ingress_rate_set(1, port, bw) == 0)
592 printf("switch port=%d, bw=%d\n", port, bw);
593 }
594 else if (argv[2][1] == 'f') {
595 if (argc != 4)
596 usage(argv[0]);
597 port = strtoul(argv[3], NULL, 0);
598 if (ingress_rate_set(0, port, bw) == 0)
599 printf("switch port=%d ingress rate limit off\n", port);
600 } else
601 usage(argv[0]);
602 } else if (!strncmp(argv[1], "egress-rate", 6)) {
603 int port = 0, bw = 0;
604 if (argv[2][1] == 'n') {
605 port = strtoul(argv[3], NULL, 0);
606 bw = strtoul(argv[4], NULL, 0);
607 if (egress_rate_set(1, port, bw) == 0)
608 printf("switch port=%d, bw=%d\n", port, bw);
609 } else if (argv[2][1] == 'f') {
610 if (argc != 4)
611 usage(argv[0]);
612 port = strtoul(argv[3], NULL, 0);
613 if (egress_rate_set(0, port, bw) == 0)
614 printf("switch port=%d egress rate limit off\n", port);
615 } else
616 usage(argv[0]);
617 } else if (!strncmp(argv[1], "igmpsnoop", 10)) {
618 if (argc < 3)
619 usage(argv[0]);
620 if (!strncmp(argv[2], "on", 3))
621 igmp_on(argc, argv);
622 else if (!strncmp(argv[2], "off", 4))
623 igmp_off();
624 else if (!strncmp(argv[2], "enable", 7))
625 igmp_enable(argc, argv);
626 else if (!strncmp(argv[2], "disable", 8))
627 igmp_disable(argc, argv);
628 else
629 usage(argv[0]);
630 } else if (!strncmp(argv[1], "collision-pool", 15)) {
631 if (argc < 3)
632 usage(argv[0]);
633 if (!strncmp(argv[2], "enable", 7))
634 collision_pool_enable(argc, argv);
635 else if (!strncmp(argv[2], "mac", 4)){
636 if (!strncmp(argv[3], "dump", 5))
637 collision_pool_mac_dump();
638 else
639 usage(argv[0]);
640 } else if (!strncmp(argv[2], "dip", 4)){
641 if (!strncmp(argv[3], "dump", 5))
642 collision_pool_dip_dump();
643 else
644 usage(argv[0]);
645 } else if (!strncmp(argv[2], "sip", 4)){
646 if (!strncmp(argv[3], "dump", 5))
647 collision_pool_sip_dump();
648 else
649 usage(argv[0]);
650 }
651 else
652 usage(argv[0]);
653 } else if (!strncmp(argv[1], "pfc", 15)) {
654 if (argc < 4 || argc > 5)
655 usage(argv[0]);
656 if (!strncmp(argv[2], "enable", 7))
657 set_mac_pfc(argc, argv);
658 else if (!strncmp(argv[2], "rx_counter", 11)){
659 pfc_get_rx_counter(argc, argv);
660 } else if (!strncmp(argv[2], "tx_counter", 11)){
661 pfc_get_tx_counter(argc, argv);
662 } else
663 usage(argv[0]);
664 } else if (!strncmp(argv[1], "crossover", 10)) {
665 if (argc < 4)
666 usage(argv[0]);
667 else
668 phy_crossover(argc, argv);
669 } else if (!strncmp(argv[1], "eee", 4)) {
670 if (argc < 3)
671 usage(argv[0]);
672 if (!strncmp(argv[2], "enable", 7) ||
673 !strncmp(argv[2], "disable", 8))
674 eee_enable(argc, argv);
675 else if (!strncmp(argv[2], "dump", 5))
676 eee_dump(argc, argv);
677 else
678 usage(argv[0]);
679 } else
680 usage(argv[0]);
681
682 exit_free();
683 return 0;
684}