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