Rajeswara Rao | f6b4e6c | 2017-08-31 17:26:27 +0530 | [diff] [blame] | 1 | /* |
| 2 | ** Copyright 2017-present Open Networking Foundation |
| 3 | ** |
| 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | ** you may not use this file except in compliance with the License. |
| 6 | ** You may obtain a copy of the License at |
| 7 | ** |
| 8 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | ** |
| 10 | ** Unless required by applicable law or agreed to in writing, software |
| 11 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | ** See the License for the specific language governing permissions and |
| 14 | ** limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <stdio.h> |
| 18 | #include <bal_api.h> |
| 19 | |
| 20 | #undef _SYS_QUEUE_H_ |
| 21 | |
| 22 | #include "asfvolt16_driver.h" |
| 23 | #include "bal_interface_hdlr.h" |
| 24 | |
| 25 | /********************************************************************\ |
| 26 | * Function : bal_interface_cfg_set * |
| 27 | * Description : Configures the PON and NNI interfaces * |
| 28 | * of OLT Device * |
| 29 | ********************************************************************/ |
| 30 | uint32_t bal_interface_cfg_set(BalInterfaceCfg *interface_cfg) |
| 31 | { |
| 32 | bcmos_errno err = BCM_ERR_OK; |
| 33 | bcmbal_interface_cfg interface_obj; |
| 34 | bcmbal_interface_key intf_key; |
| 35 | |
| 36 | intf_key.intf_id = interface_cfg->key->intf_id; |
| 37 | intf_key.intf_type = interface_cfg->key->intf_type; |
| 38 | |
| 39 | |
| 40 | /* |
| 41 | * Set the key in the interface object and initialize the object itself |
| 42 | */ |
| 43 | BCMBAL_CFG_INIT(&interface_obj, interface, intf_key); |
| 44 | |
| 45 | bcmbal_cfg_get(DEFAULT_ATERM_ID, &(interface_obj.hdr)); |
| 46 | |
| 47 | if(BCMBAL_STATUS_UP != ((bcmbal_interface_cfg *)&interface_obj.hdr)->data.oper_status) |
| 48 | { |
| 49 | BCMBAL_CFG_INIT(&interface_obj, interface, intf_key); |
| 50 | |
| 51 | ASFVOLT_CFG_PROP_SET(interface_obj, interface, admin_state, BCMOS_TRUE, BCMBAL_STATE_UP); |
| 52 | |
| 53 | ASFVOLT_CFG_PROP_SET(interface_obj, interface, min_data_agg_port_id, |
| 54 | interface_cfg->data->has_min_data_svc_port_id, |
| 55 | interface_cfg->data->min_data_agg_port_id); |
| 56 | |
| 57 | ASFVOLT_CFG_PROP_SET(interface_obj, interface, min_data_svc_port_id, |
| 58 | interface_cfg->data->has_min_data_svc_port_id, |
| 59 | interface_cfg->data->min_data_svc_port_id); |
| 60 | |
| 61 | ASFVOLT_CFG_PROP_SET(interface_obj, interface, transceiver_type, |
| 62 | BCMOS_TRUE, |
| 63 | interface_cfg->data->transceiver_type); |
| 64 | ASFVOLT_LOG(ASFVOLT_INFO, "Setting transceiver_type to : %d\n", interface_cfg->data->transceiver_type); |
| 65 | |
| 66 | ASFVOLT_CFG_PROP_SET(interface_obj, interface, ds_miss_mode, |
| 67 | interface_cfg->data->has_ds_miss_mode, |
| 68 | interface_cfg->data->ds_miss_mode); |
| 69 | |
| 70 | ASFVOLT_CFG_PROP_SET(interface_obj, interface, mtu, |
| 71 | interface_cfg->data->has_mtu, |
| 72 | interface_cfg->data->mtu); |
| 73 | |
| 74 | ASFVOLT_CFG_PROP_SET(interface_obj, interface, flow_control, |
| 75 | interface_cfg->data->has_flow_control, |
| 76 | interface_cfg->data->flow_control); |
| 77 | |
| 78 | ASFVOLT_CFG_PROP_SET(interface_obj, interface, ds_tm, |
| 79 | interface_cfg->data->has_ds_tm, |
| 80 | interface_cfg->data->ds_tm); |
| 81 | |
| 82 | ASFVOLT_CFG_PROP_SET(interface_obj, interface, us_tm, |
| 83 | interface_cfg->data->has_us_tm, |
| 84 | interface_cfg->data->us_tm); |
| 85 | |
| 86 | ASFVOLT_LOG(ASFVOLT_INFO, "Bringing up the interface No: %d\n", intf_key.intf_id); |
| 87 | |
| 88 | err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr)); |
| 89 | |
| 90 | if(BCM_ERR_OK != err) |
| 91 | { |
| 92 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the interface object to ADMIN-UP\n"); |
| 93 | return BAL_ERRNO__BAL_ERR_INTERNAL; |
| 94 | } |
| 95 | } |
| 96 | ASFVOLT_LOG(ASFVOLT_DEBUG, "\n Set Interface configuration sent to OLT.Interface ID(%d) Interface Type(%d)\n", |
| 97 | intf_key.intf_id, intf_key.intf_type); |
| 98 | return BAL_ERRNO__BAL_ERR_OK; |
| 99 | } |
| 100 | |
| 101 | |
| 102 | /********************************************************************\ |
| 103 | * Function : bal_interface_cfg_get * |
| 104 | * Description : get the PON and NNI interfaces * |
| 105 | * of OLT Device * |
| 106 | ********************************************************************/ |
| 107 | uint32_t bal_interface_cfg_get(BalInterfaceKey *interface_cfg_key, |
| 108 | BalInterfaceCfg *interface_cfg) |
| 109 | { |
| 110 | bcmos_errno err = BCM_ERR_OK; |
| 111 | bcmbal_interface_cfg interface_obj; |
| 112 | bcmbal_interface_key intf_key; |
| 113 | |
| 114 | if((interface_cfg_key->has_intf_id) && (interface_cfg_key->has_intf_type)) |
| 115 | { |
| 116 | intf_key.intf_id = interface_cfg_key->intf_id; |
| 117 | intf_key.intf_type = interface_cfg_key->intf_type; |
| 118 | } |
| 119 | else |
| 120 | { |
| 121 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to get the interface cfg(OLT): Missing Key values\ |
| 122 | Recevied key values intf-id(%d), intf-type(%d) \n", |
| 123 | interface_cfg_key->intf_id, interface_cfg_key->intf_type); |
| 124 | return BAL_ERRNO__BAL_ERR_NOENT; |
| 125 | } |
| 126 | |
| 127 | ASFVOLT_LOG(ASFVOLT_DEBUG, "Get interface cfg(for OLT) starts\n"); |
| 128 | /* |
| 129 | * Set the key in the interface object and initialize the object itself |
| 130 | */ |
| 131 | BCMBAL_CFG_INIT(&interface_obj, interface, intf_key); |
| 132 | |
| 133 | /* request all properties, include everything */ |
| 134 | BCMBAL_CFG_PROP_GET(&interface_obj, interface, all_properties); |
| 135 | |
| 136 | err = bcmbal_cfg_get(DEFAULT_ATERM_ID, &interface_obj.hdr); |
| 137 | |
| 138 | if(BCM_ERR_OK != err) |
| 139 | { |
| 140 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to get the interface Cfg(OLT)\n"); |
| 141 | return BAL_ERRNO__BAL_ERR_INTERNAL; |
| 142 | } |
| 143 | |
| 144 | ASFVOLT_LOG(ASFVOLT_INFO, "\nGet Interface cfg sent to OLT. \ |
| 145 | Interface ID(%d) Interface Type(%d)\n", |
| 146 | intf_key.intf_id, intf_key.intf_type); |
| 147 | /* TODO - Add code to call grpc */ |
| 148 | |
| 149 | return BAL_ERRNO__BAL_ERR_OK; |
| 150 | } |
| 151 | |
| 152 | |
| 153 | /********************************************************************\ |
| 154 | * Function : bal_interface_cfg_clear * |
| 155 | * Description : Clears the PON and NNI interfaces * |
| 156 | * of OLT Device * |
| 157 | ********************************************************************/ |
| 158 | uint32_t bal_interface_cfg_clear(BalInterfaceKey *interface_cfg_key) |
| 159 | { |
| 160 | bcmos_errno err = BCM_ERR_OK; |
| 161 | bcmbal_interface_cfg interface_obj; |
| 162 | bcmbal_interface_key intf_key; |
| 163 | |
| 164 | if((interface_cfg_key->has_intf_id) && (interface_cfg_key->has_intf_type)) |
| 165 | { |
| 166 | intf_key.intf_id = interface_cfg_key->intf_id; |
| 167 | intf_key.intf_type = interface_cfg_key->intf_type; |
| 168 | } |
| 169 | else |
| 170 | { |
| 171 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to clear the interface cfg(OLT): Missing Key values\ |
| 172 | Recevied key values intf-id(%d), intf-type(%d) \n", |
| 173 | interface_cfg_key->intf_id, interface_cfg_key->intf_type); |
| 174 | return BAL_ERRNO__BAL_ERR_NOENT; |
| 175 | } |
| 176 | |
| 177 | |
| 178 | ASFVOLT_LOG(ASFVOLT_DEBUG, "Clearing of OLT(interface cfg) starts\n"); |
| 179 | /* |
| 180 | * Set the key in the interface object and initialize the object itself |
| 181 | */ |
| 182 | BCMBAL_CFG_INIT(&interface_obj, interface, intf_key); |
| 183 | |
| 184 | err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &interface_obj.hdr); |
| 185 | |
| 186 | if(BCM_ERR_OK != err) |
| 187 | { |
| 188 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to clear the interface Cfg(OLT)\n"); |
| 189 | return BAL_ERRNO__BAL_ERR_INTERNAL; |
| 190 | } |
| 191 | |
| 192 | ASFVOLT_LOG(ASFVOLT_INFO, "\nClear Interface cfg sent to OLT. \ |
| 193 | Interface ID(%d) Interface Type(%d)\n", |
| 194 | intf_key.intf_id, intf_key.intf_type); |
| 195 | return BAL_ERRNO__BAL_ERR_OK; |
| 196 | } |