blob: 9d529e390941d0101643382a3bbcc295e2583808 [file] [log] [blame]
Shad Ansari2f7f9be2017-06-07 13:34:53 -07001/*
2<:copyright-BRCM:2016:DUAL/GPL:standard
3
4 Broadcom Proprietary and Confidential.(c) 2016 Broadcom
5 All Rights Reserved
6
7Unless you and Broadcom execute a separate written software license
8agreement governing use of this software, this software is licensed
9to you under the terms of the GNU General Public License version 2
10(the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php,
11with 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
22Not withstanding the above, under no circumstances may you combine
23this software in any way with any other Broadcom software provided
24under a license other than the GPL, without Broadcom's express prior
25written consent.
26
27:>
28*/
29
30#include <bcmolt_host_api.h>
31#include "bcmolt_user_appl_onu_tuning.h"
32#include "bcmolt_user_appl_onu_tuning_cli.h"
33#include <bcmolt_dev_selector.h>
34
35static bcmos_errno bcmolt_user_appl_onu_tuning_cli_create(bcmcli_entry *top_dir);
36
37static bcmcli_entry *onu_tuning_cli_dir;
38static bcmcli_entry *onu_tuning_cli_top_dir;
39static bcmos_bool onu_tuning_is_registered;
40
41/* Destroy CLI commands */
42static void onu_tuning_cli_destroy(void)
43{
44 if (onu_tuning_cli_dir)
45 {
46 bcmcli_token_destroy(onu_tuning_cli_dir);
47 onu_tuning_cli_dir = NULL;
48 }
49}
50
51/* Current device change indication */
52static void bcmolt_user_appl_onu_tuning_device_change_ind(bcmcli_session *session, bcmolt_devid dev)
53{
54 bcmolt_system_mode system_mode;
55 bcmos_errno err = bcmolt_system_mode_get(dev, &system_mode);
56
57 if (err != BCM_ERR_OK)
58 {
59 bcmcli_session_print(session, "Error device Id\n");
60 return;
61 }
62
63 if (system_mode == BCMOLT_SYSTEM_MODE_NGPON2__2_X_10_G)
64 {
65 bcmcli_session_print(session, "Building onu_tuning CLI for device %d\n", dev);
66
67 err = bcmolt_user_appl_onu_tuning_cli_create(onu_tuning_cli_top_dir);
68 if (err)
69 {
70 bcmcli_session_print(session, "Error building onu_tuning CLI\n");
71 }
72 }
73 else
74 {
75 onu_tuning_cli_destroy();
76 }
77}
78
79static bcmos_errno onu_tuning_cmd_start(bcmcli_session *session, const bcmcli_cmd_parm parms[], uint16_t n_parms)
80{
81 return bcmolt_onu_tuning_appl_start(current_device);
82}
83
84static bcmos_errno onu_tuning_cmd_stop(bcmcli_session *session, const bcmcli_cmd_parm parms[], uint16_t n_parms)
85{
86 return bcmolt_onu_tuning_appl_stop(current_device);
87}
88
89static bcmos_errno onu_handover_cmd(bcmcli_session *session, const bcmcli_cmd_parm parms[], uint16_t n_parms)
90{
91 bcmolt_xgpon_onu_id onu_id;
92 bcmolt_pon_ni target_pon_ni;
93 bcmolt_pon_ni source_pon_ni;
94 uint32_t target_pon_administrative_label;
95 uint8_t target_pon_dwlch_id;
96 uint32_t time_to_switch; /* Time to switch in ms */
97 bcmcli_cmd_parm *rollback_parm = bcmcli_find_named_parm(session, "rollback");
98 bcmos_bool rollback;
99 bcmos_errno rc = BCM_ERR_OK;
100 bcmolt_pon_id target_pon_id;
101
102
103 source_pon_ni = (bcmolt_pon_ni)bcmcli_find_named_parm(session, "source_pon_ni")->value.unumber;
104 target_pon_ni = (bcmolt_pon_ni)bcmcli_find_named_parm(session, "target_pon_ni")->value.unumber;
105 onu_id = (bcmolt_pon_onu_id)bcmcli_find_named_parm(session, "onu")->value.unumber;
106 target_pon_administrative_label = (uint32_t)bcmcli_find_named_parm(session, "target_pon_id_administrative_label")->value.unumber;
107 target_pon_dwlch_id = (uint8_t)bcmcli_find_named_parm(session, "target_pon_id_dwlch_id")->value.unumber;
108 target_pon_id.administrative_label = target_pon_administrative_label;
109 target_pon_id.dwlch_id = target_pon_dwlch_id;
110 time_to_switch = (uint32_t)bcmcli_find_named_parm(session, "time_to_switch")->value.unumber;
111
112 if (rollback_parm->value.unumber == 0)
113 rollback = BCMOS_FALSE;
114 else
115 rollback = BCMOS_TRUE;
116 /* update tuning in parameters in data base */
117 onu_tuning_update_onu_db(current_device, onu_id, source_pon_ni, target_pon_ni, target_pon_id, rollback);
118
119 bcmcli_session_print(session, "Tuning out ONU=%u source_pon_ni=%u target_pon_ni=%u \n", onu_id, source_pon_ni, target_pon_ni);
120
121 /* start tuning out onu on source pon id */
122 bcmolt_xgpon_onu_key key = { .pon_ni = source_pon_ni, .onu_id = onu_id };
123 bcmolt_xgpon_onu_onu_tuning_out onu_tuning_out;
124
125 BCMOLT_OPER_INIT(&onu_tuning_out, xgpon_onu, onu_tuning_out, key);
126 BCMOLT_OPER_PROP_SET(&onu_tuning_out, xgpon_onu, onu_tuning_out, target_ds_pon_id, target_pon_id);
127 BCMOLT_OPER_PROP_SET(&onu_tuning_out, xgpon_onu, onu_tuning_out, target_us_pon_id, target_pon_id);
128 BCMOLT_OPER_PROP_SET(&onu_tuning_out, xgpon_onu, onu_tuning_out, time_to_switch, time_to_switch);
129 BCMOLT_OPER_PROP_SET(&onu_tuning_out, xgpon_onu, onu_tuning_out, rollback, BCMOS_TRUE);
130 BCMOLT_OPER_PROP_SET(&onu_tuning_out, xgpon_onu, onu_tuning_out, status, BCMOLT_STATUS_ON);
131 rc = bcmolt_oper_submit(current_device, &onu_tuning_out.hdr);
132 if (rc != BCM_ERR_OK)
133 bcmcli_session_print(session, "ONU=%u tuning out from PON=%u failed\n", onu_id, source_pon_ni);
134
135 return BCM_ERR_OK;
136}
137
138bcmos_errno bcmolt_user_appl_onu_tuning_cli_init(bcmcli_entry *top_dir)
139{
140 bcmos_errno err = BCM_ERR_OK;
141
142 /* Subscribe for device change indication */
143 if (!onu_tuning_is_registered)
144 {
145 onu_tuning_is_registered = BCMOS_TRUE;
146
147 err = bcmolt_dev_sel_ind_register(bcmolt_user_appl_onu_tuning_device_change_ind);
148 }
149 return err ? err : bcmolt_user_appl_onu_tuning_cli_create(top_dir);
150}
151
152static bcmos_errno bcmolt_user_appl_onu_tuning_cli_create(bcmcli_entry *top_dir)
153{
154 bcmcli_entry *dir;
155
156 if (bcmcli_dir_find(top_dir, "onu_tuning"))
157 {
158 return BCM_ERR_OK;
159 }
160
161 dir = bcmcli_dir_add(
162 top_dir,
163 "onu_tuning",
164 "NGPON2 ONU tuning user application",
165 BCMCLI_ACCESS_ADMIN,
166 NULL);
167 BCMOS_CHECK_RETURN_ERROR(!dir, BCM_ERR_NOMEM);
168
169 BCMCLI_MAKE_CMD_NOPARM(dir, "start", "Start ONU tuning application", onu_tuning_cmd_start);
170
171 BCMCLI_MAKE_CMD_NOPARM(dir, "stop", "Stop ONU tuning application", onu_tuning_cmd_stop);
172
173 BCMCLI_MAKE_CMD(dir, "onu_handover", "ONU handover", onu_handover_cmd,
174 BCMCLI_MAKE_PARM("onu", "ONU ID", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_NONE),
175 BCMCLI_MAKE_PARM("source_pon_ni", "Source PON_NI", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_NONE),
176 BCMCLI_MAKE_PARM("target_pon_ni", "Target PON_NI", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_NONE),
177 BCMCLI_MAKE_PARM("target_pon_id_administrative_label", "Target PON ID Administrative label", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_NONE),
178 BCMCLI_MAKE_PARM("target_pon_id_dwlch_id", "Target PON ID Channel id", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_NONE),
179 BCMCLI_MAKE_PARM("time_to_switch", "Time_To_Switch", BCMCLI_PARM_NUMBER, BCMCLI_PARM_FLAG_NONE),
180 BCMCLI_MAKE_PARM_ENUM("rollback", "Rollback", bcmcli_enum_bool_table, BCMCLI_PARM_FLAG_OPTIONAL));
181
182
183 onu_tuning_cli_dir = dir;
184 onu_tuning_cli_top_dir = top_dir;
185
186 return BCM_ERR_OK;
187}