Shad Ansari | 2f7f9be | 2017-06-07 13:34:53 -0700 | [diff] [blame^] | 1 | /* |
| 2 | <:copyright-BRCM:2016:DUAL/GPL:standard |
| 3 | |
| 4 | Broadcom Proprietary and Confidential.(c) 2016 Broadcom |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Unless you and Broadcom execute a separate written software license |
| 8 | agreement governing use of this software, this software is licensed |
| 9 | to you under the terms of the GNU General Public License version 2 |
| 10 | (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php, |
| 11 | with the following added to such license: |
| 12 | |
| 13 | As a special exception, the copyright holders of this software give |
| 14 | you permission to link this software with independent modules, and |
| 15 | to copy and distribute the resulting executable under terms of your |
| 16 | choice, provided that you also meet, for each linked independent |
| 17 | module, the terms and conditions of the license of that module. |
| 18 | An independent module is a module which is not derived from this |
| 19 | software. The special exception does not apply to any modifications |
| 20 | of the software. |
| 21 | |
| 22 | Not withstanding the above, under no circumstances may you combine |
| 23 | this software in any way with any other Broadcom software provided |
| 24 | under a license other than the GPL, without Broadcom's express prior |
| 25 | written consent. |
| 26 | |
| 27 | :> |
| 28 | */ |
| 29 | |
| 30 | #include <bcmos_system.h> |
| 31 | #include <bcmcli.h> |
| 32 | #include <bcmtr_interface.h> |
| 33 | #include <bcmtr_internal.h> |
| 34 | #include <bcmtr_transport_cli.h> |
| 35 | #include <bcm_api_cli_helpers.h> |
| 36 | #ifdef BCMTR_PERFTEST |
| 37 | #include <test/bcmtr_perftest.h> |
| 38 | #endif |
| 39 | |
| 40 | #ifdef BCMTR_PLUGIN_TASK_FORWARDER |
| 41 | extern uint32_t raw_tx_drop_count; |
| 42 | #endif |
| 43 | |
| 44 | /* |
| 45 | * CLI support |
| 46 | */ |
| 47 | static bcmcli_entry *trcli_dir; |
| 48 | |
| 49 | #ifdef BCMTR_UDP_SUPPORT |
| 50 | |
| 51 | /* Display/set host IP+port |
| 52 | BCMCLI_MAKE_PARM("ip_addr", "IP address", BCMCLI_PARM_IP, BCMCLI_PARM_FLAG_OPTIONAL), |
| 53 | BCMCLI_MAKE_PARM_RANGE("udp_port", "UDP port", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_OPTIONAL, |
| 54 | */ |
| 55 | static bcmos_errno _bcmtr_cli_host_udp(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t nparms) |
| 56 | { |
| 57 | if (!nparms) |
| 58 | { |
| 59 | bcmcli_session_print(session, "Host Address:port = %d.%d.%d.%d:%d\n", |
| 60 | (bcmtr_host_ip >> 24) & 0xff, (bcmtr_host_ip >> 16) & 0xff, |
| 61 | (bcmtr_host_ip >> 8) & 0xff, bcmtr_host_ip & 0xff, bcmtr_host_udp_port); |
| 62 | } |
| 63 | else |
| 64 | { |
| 65 | if (bcmcli_parm_is_set(session, &parm[0])) |
| 66 | { |
| 67 | bcmtr_host_ip = parm[0].value.number; |
| 68 | } |
| 69 | if (bcmcli_parm_is_set(session, &parm[1])) |
| 70 | { |
| 71 | bcmtr_host_udp_port = parm[1].value.number; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | return BCM_ERR_OK; |
| 76 | } |
| 77 | |
| 78 | /* Display/Set OLT IP+port |
| 79 | BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| 80 | BCMCLI_MAKE_PARM("ip_addr", "IP address", BCMCLI_PARM_IP, BCMCLI_PARM_FLAG_OPTIONAL), |
| 81 | BCMCLI_MAKE_PARM_RANGE("udp_port", "UDP port", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_OPTIONAL, |
| 82 | */ |
| 83 | static bcmos_errno _bcmtr_cli_olt_udp(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t nparms) |
| 84 | { |
| 85 | bcmolt_devid device = (bcmolt_devid)parm[0].value.number; |
| 86 | |
| 87 | if (nparms == 1) |
| 88 | { |
| 89 | bcmcli_session_print(session, "OLT[%d] Address:port = %d.%d.%d.%d:%d\n", |
| 90 | device, |
| 91 | (bcmtr_olt_ip[device] >> 24) & 0xff, (bcmtr_olt_ip[device] >> 16) & 0xff, |
| 92 | (bcmtr_olt_ip[device] >> 8) & 0xff, bcmtr_olt_ip[device] & 0xff, |
| 93 | bcmtr_olt_udp_port[device]); |
| 94 | } |
| 95 | else |
| 96 | { |
| 97 | if (bcmcli_parm_is_set(session, &parm[1])) |
| 98 | { |
| 99 | bcmtr_olt_ip[device] = parm[1].value.number; |
| 100 | } |
| 101 | if (bcmcli_parm_is_set(session, &parm[2])) |
| 102 | { |
| 103 | bcmtr_olt_udp_port[device] = parm[2].value.number; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | return BCM_ERR_OK; |
| 108 | } |
| 109 | |
| 110 | #endif /* #ifdef BCMTR_UDP_SUPPORT */ |
| 111 | |
| 112 | /* Connect |
| 113 | BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| 114 | */ |
| 115 | static bcmos_errno _bcmtr_cli_connect(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t nparms) |
| 116 | { |
| 117 | bcmolt_devid device = (bcmolt_devid)parm[0].value.number; |
| 118 | return bcmtr_connect(device); |
| 119 | } |
| 120 | |
| 121 | /* Disconnect |
| 122 | BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| 123 | */ |
| 124 | static bcmos_errno _bcmtr_cli_disconnect(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t nparms) |
| 125 | { |
| 126 | bcmolt_devid device = (bcmolt_devid)parm[0].value.number; |
| 127 | return bcmtr_disconnect(device); |
| 128 | } |
| 129 | |
| 130 | /* Reconnect |
| 131 | BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| 132 | */ |
| 133 | static bcmos_errno _bcmtr_cli_reconnect(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t nparms) |
| 134 | { |
| 135 | bcmolt_devid device = (bcmolt_devid)parm[0].value.number; |
| 136 | return bcmtr_driver_reconnect(device); |
| 137 | } |
| 138 | |
| 139 | /* Stat |
| 140 | BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| 141 | */ |
| 142 | static bcmos_errno _bcmtr_cli_stat(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t nparms) |
| 143 | { |
| 144 | bcmolt_devid device = (bcmolt_devid)parm[0].value.number; |
| 145 | bcmtr_stat stat; |
| 146 | bcmos_errno err; |
| 147 | #ifdef BCMTR_PLUGIN_TASK_FORWARDER |
| 148 | static uint32_t prev_raw_tx_drop_count; |
| 149 | uint32_t new_raw_tx_drop_count = raw_tx_drop_count; |
| 150 | #endif |
| 151 | |
| 152 | err = bcmtr_stat_get(device, &stat); |
| 153 | if (err) |
| 154 | return err; |
| 155 | |
| 156 | bcmcli_session_print(session, "%-24s : %d\n", "msg_sent", stat.msg_sent); |
| 157 | bcmcli_session_print(session, "%-24s : %d\n", "msg_resp_received", stat.msg_resp_received); |
| 158 | bcmcli_session_print(session, "%-24s : %d\n", "msg_req_auto_received", stat.msg_req_auto_received); |
| 159 | bcmcli_session_print(session, "%-24s : %d\n", "msg_req_timeout", stat.msg_req_timeout); |
| 160 | bcmcli_session_print(session, "%-24s : %d\n", "msg_reass_timeout", stat.msg_reass_timeout); |
| 161 | bcmcli_session_print(session, "%-24s : %d\n", "msg_no_req", stat.msg_no_req); |
| 162 | bcmcli_session_print(session, "%-24s : %d\n", "msg_no_mem", stat.msg_no_mem); |
| 163 | bcmcli_session_print(session, "%-24s : %d\n", "msg_comm_err", stat.msg_comm_err); |
| 164 | bcmcli_session_print(session, "%-24s : %d\n", "msg_ready_timeout", stat.msg_ready_timeout); |
| 165 | bcmcli_session_print(session, "%-24s : %d\n", "msg_too_many_req", stat.msg_too_many_req); |
| 166 | bcmcli_session_print(session, "%-24s : %d\n", "msg_too_many_auto", stat.msg_too_many_auto); |
| 167 | bcmcli_session_print(session, "%-24s : %d\n", "frag_received", stat.frag_received); |
| 168 | bcmcli_session_print(session, "%-24s : %d\n", "frag_invalid", stat.frag_invalid); |
| 169 | bcmcli_session_print(session, "%-24s : %d\n", "unpack_errors", stat.unpack_errors); |
| 170 | bcmcli_session_print(session, "%-24s : %d\n", "pack_errors", stat.pack_errors); |
| 171 | bcmcli_session_print(session, "%-24s : %d\n", "no_rx_handler", stat.no_rx_handler); |
| 172 | bcmcli_session_print(session, "%-24s : %d\n", "not_connected", stat.not_connected); |
| 173 | #ifdef BCMTR_PLUGIN_TASK_FORWARDER |
| 174 | bcmcli_session_print(session, "%-24s : %d\n", "raw_tx_drop", new_raw_tx_drop_count - prev_raw_tx_drop_count); |
| 175 | prev_raw_tx_drop_count = new_raw_tx_drop_count; |
| 176 | #endif |
| 177 | return BCM_ERR_OK; |
| 178 | } |
| 179 | |
| 180 | /* Register |
| 181 | BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| 182 | */ |
| 183 | static bcmos_errno _bcmtr_cli_register_info(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t nparms) |
| 184 | { |
| 185 | bcmolt_devid device = (bcmolt_devid)parm[0].value.number; |
| 186 | bcmtr_handler_parm p = |
| 187 | { |
| 188 | .instance = (uint8_t)parm[1].value.number, |
| 189 | .group = (bcmolt_mgt_group)parm[2].value.number, |
| 190 | }; |
| 191 | |
| 192 | if (p.instance >= BCMTR_MAX_INSTANCES) |
| 193 | { |
| 194 | return BCM_ERR_PARM; |
| 195 | } |
| 196 | |
| 197 | for (p.object = BCMOLT_OBJ_ID_DEVICE; p.object < BCMOLT_OBJ_ID__NUM_OF; p.object++) |
| 198 | { |
| 199 | bcmolt_group_id group_id; |
| 200 | const char *obj_name, *obj_descr; |
| 201 | const char *sub_name, *sub_descr; |
| 202 | |
| 203 | if (api_cli_object_name(p.object, &obj_name, &obj_descr) != BCM_ERR_OK) |
| 204 | continue; |
| 205 | |
| 206 | for (p.subgroup = 0; bcmtr_msg_handler_register_get(device, &p) == BCM_ERR_OK; p.subgroup++) |
| 207 | { |
| 208 | bcmolt_group_id_combine(p.object, p.group, p.subgroup, &group_id); |
| 209 | api_cli_object_subgroup_name(p.object, p.group, p.subgroup, &sub_name, &sub_descr); |
| 210 | |
| 211 | bcmcli_session_print(session, "%s - %s : msg_id=%u ", obj_name, sub_name, group_id); |
| 212 | if (p.app_cb) |
| 213 | { |
| 214 | bcmcli_session_print(session, "module:%d func:%p\n", p.module, p.app_cb); |
| 215 | } |
| 216 | else |
| 217 | { |
| 218 | bcmcli_session_print(session, "NONE\n"); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | return BCM_ERR_OK; |
| 223 | } |
| 224 | |
| 225 | |
| 226 | bcmos_errno bcmtr_cli_init(void) |
| 227 | { |
| 228 | if ((trcli_dir=bcmcli_dir_find(NULL, "transport")) != NULL) |
| 229 | return BCM_ERR_ALREADY; |
| 230 | trcli_dir = bcmcli_dir_add(NULL, "transport", "Maple Transport", BCMCLI_ACCESS_GUEST, NULL); |
| 231 | if (!trcli_dir) |
| 232 | { |
| 233 | printf("Can't create transport directory\n"); |
| 234 | return BCM_ERR_INTERNAL; |
| 235 | } |
| 236 | |
| 237 | #ifdef BCMTR_UDP_SUPPORT |
| 238 | |
| 239 | BCMCLI_MAKE_CMD(trcli_dir, "host_udp", "Host IP and UDP port parameters", _bcmtr_cli_host_udp, |
| 240 | BCMCLI_MAKE_PARM("ip_addr", "IP address", BCMCLI_PARM_IP, BCMCLI_PARM_FLAG_OPTIONAL), |
| 241 | BCMCLI_MAKE_PARM_RANGE("udp_port", "UDP port", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_OPTIONAL, |
| 242 | 0, 0xffff)); |
| 243 | BCMCLI_MAKE_CMD(trcli_dir, "olt_udp", "OLT IP and UDP port parameters", _bcmtr_cli_olt_udp, |
| 244 | BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| 245 | 0, BCMTR_MAX_OLTS-1), |
| 246 | BCMCLI_MAKE_PARM("ip_addr", "IP address", BCMCLI_PARM_IP, BCMCLI_PARM_FLAG_OPTIONAL), |
| 247 | BCMCLI_MAKE_PARM_RANGE("udp_port", "UDP port", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_OPTIONAL, |
| 248 | 0, 0xffff)); |
| 249 | #endif |
| 250 | |
| 251 | BCMCLI_MAKE_CMD(trcli_dir, "connect", "Connect", _bcmtr_cli_connect, |
| 252 | BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| 253 | 0, BCMTR_MAX_OLTS-1)); |
| 254 | |
| 255 | BCMCLI_MAKE_CMD(trcli_dir, "disconnect", "Disconnect", _bcmtr_cli_disconnect, |
| 256 | BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| 257 | 0, BCMTR_MAX_OLTS-1)); |
| 258 | |
| 259 | BCMCLI_MAKE_CMD(trcli_dir, "reconnect", "Reconnect", _bcmtr_cli_reconnect, |
| 260 | BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| 261 | 0, BCMTR_MAX_OLTS-1)); |
| 262 | |
| 263 | BCMCLI_MAKE_CMD(trcli_dir, "stat", "Transport statistics", _bcmtr_cli_stat, |
| 264 | BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| 265 | 0, BCMTR_MAX_OLTS-1)); |
| 266 | |
| 267 | { |
| 268 | static bcmcli_enum_val groups[] = |
| 269 | { |
| 270 | #ifdef BCM_SUBSYSTEM_HOST |
| 271 | { .name = "auto", .val = BCMOLT_MGT_GROUP_CFG }, |
| 272 | { .name = "proxy_rx", .val = BCMOLT_MGT_GROUP_PROXY_RX }, |
| 273 | #else |
| 274 | { .name = "cfg", .val = BCMOLT_MGT_GROUP_CFG }, |
| 275 | { .name = "stat", .val = BCMOLT_MGT_GROUP_STAT }, |
| 276 | { .name = "stat_cfg", .val = BCMOLT_MGT_GROUP_STAT_CFG }, |
| 277 | { .name = "oper", .val = BCMOLT_MGT_GROUP_OPER }, |
| 278 | { .name = "auto_cfg", .val = BCMOLT_MGT_GROUP_AUTO_CFG }, |
| 279 | { .name = "proxy", .val = BCMOLT_MGT_GROUP_PROXY }, |
| 280 | #endif |
| 281 | { .name = NULL } |
| 282 | |
| 283 | }; |
| 284 | BCMCLI_MAKE_CMD(trcli_dir, "registration", "Transport RX registration info", _bcmtr_cli_register_info, |
| 285 | BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| 286 | 0, BCMTR_MAX_OLTS-1), |
| 287 | BCMCLI_MAKE_PARM_RANGE("pon_ni", "PON NI", BCMCLI_PARM_DECIMAL, 0, |
| 288 | 0, BCMTR_MAX_INSTANCES-1), |
| 289 | BCMCLI_MAKE_PARM_ENUM("group", "Management group", groups, 0) ); |
| 290 | } |
| 291 | |
| 292 | /* Performance testing directory */ |
| 293 | #ifdef BCMTR_PERFTEST |
| 294 | bcmtr_test_init(); |
| 295 | #endif |
| 296 | |
| 297 | return BCM_ERR_OK; |
| 298 | } |
| 299 | |
| 300 | void bcmtr_cli_exit(void) |
| 301 | { |
| 302 | if (trcli_dir) |
| 303 | { |
| 304 | bcmcli_token_destroy(trcli_dir); |
| 305 | trcli_dir = NULL; |
| 306 | } |
| 307 | } |