developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 16 | struct mt753x_attr *attres; |
| 17 | int chip_name; |
| 18 | bool nl_init_flag; |
| 19 | |
| 20 | static 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 | |
| 207 | static 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 | |
| 241 | static 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 | |
| 257 | static 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 | |
| 315 | int 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; |
| 323 | nl_init_flag = true; |
| 324 | |
| 325 | err = mt753x_netlink_init(MT753X_DSA_GENL_NAME); |
| 326 | 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) { |
| 331 | err = mt753x_netlink_init(MT753X_GENL_NAME); |
| 332 | if (!err) |
| 333 | chip_name = get_chip_name(); |
| 334 | } |
| 335 | |
| 336 | if (err < 0 || chip_name < 0) { |
| 337 | nl_init_flag = false; |
| 338 | |
| 339 | switch_ioctl_init(); |
| 340 | chip_name = get_chip_name(); |
| 341 | if (chip_name < 0) { |
| 342 | printf("no chip unsupport or chip id is invalid!\n"); |
| 343 | exit_free(); |
| 344 | exit(0); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | if (argc < 2) |
| 349 | usage(argv[0]); |
| 350 | |
| 351 | if (!strcmp(argv[1], "dev")) { |
| 352 | attres->dev_id = strtoul(argv[2], NULL, 0); |
| 353 | argv += 2; |
| 354 | argc -= 2; |
| 355 | if (argc < 2) |
| 356 | usage(argv[0]); |
| 357 | |
| 358 | } |
| 359 | |
| 360 | if (argc == 2) { |
| 361 | if (!strcmp(argv[1], "devs")) { |
| 362 | attres->type = MT753X_ATTR_TYPE_MESG; |
| 363 | mt753x_list_swdev(attres, MT753X_CMD_REQUEST); |
| 364 | } else if (!strncmp(argv[1], "dump", 5)) { |
| 365 | table_dump(); |
| 366 | } else if (!strncmp(argv[1], "clear", 6)) { |
| 367 | table_clear(); |
| 368 | printf("done.\n"); |
| 369 | } else if (!strncmp(argv[1], "reset", 5)) { |
| 370 | switch_reset(argc, argv); |
| 371 | } else if (!strncmp(argv[1], "phy", 4)) { |
| 372 | phy_dump(32); //dump all phy register |
| 373 | } else if (!strncmp(argv[1], "sysctl", 7)) { |
| 374 | if (nl_init_flag) |
| 375 | printf("netlink(%s)\n",MT753X_GENL_NAME); |
| 376 | else |
| 377 | printf("ioctl(%s)\n",ETH_DEVNAME); |
| 378 | } else |
| 379 | usage(argv[0]); |
| 380 | } else if (!strncmp(argv[1], "arl", 4)) { |
| 381 | if (!strncmp(argv[2], "aging", 6)) |
| 382 | doArlAging(argc, argv); |
| 383 | } else if (!strncmp(argv[1], "esw_cnt", 8)) { |
| 384 | if (!strncmp(argv[2], "get", 4)) |
| 385 | read_mib_counters(); |
| 386 | else if (!strncmp(argv[2], "clear", 6)) |
| 387 | clear_mib_counters(); |
| 388 | else |
| 389 | usage(argv[0]); |
| 390 | }else if (!strncmp(argv[1], "output_queue_cnt", 17)) { |
| 391 | if (!strncmp(argv[2], "get", 4)) |
| 392 | read_output_queue_counters(); |
| 393 | else |
| 394 | usage(argv[0]); |
| 395 | }else if (!strncmp(argv[1], "free_page", 10)) { |
| 396 | if (!strncmp(argv[2], "get", 4)) |
| 397 | read_free_page_counters(); |
| 398 | else |
| 399 | usage(argv[0]); |
| 400 | } |
| 401 | else if (!strncmp(argv[1], "ratectl", 8)) |
| 402 | rate_control(argc, argv); |
| 403 | else if (!strncmp(argv[1], "add", 4)) |
| 404 | table_add(argc, argv); |
| 405 | else if (!strncmp(argv[1], "filt", 5)) |
| 406 | table_add(argc, argv); |
| 407 | else if (!strncmp(argv[1], "del", 4)) { |
| 408 | if (!strncmp(argv[4], "fid", 4)) |
| 409 | table_del_fid(argc, argv); |
| 410 | else if (!strncmp(argv[4], "vid", 4)) |
| 411 | table_del_vid(argc, argv); |
| 412 | else |
| 413 | usage(argv[0]); |
| 414 | } else if (!strncmp(argv[1], "search", 7)) { |
| 415 | if (!strncmp(argv[4], "fid", 4)) |
| 416 | table_search_mac_fid(argc, argv); |
| 417 | else if (!strncmp(argv[4], "vid", 4)) |
| 418 | table_search_mac_vid(argc, argv); |
| 419 | else |
| 420 | usage(argv[0]); |
| 421 | } else if (!strncmp(argv[1], "phy", 4)) { |
| 422 | if (argc == 3) { |
| 423 | int phy_addr = strtoul(argv[2], NULL, 0); |
| 424 | if (phy_addr < 0 || phy_addr > 31) |
| 425 | usage(argv[0]); |
| 426 | phy_dump(phy_addr); |
| 427 | } else if (argc == 5) { |
| 428 | if (!strncmp(argv[2], "fc", 2)) |
| 429 | phy_set_fc(argc, argv); |
| 430 | else if (!strncmp(argv[2], "an", 2)) |
| 431 | phy_set_an(argc, argv); |
| 432 | else |
| 433 | phy_dump(32); |
| 434 | } else |
| 435 | phy_operate(argc, argv); |
| 436 | } else if (!strncmp(argv[1], "trreg", 4)) { |
| 437 | if (rw_phy_token_ring(argc, argv) < 0) |
| 438 | usage(argv[0]); |
| 439 | } else if (!strncmp(argv[1], "macctl", 7)) { |
| 440 | if (argc < 3) |
| 441 | usage(argv[0]); |
| 442 | if (!strncmp(argv[2], "fc", 3)) |
| 443 | global_set_mac_fc(argc, argv); |
| 444 | else if (!strncmp(argv[2], "pfc", 4)) |
| 445 | set_mac_pfc(argc, argv); |
| 446 | else |
| 447 | usage(argv[0]); |
| 448 | } else if (!strncmp(argv[1], "qos", 4)) { |
| 449 | if (argc < 3) |
| 450 | usage(argv[0]); |
| 451 | if (!strncmp(argv[2], "sch", 4)) |
| 452 | qos_sch_select(argc, argv); |
| 453 | else if (!strncmp(argv[2], "base", 5)) |
| 454 | qos_set_base(argc, argv); |
| 455 | else if (!strncmp(argv[2], "port-weight", 12)) |
| 456 | qos_wfq_set_weight(argc, argv); |
| 457 | else if (!strncmp(argv[2], "port-prio", 10)) |
| 458 | qos_set_portpri(argc, argv); |
| 459 | else if (!strncmp(argv[2], "dscp-prio", 10)) |
| 460 | qos_set_dscppri(argc, argv); |
| 461 | else if (!strncmp(argv[2], "prio-qmap", 10)) |
| 462 | qos_pri_mapping_queue(argc, argv); |
| 463 | else |
| 464 | usage(argv[0]); |
| 465 | } else if (!strncmp(argv[1], "stp", 3)) { |
| 466 | if (argc < 3) |
| 467 | usage(argv[0]); |
| 468 | else |
| 469 | doStp(argc, argv); |
| 470 | } else if (!strncmp(argv[1], "sip", 5)) { |
| 471 | if (argc < 3) |
| 472 | usage(argv[0]); |
| 473 | if (!strncmp(argv[2], "dump", 5)) |
| 474 | sip_dump(); |
| 475 | else if (!strncmp(argv[2], "add", 4)) |
| 476 | sip_add(argc, argv); |
| 477 | else if (!strncmp(argv[2], "del", 4)) |
| 478 | sip_del(argc, argv); |
| 479 | else if (!strncmp(argv[2], "clear", 6)) |
| 480 | sip_clear(); |
| 481 | else |
| 482 | usage(argv[0]); |
| 483 | } else if (!strncmp(argv[1], "dip", 4)) { |
| 484 | if (argc < 3) |
| 485 | usage(argv[0]); |
| 486 | if (!strncmp(argv[2], "dump", 5)) |
| 487 | dip_dump(); |
| 488 | else if (!strncmp(argv[2], "add", 4)) |
| 489 | dip_add(argc, argv); |
| 490 | else if (!strncmp(argv[2], "del", 4)) |
| 491 | dip_del(argc, argv); |
| 492 | else if (!strncmp(argv[2], "clear", 6)) |
| 493 | dip_clear(); |
| 494 | else |
| 495 | usage(argv[0]); |
| 496 | } else if (!strncmp(argv[1], "mirror", 7)) { |
| 497 | if (argc < 3) |
| 498 | usage(argv[0]); |
| 499 | if (!strncmp(argv[2], "monitor", 8)) |
| 500 | set_mirror_to(argc, argv); |
| 501 | else if (!strncmp(argv[2], "target", 7)) |
| 502 | set_mirror_from(argc, argv); |
| 503 | else if (!strncmp(argv[2], "enable", 7)) |
| 504 | doMirrorEn(argc, argv); |
| 505 | else if (!strncmp(argv[2], "port-based", 11)) |
| 506 | doMirrorPortBased(argc, argv); |
| 507 | else |
| 508 | usage(argv[0]); |
| 509 | } else if (!strncmp(argv[1], "acl", 4)) { |
| 510 | if (argc < 3) |
| 511 | usage(argv[0]); |
| 512 | if (!strncmp(argv[2], "dip", 4)) { |
| 513 | if (!strncmp(argv[3], "add", 4)) |
| 514 | acl_dip_add(argc, argv); |
| 515 | else if (!strncmp(argv[3], "modup", 6)) |
| 516 | acl_dip_modify(argc, argv); |
| 517 | else if (!strncmp(argv[3], "pppoe", 6)) |
| 518 | acl_dip_pppoe(argc, argv); |
| 519 | else if (!strncmp(argv[3], "trtcm", 4)) |
| 520 | acl_dip_trtcm(argc, argv); |
| 521 | else if (!strncmp(argv[3], "meter", 6)) |
| 522 | acl_dip_meter(argc, argv); |
| 523 | else |
| 524 | usage(argv[0]); |
| 525 | } else if (!strncmp(argv[2], "dmac", 6)) { |
| 526 | if (!strncmp(argv[3], "add", 4)) |
| 527 | acl_mac_add(argc, argv); |
| 528 | else |
| 529 | usage(argv[0]); |
| 530 | } else if (!strncmp(argv[2], "etype", 6)) { |
| 531 | if (!strncmp(argv[3], "add", 4)) |
| 532 | acl_ethertype(argc, argv); |
| 533 | else |
| 534 | usage(argv[0]); |
| 535 | } else if (!strncmp(argv[2], "port", 5)) { |
| 536 | if (!strncmp(argv[3], "add", 4)) |
| 537 | acl_sp_add(argc, argv); |
| 538 | else |
| 539 | usage(argv[0]); |
| 540 | } else if (!strncmp(argv[2], "L4", 5)) { |
| 541 | if (!strncmp(argv[3], "add", 4)) |
| 542 | acl_l4_add(argc, argv); |
| 543 | else |
| 544 | usage(argv[0]); |
| 545 | } else if (!strncmp(argv[2], "enable", 7)) |
| 546 | acl_port_enable(argc, argv); |
| 547 | else if (!strncmp(argv[2], "acltbl-add", 11)) |
| 548 | acl_table_add(argc, argv); |
| 549 | else if (!strncmp(argv[2], "masktbl-add", 12)) |
| 550 | acl_mask_table_add(argc, argv); |
| 551 | else if (!strncmp(argv[2], "ruletbl-add", 12)) |
| 552 | acl_rule_table_add(argc, argv); |
| 553 | else if (!strncmp(argv[2], "ratetbl-add", 12)) |
| 554 | acl_rate_table_add(argc, argv); |
| 555 | else |
| 556 | usage(argv[0]); |
| 557 | } else if (!strncmp(argv[1], "vlan", 5)) { |
| 558 | if (argc < 3) |
| 559 | usage(argv[0]); |
| 560 | if (!strncmp(argv[2], "dump", 5)) |
| 561 | vlan_dump(argc, argv); |
| 562 | else if (!strncmp(argv[2], "set", 4)) |
| 563 | vlan_set(argc, argv); |
| 564 | else if (!strncmp(argv[2], "clear", 6)) |
| 565 | vlan_clear(argc, argv); |
| 566 | else if (!strncmp(argv[2], "vid", 4)) |
| 567 | doVlanSetVid(argc, argv); |
| 568 | else if (!strncmp(argv[2], "pvid", 5)) |
| 569 | doVlanSetPvid(argc, argv); |
| 570 | else if (!strncmp(argv[2], "acc-frm", 8)) |
| 571 | doVlanSetAccFrm(argc, argv); |
| 572 | else if (!strncmp(argv[2], "port-attr", 10)) |
| 573 | doVlanSetPortAttr(argc, argv); |
| 574 | else if (!strncmp(argv[2], "port-mode", 10)) |
| 575 | doVlanSetPortMode(argc, argv); |
| 576 | else if (!strncmp(argv[2], "eg-tag-pcr", 11)) |
| 577 | doVlanSetEgressTagPCR(argc, argv); |
| 578 | else if (!strncmp(argv[2], "eg-tag-pvc", 11)) |
| 579 | doVlanSetEgressTagPVC(argc, argv); |
| 580 | else |
| 581 | usage(argv[0]); |
| 582 | } else if (!strncmp(argv[1], "reg", 4)) { |
| 583 | parse_reg_cmd(argc, argv, 4); |
| 584 | } else if (!strncmp(argv[1], "ingress-rate", 6)) { |
| 585 | int port = 0, bw = 0; |
| 586 | if (argv[2][1] == 'n') { |
| 587 | port = strtoul(argv[3], NULL, 0); |
| 588 | bw = strtoul(argv[4], NULL, 0); |
| 589 | if (ingress_rate_set(1, port, bw) == 0) |
| 590 | printf("switch port=%d, bw=%d\n", port, bw); |
| 591 | } |
| 592 | else if (argv[2][1] == 'f') { |
| 593 | if (argc != 4) |
| 594 | usage(argv[0]); |
| 595 | port = strtoul(argv[3], NULL, 0); |
| 596 | if (ingress_rate_set(0, port, bw) == 0) |
| 597 | printf("switch port=%d ingress rate limit off\n", port); |
| 598 | } else |
| 599 | usage(argv[0]); |
| 600 | } else if (!strncmp(argv[1], "egress-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 (egress_rate_set(1, port, bw) == 0) |
| 606 | printf("switch port=%d, bw=%d\n", port, bw); |
| 607 | } else if (argv[2][1] == 'f') { |
| 608 | if (argc != 4) |
| 609 | usage(argv[0]); |
| 610 | port = strtoul(argv[3], NULL, 0); |
| 611 | if (egress_rate_set(0, port, bw) == 0) |
| 612 | printf("switch port=%d egress rate limit off\n", port); |
| 613 | } else |
| 614 | usage(argv[0]); |
| 615 | } else if (!strncmp(argv[1], "igmpsnoop", 10)) { |
| 616 | if (argc < 3) |
| 617 | usage(argv[0]); |
| 618 | if (!strncmp(argv[2], "on", 3)) |
| 619 | igmp_on(argc, argv); |
| 620 | else if (!strncmp(argv[2], "off", 4)) |
| 621 | igmp_off(); |
| 622 | else if (!strncmp(argv[2], "enable", 7)) |
| 623 | igmp_enable(argc, argv); |
| 624 | else if (!strncmp(argv[2], "disable", 8)) |
| 625 | igmp_disable(argc, argv); |
| 626 | else |
| 627 | usage(argv[0]); |
| 628 | } else if (!strncmp(argv[1], "collision-pool", 15)) { |
| 629 | if (argc < 3) |
| 630 | usage(argv[0]); |
| 631 | if (!strncmp(argv[2], "enable", 7)) |
| 632 | collision_pool_enable(argc, argv); |
| 633 | else if (!strncmp(argv[2], "mac", 4)){ |
| 634 | if (!strncmp(argv[3], "dump", 5)) |
| 635 | collision_pool_mac_dump(); |
| 636 | else |
| 637 | usage(argv[0]); |
| 638 | } else if (!strncmp(argv[2], "dip", 4)){ |
| 639 | if (!strncmp(argv[3], "dump", 5)) |
| 640 | collision_pool_dip_dump(); |
| 641 | else |
| 642 | usage(argv[0]); |
| 643 | } else if (!strncmp(argv[2], "sip", 4)){ |
| 644 | if (!strncmp(argv[3], "dump", 5)) |
| 645 | collision_pool_sip_dump(); |
| 646 | else |
| 647 | usage(argv[0]); |
| 648 | } |
| 649 | else |
| 650 | usage(argv[0]); |
| 651 | } else if (!strncmp(argv[1], "pfc", 15)) { |
| 652 | if (argc < 4 || argc > 5) |
| 653 | usage(argv[0]); |
| 654 | if (!strncmp(argv[2], "enable", 7)) |
| 655 | set_mac_pfc(argc, argv); |
| 656 | else if (!strncmp(argv[2], "rx_counter", 11)){ |
| 657 | pfc_get_rx_counter(argc, argv); |
| 658 | } else if (!strncmp(argv[2], "tx_counter", 11)){ |
| 659 | pfc_get_tx_counter(argc, argv); |
| 660 | } else |
| 661 | usage(argv[0]); |
| 662 | } else if (!strncmp(argv[1], "crossover", 10)) { |
| 663 | if (argc < 4) |
| 664 | usage(argv[0]); |
| 665 | else |
| 666 | phy_crossover(argc, argv); |
| 667 | } else if (!strncmp(argv[1], "eee", 4)) { |
| 668 | if (argc < 3) |
| 669 | usage(argv[0]); |
| 670 | if (!strncmp(argv[2], "enable", 7) || |
| 671 | !strncmp(argv[2], "disable", 8)) |
| 672 | eee_enable(argc, argv); |
| 673 | else if (!strncmp(argv[2], "dump", 5)) |
| 674 | eee_dump(argc, argv); |
| 675 | else |
| 676 | usage(argv[0]); |
| 677 | } else |
| 678 | usage(argv[0]); |
| 679 | |
| 680 | exit_free(); |
| 681 | return 0; |
| 682 | } |