| /* |
| <:copyright-BRCM:2016:DUAL/GPL:standard |
| |
| Broadcom Proprietary and Confidential.(c) 2016 Broadcom |
| All Rights Reserved |
| |
| Unless you and Broadcom execute a separate written software license |
| agreement governing use of this software, this software is licensed |
| to you under the terms of the GNU General Public License version 2 |
| (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php, |
| with the following added to such license: |
| |
| As a special exception, the copyright holders of this software give |
| you permission to link this software with independent modules, and |
| to copy and distribute the resulting executable under terms of your |
| choice, provided that you also meet, for each linked independent |
| module, the terms and conditions of the license of that module. |
| An independent module is a module which is not derived from this |
| software. The special exception does not apply to any modifications |
| of the software. |
| |
| Not withstanding the above, under no circumstances may you combine |
| this software in any way with any other Broadcom software provided |
| under a license other than the GPL, without Broadcom's express prior |
| written consent. |
| |
| :> |
| */ |
| |
| #include <bcmos_system.h> |
| #include <bcmcli.h> |
| #include <bcmtr_interface.h> |
| #include <bcmtr_internal.h> |
| #include <bcmtr_transport_cli.h> |
| #include <bcm_api_cli_helpers.h> |
| #ifdef BCMTR_PERFTEST |
| #include <test/bcmtr_perftest.h> |
| #endif |
| |
| #ifdef BCMTR_PLUGIN_TASK_FORWARDER |
| extern uint32_t raw_tx_drop_count; |
| #endif |
| |
| /* |
| * CLI support |
| */ |
| static bcmcli_entry *trcli_dir; |
| |
| #ifdef BCMTR_UDP_SUPPORT |
| |
| /* Display/set host IP+port |
| BCMCLI_MAKE_PARM("ip_addr", "IP address", BCMCLI_PARM_IP, BCMCLI_PARM_FLAG_OPTIONAL), |
| BCMCLI_MAKE_PARM_RANGE("udp_port", "UDP port", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_OPTIONAL, |
| */ |
| static bcmos_errno _bcmtr_cli_host_udp(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t nparms) |
| { |
| if (!nparms) |
| { |
| bcmcli_session_print(session, "Host Address:port = %d.%d.%d.%d:%d\n", |
| (bcmtr_host_ip >> 24) & 0xff, (bcmtr_host_ip >> 16) & 0xff, |
| (bcmtr_host_ip >> 8) & 0xff, bcmtr_host_ip & 0xff, bcmtr_host_udp_port); |
| } |
| else |
| { |
| if (bcmcli_parm_is_set(session, &parm[0])) |
| { |
| bcmtr_host_ip = parm[0].value.number; |
| } |
| if (bcmcli_parm_is_set(session, &parm[1])) |
| { |
| bcmtr_host_udp_port = parm[1].value.number; |
| } |
| } |
| |
| return BCM_ERR_OK; |
| } |
| |
| /* Display/Set OLT IP+port |
| BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| BCMCLI_MAKE_PARM("ip_addr", "IP address", BCMCLI_PARM_IP, BCMCLI_PARM_FLAG_OPTIONAL), |
| BCMCLI_MAKE_PARM_RANGE("udp_port", "UDP port", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_OPTIONAL, |
| */ |
| static bcmos_errno _bcmtr_cli_olt_udp(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t nparms) |
| { |
| bcmolt_devid device = (bcmolt_devid)parm[0].value.number; |
| |
| if (nparms == 1) |
| { |
| bcmcli_session_print(session, "OLT[%d] Address:port = %d.%d.%d.%d:%d\n", |
| device, |
| (bcmtr_olt_ip[device] >> 24) & 0xff, (bcmtr_olt_ip[device] >> 16) & 0xff, |
| (bcmtr_olt_ip[device] >> 8) & 0xff, bcmtr_olt_ip[device] & 0xff, |
| bcmtr_olt_udp_port[device]); |
| } |
| else |
| { |
| if (bcmcli_parm_is_set(session, &parm[1])) |
| { |
| bcmtr_olt_ip[device] = parm[1].value.number; |
| } |
| if (bcmcli_parm_is_set(session, &parm[2])) |
| { |
| bcmtr_olt_udp_port[device] = parm[2].value.number; |
| } |
| } |
| |
| return BCM_ERR_OK; |
| } |
| |
| #endif /* #ifdef BCMTR_UDP_SUPPORT */ |
| |
| /* Connect |
| BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| */ |
| static bcmos_errno _bcmtr_cli_connect(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t nparms) |
| { |
| bcmolt_devid device = (bcmolt_devid)parm[0].value.number; |
| return bcmtr_connect(device); |
| } |
| |
| /* Disconnect |
| BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| */ |
| static bcmos_errno _bcmtr_cli_disconnect(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t nparms) |
| { |
| bcmolt_devid device = (bcmolt_devid)parm[0].value.number; |
| return bcmtr_disconnect(device); |
| } |
| |
| /* Reconnect |
| BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| */ |
| static bcmos_errno _bcmtr_cli_reconnect(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t nparms) |
| { |
| bcmolt_devid device = (bcmolt_devid)parm[0].value.number; |
| return bcmtr_driver_reconnect(device); |
| } |
| |
| /* Stat |
| BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| */ |
| static bcmos_errno _bcmtr_cli_stat(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t nparms) |
| { |
| bcmolt_devid device = (bcmolt_devid)parm[0].value.number; |
| bcmtr_stat stat; |
| bcmos_errno err; |
| #ifdef BCMTR_PLUGIN_TASK_FORWARDER |
| static uint32_t prev_raw_tx_drop_count; |
| uint32_t new_raw_tx_drop_count = raw_tx_drop_count; |
| #endif |
| |
| err = bcmtr_stat_get(device, &stat); |
| if (err) |
| return err; |
| |
| bcmcli_session_print(session, "%-24s : %d\n", "msg_sent", stat.msg_sent); |
| bcmcli_session_print(session, "%-24s : %d\n", "msg_resp_received", stat.msg_resp_received); |
| bcmcli_session_print(session, "%-24s : %d\n", "msg_req_auto_received", stat.msg_req_auto_received); |
| bcmcli_session_print(session, "%-24s : %d\n", "msg_req_timeout", stat.msg_req_timeout); |
| bcmcli_session_print(session, "%-24s : %d\n", "msg_reass_timeout", stat.msg_reass_timeout); |
| bcmcli_session_print(session, "%-24s : %d\n", "msg_no_req", stat.msg_no_req); |
| bcmcli_session_print(session, "%-24s : %d\n", "msg_no_mem", stat.msg_no_mem); |
| bcmcli_session_print(session, "%-24s : %d\n", "msg_comm_err", stat.msg_comm_err); |
| bcmcli_session_print(session, "%-24s : %d\n", "msg_ready_timeout", stat.msg_ready_timeout); |
| bcmcli_session_print(session, "%-24s : %d\n", "msg_too_many_req", stat.msg_too_many_req); |
| bcmcli_session_print(session, "%-24s : %d\n", "msg_too_many_auto", stat.msg_too_many_auto); |
| bcmcli_session_print(session, "%-24s : %d\n", "frag_received", stat.frag_received); |
| bcmcli_session_print(session, "%-24s : %d\n", "frag_invalid", stat.frag_invalid); |
| bcmcli_session_print(session, "%-24s : %d\n", "unpack_errors", stat.unpack_errors); |
| bcmcli_session_print(session, "%-24s : %d\n", "pack_errors", stat.pack_errors); |
| bcmcli_session_print(session, "%-24s : %d\n", "no_rx_handler", stat.no_rx_handler); |
| bcmcli_session_print(session, "%-24s : %d\n", "not_connected", stat.not_connected); |
| #ifdef BCMTR_PLUGIN_TASK_FORWARDER |
| bcmcli_session_print(session, "%-24s : %d\n", "raw_tx_drop", new_raw_tx_drop_count - prev_raw_tx_drop_count); |
| prev_raw_tx_drop_count = new_raw_tx_drop_count; |
| #endif |
| return BCM_ERR_OK; |
| } |
| |
| /* Register |
| BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| */ |
| static bcmos_errno _bcmtr_cli_register_info(bcmcli_session *session, const bcmcli_cmd_parm parm[], uint16_t nparms) |
| { |
| bcmolt_devid device = (bcmolt_devid)parm[0].value.number; |
| bcmtr_handler_parm p = |
| { |
| .instance = (uint8_t)parm[1].value.number, |
| .group = (bcmolt_mgt_group)parm[2].value.number, |
| }; |
| |
| if (p.instance >= BCMTR_MAX_INSTANCES) |
| { |
| return BCM_ERR_PARM; |
| } |
| |
| for (p.object = BCMOLT_OBJ_ID_DEVICE; p.object < BCMOLT_OBJ_ID__NUM_OF; p.object++) |
| { |
| bcmolt_group_id group_id; |
| const char *obj_name, *obj_descr; |
| const char *sub_name, *sub_descr; |
| |
| if (api_cli_object_name(p.object, &obj_name, &obj_descr) != BCM_ERR_OK) |
| continue; |
| |
| for (p.subgroup = 0; bcmtr_msg_handler_register_get(device, &p) == BCM_ERR_OK; p.subgroup++) |
| { |
| bcmolt_group_id_combine(p.object, p.group, p.subgroup, &group_id); |
| api_cli_object_subgroup_name(p.object, p.group, p.subgroup, &sub_name, &sub_descr); |
| |
| bcmcli_session_print(session, "%s - %s : msg_id=%u ", obj_name, sub_name, group_id); |
| if (p.app_cb) |
| { |
| bcmcli_session_print(session, "module:%d func:%p\n", p.module, p.app_cb); |
| } |
| else |
| { |
| bcmcli_session_print(session, "NONE\n"); |
| } |
| } |
| } |
| return BCM_ERR_OK; |
| } |
| |
| |
| bcmos_errno bcmtr_cli_init(void) |
| { |
| if ((trcli_dir=bcmcli_dir_find(NULL, "transport")) != NULL) |
| return BCM_ERR_ALREADY; |
| trcli_dir = bcmcli_dir_add(NULL, "transport", "Maple Transport", BCMCLI_ACCESS_GUEST, NULL); |
| if (!trcli_dir) |
| { |
| printf("Can't create transport directory\n"); |
| return BCM_ERR_INTERNAL; |
| } |
| |
| #ifdef BCMTR_UDP_SUPPORT |
| |
| BCMCLI_MAKE_CMD(trcli_dir, "host_udp", "Host IP and UDP port parameters", _bcmtr_cli_host_udp, |
| BCMCLI_MAKE_PARM("ip_addr", "IP address", BCMCLI_PARM_IP, BCMCLI_PARM_FLAG_OPTIONAL), |
| BCMCLI_MAKE_PARM_RANGE("udp_port", "UDP port", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_OPTIONAL, |
| 0, 0xffff)); |
| BCMCLI_MAKE_CMD(trcli_dir, "olt_udp", "OLT IP and UDP port parameters", _bcmtr_cli_olt_udp, |
| BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| 0, BCMTR_MAX_OLTS-1), |
| BCMCLI_MAKE_PARM("ip_addr", "IP address", BCMCLI_PARM_IP, BCMCLI_PARM_FLAG_OPTIONAL), |
| BCMCLI_MAKE_PARM_RANGE("udp_port", "UDP port", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_OPTIONAL, |
| 0, 0xffff)); |
| #endif |
| |
| BCMCLI_MAKE_CMD(trcli_dir, "connect", "Connect", _bcmtr_cli_connect, |
| BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| 0, BCMTR_MAX_OLTS-1)); |
| |
| BCMCLI_MAKE_CMD(trcli_dir, "disconnect", "Disconnect", _bcmtr_cli_disconnect, |
| BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| 0, BCMTR_MAX_OLTS-1)); |
| |
| BCMCLI_MAKE_CMD(trcli_dir, "reconnect", "Reconnect", _bcmtr_cli_reconnect, |
| BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| 0, BCMTR_MAX_OLTS-1)); |
| |
| BCMCLI_MAKE_CMD(trcli_dir, "stat", "Transport statistics", _bcmtr_cli_stat, |
| BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| 0, BCMTR_MAX_OLTS-1)); |
| |
| { |
| static bcmcli_enum_val groups[] = |
| { |
| #ifdef BCM_SUBSYSTEM_HOST |
| { .name = "auto", .val = BCMOLT_MGT_GROUP_CFG }, |
| { .name = "proxy_rx", .val = BCMOLT_MGT_GROUP_PROXY_RX }, |
| #else |
| { .name = "cfg", .val = BCMOLT_MGT_GROUP_CFG }, |
| { .name = "stat", .val = BCMOLT_MGT_GROUP_STAT }, |
| { .name = "stat_cfg", .val = BCMOLT_MGT_GROUP_STAT_CFG }, |
| { .name = "oper", .val = BCMOLT_MGT_GROUP_OPER }, |
| { .name = "auto_cfg", .val = BCMOLT_MGT_GROUP_AUTO_CFG }, |
| { .name = "proxy", .val = BCMOLT_MGT_GROUP_PROXY }, |
| #endif |
| { .name = NULL } |
| |
| }; |
| BCMCLI_MAKE_CMD(trcli_dir, "registration", "Transport RX registration info", _bcmtr_cli_register_info, |
| BCMCLI_MAKE_PARM_RANGE("device", "Device index", BCMCLI_PARM_DECIMAL, 0, |
| 0, BCMTR_MAX_OLTS-1), |
| BCMCLI_MAKE_PARM_RANGE("pon_ni", "PON NI", BCMCLI_PARM_DECIMAL, 0, |
| 0, BCMTR_MAX_INSTANCES-1), |
| BCMCLI_MAKE_PARM_ENUM("group", "Management group", groups, 0) ); |
| } |
| |
| /* Performance testing directory */ |
| #ifdef BCMTR_PERFTEST |
| bcmtr_test_init(); |
| #endif |
| |
| return BCM_ERR_OK; |
| } |
| |
| void bcmtr_cli_exit(void) |
| { |
| if (trcli_dir) |
| { |
| bcmcli_token_destroy(trcli_dir); |
| trcli_dir = NULL; |
| } |
| } |