blob: 2637ed5324ffda9bbdd036525a8ad6b10d3f02e4 [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{
developerb5ea1302022-08-03 19:54:17 +0800243 int temp;
developer8c3871b2022-07-01 14:07:53 +0800244 FILE *fp = NULL;
245 char buff[255];
246
developerfd40db22021-04-29 10:08:25 +0800247 /*judge 7530*/
248 reg_read((0x7ffc), &temp);
249 temp = temp >> 16;
250 if (temp == 0x7530)
251 return temp;
252 /*judge 7531*/
253 reg_read(0x781c, &temp);
254 temp = temp >> 16;
255 if (temp == 0x7531)
256 return temp;
developer8c3871b2022-07-01 14:07:53 +0800257
258 /*judge jaguar embedded switch*/
developerb5ea1302022-08-03 19:54:17 +0800259 fp = fopen("/proc/device-tree/compatible", "r");
developer8c3871b2022-07-01 14:07:53 +0800260 if (fp != NULL) {
developerb5ea1302022-08-03 19:54:17 +0800261 temp = -1;
262 if (fgets(buff, 255, (FILE *)fp) && strstr(buff, "mt7988"))
developer8c3871b2022-07-01 14:07:53 +0800263 temp = 0x7988;
developerb5ea1302022-08-03 19:54:17 +0800264
265 fclose(fp);
266 return temp;
developer8c3871b2022-07-01 14:07:53 +0800267 }
268
developerfd40db22021-04-29 10:08:25 +0800269 return -1;
270}
271
272static int phy_operate(int argc, char *argv[])
273{
274 unsigned int port_num;
275 unsigned int dev_num;
276 unsigned int value;
277 unsigned int reg;
278 int ret = 0;
279 char op;
280
281 if (strncmp(argv[2], "cl22", 4) && strncmp(argv[2], "cl45", 4))
282 usage(argv[0]);
283
284 op = argv[3][0];
285
286 switch(op) {
287 case 'r':
288 reg = strtoul(argv[argc-1], NULL, 0);
289 if (argc == 6) {
290 port_num = strtoul(argv[argc-2], NULL, 0);
291 ret = mii_mgr_read(port_num, reg, &value);
292 if (ret < 0)
293 printf(" Phy read reg fail\n");
294 else
295 printf(" Phy read reg=0x%x, value=0x%x\n", reg, value);
296 } else if (argc == 7) {
297 dev_num = strtoul(argv[argc-2], NULL, 0);
298 port_num = strtoul(argv[argc-3], NULL, 0);
299 ret = mii_mgr_c45_read(port_num, dev_num, reg, &value);
300 if (ret < 0)
301 printf(" Phy read reg fail\n");
302 else
303 printf(" Phy read reg=0x%x, value=0x%x\n", reg, value);
304 } else
305 ret = phy_dump(32);
306 break;
307 case 'w':
308 reg = strtoul(argv[argc-2], NULL, 0);
309 value = strtoul(argv[argc-1], NULL, 0);
310 if (argc == 7) {
311 port_num = strtoul(argv[argc-3], NULL, 0);
312 ret = mii_mgr_write(port_num, reg, value);
313 }
314 else if (argc == 8) {
315 dev_num = strtoul(argv[argc-3], NULL, 0);
316 port_num = strtoul(argv[argc-4], NULL, 0);
317 ret = mii_mgr_c45_write(port_num, dev_num, reg, value);
318 }
319 else
320 usage(argv[0]);
321 break;
322 default:
323 break;
324 }
325
326 return ret;
327}
328
329
330int main(int argc, char *argv[])
331{
332 int err;
333
334 attres = (struct mt753x_attr *)malloc(sizeof(struct mt753x_attr));
335 attres->dev_id = -1;
336 attres->port_num = -1;
337 attres->phy_dev = -1;
developer8c3871b2022-07-01 14:07:53 +0800338 nl_init_flag = true;
developerfd40db22021-04-29 10:08:25 +0800339
developer8c3871b2022-07-01 14:07:53 +0800340 /* dsa netlink family might not be enabled. Try gsw netlink family. */
341 err = mt753x_netlink_init(MT753X_DSA_GENL_NAME);
developerfd40db22021-04-29 10:08:25 +0800342 if (!err)
343 chip_name = get_chip_name();
344
developer8c3871b2022-07-01 14:07:53 +0800345 if (err < 0) {
346 err = mt753x_netlink_init(MT753X_GENL_NAME);
developerfd40db22021-04-29 10:08:25 +0800347 if (!err)
348 chip_name = get_chip_name();
349 }
developer8c3871b2022-07-01 14:07:53 +0800350
351 if (err < 0) {
352 err = switch_ioctl_init();
353 if (!err) {
developer8c3871b2022-07-01 14:07:53 +0800354 nl_init_flag = false;
developer5145ebb2022-07-14 15:16:24 +0800355 chip_name = get_chip_name();
developer8c3871b2022-07-01 14:07:53 +0800356 if (chip_name < 0) {
357 printf("no chip unsupport or chip id is invalid!\n");
358 exit_free();
359 exit(0);
360 }
developerfd40db22021-04-29 10:08:25 +0800361 }
362 }
363
364 if (argc < 2)
365 usage(argv[0]);
366
367 if (!strcmp(argv[1], "dev")) {
368 attres->dev_id = strtoul(argv[2], NULL, 0);
369 argv += 2;
370 argc -= 2;
371 if (argc < 2)
372 usage(argv[0]);
373
374 }
375
376 if (argc == 2) {
377 if (!strcmp(argv[1], "devs")) {
378 attres->type = MT753X_ATTR_TYPE_MESG;
379 mt753x_list_swdev(attres, MT753X_CMD_REQUEST);
380 } else if (!strncmp(argv[1], "dump", 5)) {
381 table_dump();
382 } else if (!strncmp(argv[1], "clear", 6)) {
383 table_clear();
384 printf("done.\n");
385 } else if (!strncmp(argv[1], "reset", 5)) {
386 switch_reset(argc, argv);
387 } else if (!strncmp(argv[1], "phy", 4)) {
388 phy_dump(32); //dump all phy register
389 } else if (!strncmp(argv[1], "sysctl", 7)) {
390 if (nl_init_flag)
391 printf("netlink(%s)\n",MT753X_GENL_NAME);
392 else
393 printf("ioctl(%s)\n",ETH_DEVNAME);
394 } else
395 usage(argv[0]);
396 } else if (!strncmp(argv[1], "arl", 4)) {
397 if (!strncmp(argv[2], "aging", 6))
398 doArlAging(argc, argv);
399 } else if (!strncmp(argv[1], "esw_cnt", 8)) {
400 if (!strncmp(argv[2], "get", 4))
401 read_mib_counters();
402 else if (!strncmp(argv[2], "clear", 6))
403 clear_mib_counters();
404 else
405 usage(argv[0]);
406 }else if (!strncmp(argv[1], "output_queue_cnt", 17)) {
407 if (!strncmp(argv[2], "get", 4))
408 read_output_queue_counters();
409 else
410 usage(argv[0]);
411 }else if (!strncmp(argv[1], "free_page", 10)) {
412 if (!strncmp(argv[2], "get", 4))
413 read_free_page_counters();
414 else
415 usage(argv[0]);
416 }
417 else if (!strncmp(argv[1], "ratectl", 8))
418 rate_control(argc, argv);
419 else if (!strncmp(argv[1], "add", 4))
420 table_add(argc, argv);
421 else if (!strncmp(argv[1], "filt", 5))
422 table_add(argc, argv);
423 else if (!strncmp(argv[1], "del", 4)) {
424 if (!strncmp(argv[4], "fid", 4))
425 table_del_fid(argc, argv);
426 else if (!strncmp(argv[4], "vid", 4))
427 table_del_vid(argc, argv);
428 else
429 usage(argv[0]);
430 } else if (!strncmp(argv[1], "search", 7)) {
431 if (!strncmp(argv[4], "fid", 4))
432 table_search_mac_fid(argc, argv);
433 else if (!strncmp(argv[4], "vid", 4))
434 table_search_mac_vid(argc, argv);
435 else
436 usage(argv[0]);
437 } else if (!strncmp(argv[1], "phy", 4)) {
438 if (argc == 3) {
439 int phy_addr = strtoul(argv[2], NULL, 0);
440 if (phy_addr < 0 || phy_addr > 31)
441 usage(argv[0]);
442 phy_dump(phy_addr);
443 } else if (argc == 5) {
444 if (!strncmp(argv[2], "fc", 2))
445 phy_set_fc(argc, argv);
446 else if (!strncmp(argv[2], "an", 2))
447 phy_set_an(argc, argv);
448 else
449 phy_dump(32);
450 } else
451 phy_operate(argc, argv);
452 } else if (!strncmp(argv[1], "trreg", 4)) {
453 if (rw_phy_token_ring(argc, argv) < 0)
454 usage(argv[0]);
455 } else if (!strncmp(argv[1], "macctl", 7)) {
456 if (argc < 3)
457 usage(argv[0]);
458 if (!strncmp(argv[2], "fc", 3))
459 global_set_mac_fc(argc, argv);
460 else if (!strncmp(argv[2], "pfc", 4))
461 set_mac_pfc(argc, argv);
462 else
463 usage(argv[0]);
464 } else if (!strncmp(argv[1], "qos", 4)) {
465 if (argc < 3)
466 usage(argv[0]);
467 if (!strncmp(argv[2], "sch", 4))
468 qos_sch_select(argc, argv);
469 else if (!strncmp(argv[2], "base", 5))
470 qos_set_base(argc, argv);
471 else if (!strncmp(argv[2], "port-weight", 12))
472 qos_wfq_set_weight(argc, argv);
473 else if (!strncmp(argv[2], "port-prio", 10))
474 qos_set_portpri(argc, argv);
475 else if (!strncmp(argv[2], "dscp-prio", 10))
476 qos_set_dscppri(argc, argv);
477 else if (!strncmp(argv[2], "prio-qmap", 10))
478 qos_pri_mapping_queue(argc, argv);
479 else
480 usage(argv[0]);
481 } else if (!strncmp(argv[1], "stp", 3)) {
482 if (argc < 3)
483 usage(argv[0]);
484 else
485 doStp(argc, argv);
486 } else if (!strncmp(argv[1], "sip", 5)) {
487 if (argc < 3)
488 usage(argv[0]);
489 if (!strncmp(argv[2], "dump", 5))
490 sip_dump();
491 else if (!strncmp(argv[2], "add", 4))
492 sip_add(argc, argv);
493 else if (!strncmp(argv[2], "del", 4))
494 sip_del(argc, argv);
495 else if (!strncmp(argv[2], "clear", 6))
496 sip_clear();
497 else
498 usage(argv[0]);
499 } else if (!strncmp(argv[1], "dip", 4)) {
500 if (argc < 3)
501 usage(argv[0]);
502 if (!strncmp(argv[2], "dump", 5))
503 dip_dump();
504 else if (!strncmp(argv[2], "add", 4))
505 dip_add(argc, argv);
506 else if (!strncmp(argv[2], "del", 4))
507 dip_del(argc, argv);
508 else if (!strncmp(argv[2], "clear", 6))
509 dip_clear();
510 else
511 usage(argv[0]);
512 } else if (!strncmp(argv[1], "mirror", 7)) {
513 if (argc < 3)
514 usage(argv[0]);
515 if (!strncmp(argv[2], "monitor", 8))
516 set_mirror_to(argc, argv);
517 else if (!strncmp(argv[2], "target", 7))
518 set_mirror_from(argc, argv);
519 else if (!strncmp(argv[2], "enable", 7))
520 doMirrorEn(argc, argv);
521 else if (!strncmp(argv[2], "port-based", 11))
522 doMirrorPortBased(argc, argv);
523 else
524 usage(argv[0]);
525 } else if (!strncmp(argv[1], "acl", 4)) {
526 if (argc < 3)
527 usage(argv[0]);
528 if (!strncmp(argv[2], "dip", 4)) {
529 if (!strncmp(argv[3], "add", 4))
530 acl_dip_add(argc, argv);
531 else if (!strncmp(argv[3], "modup", 6))
532 acl_dip_modify(argc, argv);
533 else if (!strncmp(argv[3], "pppoe", 6))
534 acl_dip_pppoe(argc, argv);
535 else if (!strncmp(argv[3], "trtcm", 4))
536 acl_dip_trtcm(argc, argv);
537 else if (!strncmp(argv[3], "meter", 6))
538 acl_dip_meter(argc, argv);
539 else
540 usage(argv[0]);
541 } else if (!strncmp(argv[2], "dmac", 6)) {
542 if (!strncmp(argv[3], "add", 4))
543 acl_mac_add(argc, argv);
544 else
545 usage(argv[0]);
546 } else if (!strncmp(argv[2], "etype", 6)) {
547 if (!strncmp(argv[3], "add", 4))
548 acl_ethertype(argc, argv);
549 else
550 usage(argv[0]);
551 } else if (!strncmp(argv[2], "port", 5)) {
552 if (!strncmp(argv[3], "add", 4))
553 acl_sp_add(argc, argv);
554 else
555 usage(argv[0]);
556 } else if (!strncmp(argv[2], "L4", 5)) {
557 if (!strncmp(argv[3], "add", 4))
558 acl_l4_add(argc, argv);
559 else
560 usage(argv[0]);
561 } else if (!strncmp(argv[2], "enable", 7))
562 acl_port_enable(argc, argv);
563 else if (!strncmp(argv[2], "acltbl-add", 11))
564 acl_table_add(argc, argv);
565 else if (!strncmp(argv[2], "masktbl-add", 12))
566 acl_mask_table_add(argc, argv);
567 else if (!strncmp(argv[2], "ruletbl-add", 12))
568 acl_rule_table_add(argc, argv);
569 else if (!strncmp(argv[2], "ratetbl-add", 12))
570 acl_rate_table_add(argc, argv);
571 else
572 usage(argv[0]);
573 } else if (!strncmp(argv[1], "vlan", 5)) {
574 if (argc < 3)
575 usage(argv[0]);
576 if (!strncmp(argv[2], "dump", 5))
577 vlan_dump(argc, argv);
578 else if (!strncmp(argv[2], "set", 4))
579 vlan_set(argc, argv);
580 else if (!strncmp(argv[2], "clear", 6))
581 vlan_clear(argc, argv);
582 else if (!strncmp(argv[2], "vid", 4))
583 doVlanSetVid(argc, argv);
584 else if (!strncmp(argv[2], "pvid", 5))
585 doVlanSetPvid(argc, argv);
586 else if (!strncmp(argv[2], "acc-frm", 8))
587 doVlanSetAccFrm(argc, argv);
588 else if (!strncmp(argv[2], "port-attr", 10))
589 doVlanSetPortAttr(argc, argv);
590 else if (!strncmp(argv[2], "port-mode", 10))
591 doVlanSetPortMode(argc, argv);
592 else if (!strncmp(argv[2], "eg-tag-pcr", 11))
593 doVlanSetEgressTagPCR(argc, argv);
594 else if (!strncmp(argv[2], "eg-tag-pvc", 11))
595 doVlanSetEgressTagPVC(argc, argv);
596 else
597 usage(argv[0]);
598 } else if (!strncmp(argv[1], "reg", 4)) {
599 parse_reg_cmd(argc, argv, 4);
600 } else if (!strncmp(argv[1], "ingress-rate", 6)) {
601 int port = 0, bw = 0;
602 if (argv[2][1] == 'n') {
603 port = strtoul(argv[3], NULL, 0);
604 bw = strtoul(argv[4], NULL, 0);
605 if (ingress_rate_set(1, port, bw) == 0)
606 printf("switch port=%d, bw=%d\n", port, bw);
607 }
608 else if (argv[2][1] == 'f') {
609 if (argc != 4)
610 usage(argv[0]);
611 port = strtoul(argv[3], NULL, 0);
612 if (ingress_rate_set(0, port, bw) == 0)
613 printf("switch port=%d ingress rate limit off\n", port);
614 } else
615 usage(argv[0]);
616 } else if (!strncmp(argv[1], "egress-rate", 6)) {
617 int port = 0, bw = 0;
618 if (argv[2][1] == 'n') {
619 port = strtoul(argv[3], NULL, 0);
620 bw = strtoul(argv[4], NULL, 0);
621 if (egress_rate_set(1, port, bw) == 0)
622 printf("switch port=%d, bw=%d\n", port, bw);
623 } else if (argv[2][1] == 'f') {
624 if (argc != 4)
625 usage(argv[0]);
626 port = strtoul(argv[3], NULL, 0);
627 if (egress_rate_set(0, port, bw) == 0)
628 printf("switch port=%d egress rate limit off\n", port);
629 } else
630 usage(argv[0]);
631 } else if (!strncmp(argv[1], "igmpsnoop", 10)) {
632 if (argc < 3)
633 usage(argv[0]);
634 if (!strncmp(argv[2], "on", 3))
635 igmp_on(argc, argv);
636 else if (!strncmp(argv[2], "off", 4))
637 igmp_off();
638 else if (!strncmp(argv[2], "enable", 7))
639 igmp_enable(argc, argv);
640 else if (!strncmp(argv[2], "disable", 8))
641 igmp_disable(argc, argv);
642 else
643 usage(argv[0]);
644 } else if (!strncmp(argv[1], "collision-pool", 15)) {
645 if (argc < 3)
646 usage(argv[0]);
647 if (!strncmp(argv[2], "enable", 7))
648 collision_pool_enable(argc, argv);
649 else if (!strncmp(argv[2], "mac", 4)){
650 if (!strncmp(argv[3], "dump", 5))
651 collision_pool_mac_dump();
652 else
653 usage(argv[0]);
654 } else if (!strncmp(argv[2], "dip", 4)){
655 if (!strncmp(argv[3], "dump", 5))
656 collision_pool_dip_dump();
657 else
658 usage(argv[0]);
659 } else if (!strncmp(argv[2], "sip", 4)){
660 if (!strncmp(argv[3], "dump", 5))
661 collision_pool_sip_dump();
662 else
663 usage(argv[0]);
664 }
665 else
666 usage(argv[0]);
667 } else if (!strncmp(argv[1], "pfc", 15)) {
668 if (argc < 4 || argc > 5)
669 usage(argv[0]);
670 if (!strncmp(argv[2], "enable", 7))
671 set_mac_pfc(argc, argv);
672 else if (!strncmp(argv[2], "rx_counter", 11)){
673 pfc_get_rx_counter(argc, argv);
674 } else if (!strncmp(argv[2], "tx_counter", 11)){
675 pfc_get_tx_counter(argc, argv);
676 } else
677 usage(argv[0]);
678 } else if (!strncmp(argv[1], "crossover", 10)) {
679 if (argc < 4)
680 usage(argv[0]);
681 else
682 phy_crossover(argc, argv);
683 } else if (!strncmp(argv[1], "eee", 4)) {
684 if (argc < 3)
685 usage(argv[0]);
686 if (!strncmp(argv[2], "enable", 7) ||
687 !strncmp(argv[2], "disable", 8))
688 eee_enable(argc, argv);
689 else if (!strncmp(argv[2], "dump", 5))
690 eee_dump(argc, argv);
691 else
692 usage(argv[0]);
693 } else
694 usage(argv[0]);
695
696 exit_free();
697 return 0;
698}