blob: ba8eaa609303377bb9745d8a80535cf4c4723c5a [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
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 "bcmolt_math.h"
32#include "bcm_dev_log.h"
33#include "bcmolt_api.h"
34#include "bcmolt_model_types.h"
35#include "bcmolt_user_appl_epon_oam.h"
36#include "bcmolt_user_appl_epon_oam_cli.h"
37#include "bcmolt_epon_oam_types.h"
38
39static bcmos_errno epon_oam_dpoe_get_critical_info_cli(bcmcli_session *session,
40 const bcmcli_cmd_parm parm[],
41 uint16_t n_parms)
42{
43 bcmolt_epon_ni epon = (bcmolt_epon_ni)bcmcli_find_named_parm(session, "epon_ni")->value.unumber;
44 bcmos_mac_address mac = bcmcli_find_named_parm(session, "mac_address")->value.mac;
45
46 return epon_oam_dpoe_get_critical_info(current_device, epon, &mac);
47}
48
49static bcmos_errno epon_oam_dpoe_set_oam_rate_cli(bcmcli_session *session,
50 const bcmcli_cmd_parm parm[],
51 uint16_t n_parms)
52{
53 bcmolt_epon_ni epon = (bcmolt_epon_ni)bcmcli_find_named_parm(session, "epon_ni")->value.unumber;
54 bcmos_mac_address mac = bcmcli_find_named_parm(session, "mac_address")->value.mac;
55 uint8_t min = (uint8_t)bcmcli_find_named_parm(session, "min")->value.unumber;
56 uint8_t max = (uint8_t)bcmcli_find_named_parm(session, "max")->value.unumber;
57
58 return epon_oam_dpoe_set_oam_rate(current_device, epon, &mac, min, max);
59}
60
61static bcmos_errno epon_oam_dpoe_set_report_thresholds_cli(bcmcli_session *session,
62 const bcmcli_cmd_parm parm[],
63 uint16_t n_parms)
64{
65 bcmolt_epon_ni epon = (bcmolt_epon_ni)bcmcli_find_named_parm(session, "epon_ni")->value.unumber;
66 bcmos_mac_address mac = bcmcli_find_named_parm(session, "mac_address")->value.mac;
67 bcmcli_cmd_parm *queue_set_parms[MAX_QUEUE_SETS];
68
69 /* OAM stuff */
70 bcmolt_epon_oam_queue_sets queue_sets;
71 uint8_t i, j, num_queue_sets = 0;
72
73 /* process input */
74 queue_set_parms[0] = bcmcli_find_named_parm(session, "queue_0");
75 queue_set_parms[1] = bcmcli_find_named_parm(session, "queue_1");
76 queue_set_parms[2] = bcmcli_find_named_parm(session, "queue_2");
77 queue_set_parms[3] = bcmcli_find_named_parm(session, "queue_3");
78 for (i = 0; i < MAX_QUEUE_SETS; i++)
79 {
80 if (NULL != queue_set_parms[i])
81 {
82 num_queue_sets++;
83 if (queue_set_parms[i]->array_size != queue_set_parms[0]->array_size)
84 {
85 bcmcli_session_print(session, "All queue sets must have the same number of report thresholds!\n");
86 return BCM_ERR_PARM;
87 }
88 for (j = 0; j < queue_set_parms[i]->array_size; j++)
89 {
90 if (queue_set_parms[i]->values[j].unumber > 65535)
91 {
92 bcmcli_session_print(session, "Queue Set %u, Threshold %u: %lu is not a valid report threshold!\n",
93 i, j, queue_set_parms[i]->values[j].unumber);
94 return BCM_ERR_PARM;
95 }
96 queue_sets[i][j] = (uint16_t)queue_set_parms[i]->values[j].unumber;
97 }
98 }
99 else
100 {
101 for (j = i + 1; j < MAX_QUEUE_SETS; j++)
102 {
103 if (NULL != queue_set_parms[j])
104 {
105 bcmcli_session_print(session, "Included queue sets must be sequential from 0!\n");
106 return BCM_ERR_PARM;
107 }
108 }
109 }
110 }
111
112 return epon_oam_dpoe_set_report_thresholds(current_device,
113 epon,
114 &mac,
115 queue_set_parms[0]->array_size,
116 queue_sets,
117 num_queue_sets);
118}
119
120static bcmos_errno epon_oam_dpoe_clear_ingress_rules_network_pon_cli(bcmcli_session *session,
121 const bcmcli_cmd_parm parm[],
122 uint16_t n_parms)
123{
124 bcmolt_epon_ni epon = (bcmolt_epon_ni)bcmcli_find_named_parm(session, "epon_ni")->value.unumber;
125 bcmos_mac_address mac = bcmcli_find_named_parm(session, "mac_address")->value.mac;
126
127 return epon_oam_dpoe_clear_ingress_rules_network_pon(current_device, epon, &mac);
128}
129
130static bcmos_errno epon_oam_dpoe_clear_ingress_rules_user_port_cli(bcmcli_session *session,
131 const bcmcli_cmd_parm parm[],
132 uint16_t n_parms)
133{
134 bcmolt_epon_ni epon = (bcmolt_epon_ni)bcmcli_find_named_parm(session, "epon_ni")->value.unumber;
135 bcmos_mac_address mac = bcmcli_find_named_parm(session, "mac_address")->value.mac;
136
137 return epon_oam_dpoe_clear_ingress_rules_user_port(current_device, epon, &mac);
138}
139
140static bcmos_errno epon_oam_dpoe_clear_ingress_rules_cli(bcmcli_session *session,
141 const bcmcli_cmd_parm parm[],
142 uint16_t n_parms)
143{
144 bcmolt_epon_ni epon = (bcmolt_epon_ni)bcmcli_find_named_parm(session, "epon_ni")->value.unumber;
145 bcmos_mac_address mac = bcmcli_find_named_parm(session, "mac_address")->value.mac;
146
147 return epon_oam_dpoe_clear_ingress_rules(current_device, epon, &mac);
148}
149
150static bcmos_errno epon_oam_dpoe_set_basic_queue_config_cli(bcmcli_session *session,
151 const bcmcli_cmd_parm parm[],
152 uint16_t n_parms)
153{
154 bcmolt_epon_ni epon = (bcmolt_epon_ni)bcmcli_find_named_parm(session, "epon_ni")->value.unumber;
155 bcmos_mac_address mac = bcmcli_find_named_parm(session, "mac_address")->value.mac;
156 uint8_t up_queue_size = (uint8_t)bcmcli_find_named_parm(session, "up_size")->value.unumber;
157 uint8_t dn_queue_size = (uint8_t)bcmcli_find_named_parm(session, "dn_size")->value.unumber;
158
159 return epon_oam_dpoe_set_basic_queue_config(current_device, epon, &mac, up_queue_size, dn_queue_size);
160}
161
162static bcmos_errno epon_oam_dpoe_add_ingress_rules_network_pon_cli(bcmcli_session *session,
163 const bcmcli_cmd_parm parm[],
164 uint16_t n_parms)
165{
166 bcmolt_epon_ni epon = (bcmolt_epon_ni)bcmcli_find_named_parm(session, "epon_ni")->value.unumber;
167 bcmos_mac_address mac = bcmcli_find_named_parm(session, "mac_address")->value.mac;
168
169 return epon_oam_dpoe_add_ingress_rules_network_pon(current_device, epon, &mac, DPOE_RULE_VLAN_MODE_NONE, NULL);
170}
171
172static bcmos_errno epon_oam_dpoe_add_ingress_rules_user_port_cli(bcmcli_session *session,
173 const bcmcli_cmd_parm parm[],
174 uint16_t n_parms)
175{
176 bcmolt_epon_ni epon = (bcmolt_epon_ni)bcmcli_find_named_parm(session, "epon_ni")->value.unumber;
177 bcmos_mac_address mac = bcmcli_find_named_parm(session, "mac_address")->value.mac;
178
179 return epon_oam_dpoe_add_ingress_rules_user_port(current_device, epon, &mac, DPOE_RULE_VLAN_MODE_NONE, NULL);
180}
181
182static bcmos_errno epon_oam_dpoe_add_ingress_rules_cli(bcmcli_session *session,
183 const bcmcli_cmd_parm parm[],
184 uint16_t n_parms)
185{
186 bcmolt_epon_ni epon = (bcmolt_epon_ni)bcmcli_find_named_parm(session, "epon_ni")->value.unumber;
187 bcmos_mac_address mac = bcmcli_find_named_parm(session, "mac_address")->value.mac;
188
189 return epon_oam_dpoe_add_ingress_rules(current_device, epon, &mac);
190}
191
192static bcmos_errno epon_oam_dpoe_add_ingress_rules_with_vlan_cli(bcmcli_session *session,
193 const bcmcli_cmd_parm parm[],
194 uint16_t n_parms)
195{
196 bcmolt_epon_ni epon = (bcmolt_epon_ni)bcmcli_find_named_parm(session, "epon_ni")->value.unumber;
197 bcmos_mac_address mac = bcmcli_find_named_parm(session, "mac_address")->value.mac;
198 uint32_t vlan = bcmcli_find_named_parm(session, "vlan")->value.unumber;
199 uint8_t vlan_tag[4];
200
201 vlan = BCMOS_ENDIAN_CPU_TO_BIG_U32(vlan);
202 vlan_tag[0] = (vlan >> 24) & 0xff;
203 vlan_tag[1] = (vlan >> 16) & 0xff;
204 vlan_tag[2] = (vlan >> 8) & 0xff;
205 vlan_tag[3] = (vlan >> 0) & 0xff;
206
207 return epon_oam_dpoe_add_ingress_rules_with_vlan(current_device, epon, &mac, vlan_tag);
208}
209
210static bcmos_errno epon_oam_dpoe_enable_user_traffic_cli(bcmcli_session *session,
211 const bcmcli_cmd_parm parm[],
212 uint16_t n_parms)
213{
214 bcmolt_epon_ni epon = (bcmolt_epon_ni)bcmcli_find_named_parm(session, "epon_ni")->value.unumber;
215 bcmos_mac_address mac = bcmcli_find_named_parm(session, "mac_address")->value.mac;
216
217 return epon_oam_dpoe_enable_user_traffic(current_device, epon, &mac);
218}
219
220static bcmos_errno epon_oam_dpoe_start_upgrade_cli(bcmcli_session *session,
221 const bcmcli_cmd_parm parm[],
222 uint16_t n_parms)
223{
224 bcmolt_epon_ni epon = (bcmolt_epon_ni)bcmcli_find_named_parm(session, "epon_ni")->value.unumber;
225 bcmos_mac_address mac = bcmcli_find_named_parm(session, "mac_address")->value.mac;
226 const char *fw_file = bcmcli_find_named_parm(session, "fw_file")->value.string;
227 /* This should be based on the negotiated PDU size! */
228 uint16_t block_size = (uint16_t)bcmcli_find_named_parm(session, "block_size")->value.unumber;
229 uint8_t timeout = (uint8_t)bcmcli_find_named_parm(session, "timeout")->value.unumber;
230
231 return epon_oam_dpoe_start_upgrade(current_device, epon, &mac, fw_file, block_size, timeout);
232}
233
234static bcmos_errno epon_oam_dpoe_reset_onu_cli(bcmcli_session *session,
235 const bcmcli_cmd_parm parm[],
236 uint16_t n_parms)
237{
238 bcmolt_epon_ni epon = (bcmolt_epon_ni)bcmcli_find_named_parm(session, "epon_ni")->value.unumber;
239 bcmos_mac_address mac = bcmcli_find_named_parm(session, "mac_address")->value.mac;
240
241 return epon_oam_dpoe_reset_onu(current_device, epon, &mac);
242}
243
244void bcmolt_user_appl_epon_oam_cli_init(bcmcli_entry *top_dir)
245{
246#ifdef ENABLE_CLI
247 static const char *dir_name = "epon_oam";
248
249 if (bcmcli_dir_find(top_dir, dir_name))
250 {
251 return;
252 }
253
254 bcmcli_entry *oam_dir = bcmcli_dir_add(top_dir, dir_name, "EPON OAM", BCMCLI_ACCESS_ADMIN, NULL);
255 BUG_ON(NULL == oam_dir);
256
257 static bcmcli_parm_value queue_0[MAX_REPORT_THRESHOLDS];
258 static bcmcli_parm_value queue_1[MAX_REPORT_THRESHOLDS];
259 static bcmcli_parm_value queue_2[MAX_REPORT_THRESHOLDS];
260 static bcmcli_parm_value queue_3[MAX_REPORT_THRESHOLDS];
261
262 BCMCLI_MAKE_CMD(oam_dir, "dpoe_get_critical_info", "DPoE get ONU ID and max links",
263 epon_oam_dpoe_get_critical_info_cli,
264 BCMCLI_MAKE_PARM("epon_ni", "EPON NI", BCMCLI_PARM_UNUMBER, 0),
265 BCMCLI_MAKE_PARM("mac_address", "link MAC", BCMCLI_PARM_MAC, 0));
266
267 BCMCLI_MAKE_CMD(oam_dir, "dpoe_set_oam_rate", "DPoE set OAM rate",
268 epon_oam_dpoe_set_oam_rate_cli,
269 BCMCLI_MAKE_PARM("epon_ni", "EPON NI", BCMCLI_PARM_UNUMBER, 0),
270 BCMCLI_MAKE_PARM("mac_address", "link MAC", BCMCLI_PARM_MAC, 0),
271 BCMCLI_MAKE_PARM("min", "Minimum OAM rate", BCMCLI_PARM_UNUMBER, 0),
272 BCMCLI_MAKE_PARM("max", "Maximum OAM rate", BCMCLI_PARM_UNUMBER, 0));
273
274 BCMCLI_MAKE_CMD(oam_dir, "dpoe_set_report_thresholds", "DPoE set report threhsolds",
275 epon_oam_dpoe_set_report_thresholds_cli,
276 BCMCLI_MAKE_PARM("epon_ni", "EPON NI", BCMCLI_PARM_UNUMBER, 0),
277 BCMCLI_MAKE_PARM("mac_address", "link MAC", BCMCLI_PARM_MAC, 0),
278 BCMCLI_MAKE_PARM_ARRAY("queue_0",
279 "Report threhsold for queue set 0",
280 BCMCLI_PARM_UNUMBER,
281 BCMCLI_PARM_FLAG_NONE,
282 MAX_REPORT_THRESHOLDS,
283 queue_0),
284 BCMCLI_MAKE_PARM_ARRAY("queue_1",
285 "Report threhsold for queue set 0",
286 BCMCLI_PARM_UNUMBER,
287 BCMCLI_PARM_FLAG_OPTIONAL,
288 MAX_REPORT_THRESHOLDS,
289 queue_1),
290 BCMCLI_MAKE_PARM_ARRAY("queue_2",
291 "Report threhsold for queue set 0",
292 BCMCLI_PARM_UNUMBER,
293 BCMCLI_PARM_FLAG_OPTIONAL,
294 MAX_REPORT_THRESHOLDS,
295 queue_2),
296 BCMCLI_MAKE_PARM_ARRAY("queue_3",
297 "Report threhsold for queue set 0",
298 BCMCLI_PARM_UNUMBER,
299 BCMCLI_PARM_FLAG_OPTIONAL,
300 MAX_REPORT_THRESHOLDS,
301 queue_3));
302
303 BCMCLI_MAKE_CMD(oam_dir, "dpoe_clear_ingress_rules_network_pon", "DPoE clear ingress rules for network PON",
304 epon_oam_dpoe_clear_ingress_rules_network_pon_cli,
305 BCMCLI_MAKE_PARM("epon_ni", "EPON NI", BCMCLI_PARM_UNUMBER, 0),
306 BCMCLI_MAKE_PARM("mac_address", "link MAC", BCMCLI_PARM_MAC, 0));
307 BCMCLI_MAKE_CMD(oam_dir, "dpoe_clear_ingress_rules_user_port", "DPoE clear ingress rules for user port",
308 epon_oam_dpoe_clear_ingress_rules_user_port_cli,
309 BCMCLI_MAKE_PARM("epon_ni", "EPON NI", BCMCLI_PARM_UNUMBER, 0),
310 BCMCLI_MAKE_PARM("mac_address", "link MAC", BCMCLI_PARM_MAC, 0));
311 BCMCLI_MAKE_CMD(oam_dir, "dpoe_clear_ingress_rules", "DPoE clear ingress rules",
312 epon_oam_dpoe_clear_ingress_rules_cli,
313 BCMCLI_MAKE_PARM("epon_ni", "EPON NI", BCMCLI_PARM_UNUMBER, 0),
314 BCMCLI_MAKE_PARM("mac_address", "link MAC", BCMCLI_PARM_MAC, 0));
315
316 BCMCLI_MAKE_CMD(oam_dir, "dpoe_set_basic_queue_config", "DPoE set basic queue config for 1 link/1 port",
317 epon_oam_dpoe_set_basic_queue_config_cli,
318 BCMCLI_MAKE_PARM("epon_ni", "EPON NI", BCMCLI_PARM_UNUMBER, 0),
319 BCMCLI_MAKE_PARM("mac_address", "link MAC", BCMCLI_PARM_MAC, 0),
320 BCMCLI_MAKE_PARM("up_size", "upstream queue size", BCMCLI_PARM_UNUMBER, 0),
321 BCMCLI_MAKE_PARM("dn_size", "downstream queue size", BCMCLI_PARM_UNUMBER, 0));
322
323 BCMCLI_MAKE_CMD(oam_dir, "dpoe_add_ingress_rules_network_pon", "DPoE add ingress rules for network PON",
324 epon_oam_dpoe_add_ingress_rules_network_pon_cli,
325 BCMCLI_MAKE_PARM("epon_ni", "EPON NI", BCMCLI_PARM_UNUMBER, 0),
326 BCMCLI_MAKE_PARM("mac_address", "link MAC", BCMCLI_PARM_MAC, 0));
327 BCMCLI_MAKE_CMD(oam_dir, "dpoe_add_ingress_rules_user_port", "DPoE add ingress rules for user port",
328 epon_oam_dpoe_add_ingress_rules_user_port_cli,
329 BCMCLI_MAKE_PARM("epon_ni", "EPON NI", BCMCLI_PARM_UNUMBER, 0),
330 BCMCLI_MAKE_PARM("mac_address", "link MAC", BCMCLI_PARM_MAC, 0));
331 BCMCLI_MAKE_CMD(oam_dir, "dpoe_add_ingress_rules", "DPoE add ingress rules",
332 epon_oam_dpoe_add_ingress_rules_cli,
333 BCMCLI_MAKE_PARM("epon_ni", "EPON NI", BCMCLI_PARM_UNUMBER, 0),
334 BCMCLI_MAKE_PARM("mac_address", "link MAC", BCMCLI_PARM_MAC, 0));
335 BCMCLI_MAKE_CMD(oam_dir, "dpoe_add_ingress_rules_with_vlan", "DPoE add ingress rules with VLAN",
336 epon_oam_dpoe_add_ingress_rules_with_vlan_cli,
337 BCMCLI_MAKE_PARM("epon_ni", "EPON NI", BCMCLI_PARM_UNUMBER, 0),
338 BCMCLI_MAKE_PARM("mac_address", "link MAC", BCMCLI_PARM_MAC, 0),
339 BCMCLI_MAKE_PARM("vlan", "VLAN", BCMCLI_PARM_UNUMBER, 0));
340
341 BCMCLI_MAKE_CMD(oam_dir, "dpoe_enable_user_traffic", "DPoE enable user traffic",
342 epon_oam_dpoe_enable_user_traffic_cli,
343 BCMCLI_MAKE_PARM("epon_ni", "EPON NI", BCMCLI_PARM_UNUMBER, 0),
344 BCMCLI_MAKE_PARM("mac_address", "link MAC", BCMCLI_PARM_MAC, 0));
345
346 BCMCLI_MAKE_CMD(oam_dir, "dpoe_fw_upgrade", "DPoE firwmare upgrade",
347 epon_oam_dpoe_start_upgrade_cli,
348 BCMCLI_MAKE_PARM("epon_ni", "EPON NI", BCMCLI_PARM_UNUMBER, 0),
349 BCMCLI_MAKE_PARM("mac_address", "link MAC", BCMCLI_PARM_MAC, 0),
350 BCMCLI_MAKE_PARM("fw_file", "Firmware file", BCMCLI_PARM_STRING, 0),
351 BCMCLI_MAKE_PARM("block_size", "Block size", BCMCLI_PARM_UNUMBER, 0),
352 BCMCLI_MAKE_PARM("timeout", "Timeout in seconds", BCMCLI_PARM_UNUMBER, 0));
353
354 BCMCLI_MAKE_CMD(oam_dir, "dpoe_reset_onu", "DPoE reset ONU",
355 epon_oam_dpoe_reset_onu_cli,
356 BCMCLI_MAKE_PARM("epon_ni", "EPON NI", BCMCLI_PARM_UNUMBER, 0),
357 BCMCLI_MAKE_PARM("mac_address", "link MAC", BCMCLI_PARM_MAC, 0));
358#endif
359}
360