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 <bcmolt_api.h> |
| 32 | #include <bcmolt_model_types.h> |
| 33 | #include <bcm_dev_log.h> |
| 34 | #include <bcmos_common.h> |
| 35 | #include "bcmolt_user_appl_ps.h" |
| 36 | #include "bcmolt_user_appl_ps_internal.h" |
| 37 | |
| 38 | |
| 39 | static bcmos_errno ps_handle_ni_no_reports(bcmolt_ps_global_cfg * global_cfg, const bcmolt_ps_pon *pon, const bcmolt_epon_ni_no_reports * ind) |
| 40 | { |
| 41 | if (ind->data.alarm_status == BCMOLT_STATUS_OFF) |
| 42 | { |
| 43 | PS_INFO("<%d:%d> LoS alarm cleared\n", pon->device_id, pon->pon_id); |
| 44 | return BCM_ERR_OK; |
| 45 | } |
| 46 | |
| 47 | PS_INFO("<%d:%d> LoS alarm raised\n", pon->device_id, pon->pon_id); |
| 48 | |
| 49 | if (global_cfg->switch_condition == BCMOLT_PS_SWITCH_CONDITION_MANUAL) |
| 50 | { |
| 51 | /* don't react to the switch if we're in manual switch mode */ |
| 52 | return BCM_ERR_OK; |
| 53 | } |
| 54 | else |
| 55 | { |
| 56 | return bcmolt_ps_switch_perform(pon); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | static bcmos_errno ps_handle_logical_link_discovered(bcmolt_ps_global_cfg * global_cfg, const bcmolt_ps_pon *pon, const bcmolt_epon_link_mpcp_discovered * ind) |
| 61 | { |
| 62 | bcmolt_ps_pon_state state; |
| 63 | bcmolt_ps_pon partner; |
| 64 | bcmos_errno result; |
| 65 | |
| 66 | if (global_cfg->mirror_mode != BCMOLT_PS_MIRROR_MODE_AUTO) |
| 67 | { |
| 68 | return BCM_ERR_OK; |
| 69 | } |
| 70 | |
| 71 | //At this point we know we have a link discovered on a PON that is in the PROTECTED WORKING state. |
| 72 | //This means we want to make sure that is is setup on the PROCTECTED STANDBY PON. It is possible |
| 73 | //That this link has been previously configured on the STANDBY PON so we have to handle that case |
| 74 | //gracefully as well. |
| 75 | result = bcmolt_ps_pon_state_get(pon, &state, &partner); |
| 76 | PS_INFO("pon %d, bcmolt_ps_pon_state_get result == %d, state == %d, partner.pon_id == %d\n", pon->pon_id, result, state, partner.pon_id); |
| 77 | if ((BCM_ERR_OK == result) && (state == BCMOLT_PS_PON_STATE_WORKING)) |
| 78 | { |
| 79 | bcmolt_epon_ni_add_protected_standby_link add_standby = {}; |
| 80 | bcmolt_epon_ni_key key = {}; |
| 81 | PS_INFO("Mirroring received link discovered on working PON\n"); |
| 82 | |
| 83 | key.epon_ni = (bcmolt_epon_ni)partner.pon_id; //Setup the standby PON as the location to add the link. |
| 84 | |
| 85 | //Setup operation key for api call. |
| 86 | BCMOLT_OPER_INIT(&add_standby, epon_ni, add_protected_standby_link, key); |
| 87 | |
| 88 | //Copy over the data from the received messages: |
| 89 | BCMOLT_OPER_PROP_SET(&add_standby, epon_ni, add_protected_standby_link, mac_address, ind->key.mac_address); |
| 90 | BCMOLT_OPER_PROP_SET(&add_standby, epon_ni, add_protected_standby_link, working_link_info, ind->data.link_info); |
| 91 | |
| 92 | result = bcmolt_oper_submit(partner.device_id, &add_standby.hdr); |
| 93 | |
| 94 | //We have multiple acceptable return codes here: |
| 95 | // BCM_ERR_OK - Indicates new entry created. |
| 96 | // BCM_ERR_ALREADY - Indicates the entry already exists (possible after deregistration/reregistration). |
| 97 | PS_INFO("Mirroring add protected standby link result %d\n", result); |
| 98 | |
| 99 | if ( (result == BCM_ERR_OK) || (result == BCM_ERR_ALREADY) ) |
| 100 | { |
| 101 | bcmolt_epon_link_static_registration static_reg = {}; |
| 102 | bcmolt_epon_link_key link_key = {}; |
| 103 | |
| 104 | link_key.epon_ni = (bcmolt_epon_ni)partner.pon_id; |
| 105 | link_key.mac_address = ind->key.mac_address; |
| 106 | |
| 107 | //Setup operation key for api call. |
| 108 | BCMOLT_OPER_INIT(&static_reg, epon_link, static_registration, link_key); |
| 109 | BCMOLT_OPER_PROP_SET(&static_reg, epon_link, static_registration, laseron_time_tq, ind->data.link_info.onu_laser_on_time_tq); |
| 110 | BCMOLT_OPER_PROP_SET(&static_reg, epon_link, static_registration, laseroff_time_tq, ind->data.link_info.onu_laser_off_time_tq); |
| 111 | BCMOLT_OPER_PROP_SET(&static_reg, epon_link, static_registration, range_value_tq, ind->data.link_info.range_value_tq); |
| 112 | BCMOLT_OPER_PROP_SET(&static_reg, epon_link, static_registration, pending_grants, ind->data.link_info.pending_grants); |
| 113 | result = bcmolt_oper_submit(partner.device_id, &static_reg.hdr); |
| 114 | if (result != BCM_ERR_OK) |
| 115 | { |
| 116 | PS_ERR("Static registration failed %d\n", result); |
| 117 | } |
| 118 | else |
| 119 | { |
| 120 | PS_INFO("Static registration success\n"); |
| 121 | } |
| 122 | } |
| 123 | else |
| 124 | { |
| 125 | PS_ERR("Add protected standby failed %d\n", result); |
| 126 | } |
| 127 | } |
| 128 | return BCM_ERR_OK; |
| 129 | } |
| 130 | |
| 131 | bcmos_errno ps_process_ind_epon(const bcmolt_ps_pon *pon, const bcmolt_auto *ind) |
| 132 | { |
| 133 | bcmos_errno err; |
| 134 | bcmolt_ps_global_cfg global_cfg; |
| 135 | |
| 136 | err = bcmolt_ps_global_cfg_get(&global_cfg); |
| 137 | if (err != BCM_ERR_OK) |
| 138 | { |
| 139 | return err; |
| 140 | } |
| 141 | |
| 142 | PS_INFO("ps_process_ind_epon Type: %d CFG_ID: %d\n", ind->hdr.obj_type, ind->hdr.subgroup); |
| 143 | switch (ind->hdr.obj_type) |
| 144 | { |
| 145 | case BCMOLT_OBJ_ID_EPON_NI: |
| 146 | switch (ind->hdr.subgroup) |
| 147 | { |
| 148 | case BCMOLT_EPON_NI_AUTO_CFG_ID_NO_REPORTS: |
| 149 | return ps_handle_ni_no_reports(&global_cfg, pon, ((const bcmolt_epon_ni_no_reports *)ind)); |
| 150 | default: |
| 151 | return BCM_ERR_OK; |
| 152 | } |
| 153 | case BCMOLT_OBJ_ID_EPON_LINK: |
| 154 | switch (ind->hdr.subgroup) |
| 155 | { |
| 156 | case BCMOLT_EPON_LINK_AUTO_CFG_ID_MPCP_DISCOVERED: |
| 157 | return ps_handle_logical_link_discovered(&global_cfg, pon, ((const bcmolt_epon_link_mpcp_discovered *)ind)); |
| 158 | default: |
| 159 | return BCM_ERR_OK; |
| 160 | } |
| 161 | default: |
| 162 | return BCM_ERR_OK; |
| 163 | } |
| 164 | |
| 165 | return BCM_ERR_OK; |
| 166 | } |
| 167 | |
| 168 | bcmos_errno ps_move_to_standby_epon(const bcmolt_ps_pon *pon) |
| 169 | { |
| 170 | bcmolt_epon_ni_set_epon_ni_en_state set_pon_state; |
| 171 | bcmolt_epon_ni_key key = {}; |
| 172 | key.epon_ni = pon->pon_id; |
| 173 | |
| 174 | BCMOLT_OPER_INIT(&set_pon_state, epon_ni, set_epon_ni_en_state, key); |
| 175 | BCMOLT_OPER_PROP_SET(&set_pon_state, epon_ni, set_epon_ni_en_state, new_state, BCMOLT_EPON_NI_EN_STATE_PROTECTED_STANDBY); |
| 176 | return bcmolt_oper_submit(pon->device_id, &set_pon_state.hdr); |
| 177 | } |
| 178 | |
| 179 | bcmos_errno ps_move_to_working_epon(const bcmolt_ps_pon *pon) |
| 180 | { |
| 181 | bcmolt_epon_ni_set_epon_ni_en_state set_pon_state; |
| 182 | bcmolt_epon_ni_key key = {}; |
| 183 | key.epon_ni = pon->pon_id; |
| 184 | |
| 185 | BCMOLT_OPER_INIT(&set_pon_state, epon_ni, set_epon_ni_en_state, key); |
| 186 | BCMOLT_OPER_PROP_SET(&set_pon_state, epon_ni, set_epon_ni_en_state, new_state, BCMOLT_EPON_NI_EN_STATE_PROTECTED_WORKING); |
| 187 | return bcmolt_oper_submit(pon->device_id, &set_pon_state.hdr); |
| 188 | } |