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 | /* Includes related to proto buf */ |
| 23 | #include "asfvolt16_driver.h" |
| 24 | #include "bal_tmsched_hdlr.h" |
| 25 | |
| 26 | /********************************************************************\ |
| 27 | * Function : bal_tm_sched_cfg_set * |
| 28 | * Description : Configures the tm scheduler for OLT device * |
| 29 | ********************************************************************/ |
| 30 | |
| 31 | uint32_t bal_tm_sched_cfg_set(BalTmSchedCfg *tm_sched_cfg) |
| 32 | { |
| 33 | bcmos_errno err = BCM_ERR_OK; |
| 34 | bcmbal_tm_sched_cfg tm_sched_obj; /**< declare main API struct */ |
| 35 | bcmbal_tm_sched_key key = { }; /**< declare key */ |
| 36 | |
| 37 | if((tm_sched_cfg->key->has_dir) && (tm_sched_cfg->key->has_id)) |
| 38 | { |
| 39 | key.dir = tm_sched_cfg->key->dir; |
| 40 | key.id = tm_sched_cfg->key->id; |
| 41 | } |
| 42 | else |
| 43 | { |
| 44 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the tm schedule cfg(OLT): Missing Key values\ |
| 45 | Recevied key values Sched-Dir(%d), Sched-Id(%d) \n", |
| 46 | tm_sched_cfg->key->dir, tm_sched_cfg->key->id); |
| 47 | return BAL_ERRNO__BAL_ERR_NOENT; |
| 48 | } |
| 49 | |
| 50 | ASFVOLT_LOG(ASFVOLT_DEBUG, "Configuration of OLT(tm Sched) starts\n"); |
| 51 | /* init the API struct */ |
| 52 | BCMBAL_CFG_INIT(&tm_sched_obj, tm_sched, key); |
| 53 | |
| 54 | /* decode API parameters from GRPC */ |
| 55 | /* scheduler owner */ |
| 56 | BalTmSchedOwner *tmScOwn = (BalTmSchedOwner *)tm_sched_cfg->data->owner; |
| 57 | bcmbal_tm_sched_owner valtmScOwn = {}; |
| 58 | if(tmScOwn->has_type) |
| 59 | { |
| 60 | valtmScOwn.type = tmScOwn->type; |
| 61 | switch(valtmScOwn.type) |
| 62 | { |
| 63 | case BCMBAL_TM_SCHED_OWNER_TYPE_INTERFACE: |
| 64 | if(tmScOwn->interface->has_intf_type) |
| 65 | { |
| 66 | valtmScOwn.u.interface.intf_type = tmScOwn->interface->intf_type; |
| 67 | } |
| 68 | if(tmScOwn->interface->has_intf_id) |
| 69 | { |
| 70 | valtmScOwn.u.interface.intf_id = tmScOwn->interface->intf_id; |
| 71 | } |
| 72 | break; |
| 73 | case BCMBAL_TM_SCHED_OWNER_TYPE_SUB_TERM: |
| 74 | if(tmScOwn->sub_term->has_intf_id) |
| 75 | { |
| 76 | valtmScOwn.u.sub_term.intf_id = tmScOwn->sub_term->intf_id; |
| 77 | } |
| 78 | if(tmScOwn->sub_term->has_sub_term_id) |
| 79 | { |
| 80 | valtmScOwn.u.sub_term.sub_term_id = tmScOwn->sub_term->sub_term_id; |
| 81 | } |
| 82 | break; |
| 83 | case BCMBAL_TM_SCHED_OWNER_TYPE_AGG_PORT: |
| 84 | if(tmScOwn->agg_port->has_presence_mask) |
| 85 | { |
| 86 | valtmScOwn.u.agg_port.presence_mask = tmScOwn->agg_port->presence_mask; |
| 87 | if(tmScOwn->agg_port->has_intf_id) |
| 88 | { |
| 89 | valtmScOwn.u.agg_port.intf_id= tmScOwn->agg_port->intf_id; |
| 90 | } |
| 91 | if(tmScOwn->agg_port->has_sub_term_id) |
| 92 | { |
| 93 | valtmScOwn.u.agg_port.sub_term_id = tmScOwn->agg_port->sub_term_id; |
| 94 | } |
| 95 | if(tmScOwn->agg_port->has_agg_port_id) |
| 96 | { |
| 97 | valtmScOwn.u.agg_port.agg_port_id = tmScOwn->agg_port->agg_port_id; |
| 98 | } |
| 99 | } |
| 100 | break; |
| 101 | case BCMBAL_TM_SCHED_OWNER_TYPE_UNI: |
| 102 | if(tmScOwn->uni->has_intf_id) |
| 103 | { |
| 104 | valtmScOwn.u.uni.intf_id = tmScOwn->uni->intf_id; |
| 105 | } |
| 106 | if(tmScOwn->uni->has_sub_term_id) |
| 107 | { |
| 108 | valtmScOwn.u.uni.sub_term_id = tmScOwn->uni->sub_term_id; |
| 109 | } |
| 110 | if(tmScOwn->uni->has_idx) |
| 111 | { |
| 112 | valtmScOwn.u.uni.idx = tmScOwn->uni->idx; |
| 113 | } |
| 114 | break; |
| 115 | case BCMBAL_TM_SCHED_OWNER_TYPE_VIRTUAL: |
| 116 | if(tmScOwn->virtual_->has_idx) |
| 117 | { |
| 118 | valtmScOwn.u.virtual.idx = tmScOwn->virtual_->idx; |
| 119 | } |
| 120 | break; |
| 121 | default: |
| 122 | break; |
| 123 | } |
| 124 | ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, owner, BCMOS_TRUE, valtmScOwn); |
| 125 | } |
| 126 | |
| 127 | ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, sched_type, |
| 128 | tm_sched_cfg->data->has_sched_type, |
| 129 | tm_sched_cfg->data->sched_type); |
| 130 | |
| 131 | /* scheduler parent */ |
| 132 | BalTmSchedParent *schedPar = (BalTmSchedParent *)tm_sched_cfg->data->sched_parent; |
| 133 | bcmbal_tm_sched_parent valSchedPar = {}; |
| 134 | if(schedPar != NULL && schedPar->has_presence_mask) |
| 135 | { |
| 136 | valSchedPar.presence_mask = schedPar->presence_mask; |
| 137 | if(schedPar->has_sched_id) |
| 138 | { |
| 139 | valSchedPar.sched_id = schedPar->sched_id; |
| 140 | } |
| 141 | if(schedPar->has_priority) |
| 142 | { |
| 143 | valSchedPar.priority = schedPar->priority; |
| 144 | } |
| 145 | if(schedPar->has_weight) |
| 146 | { |
| 147 | valSchedPar.weight = schedPar->weight; |
| 148 | } |
| 149 | ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, sched_parent, BCMOS_TRUE, valSchedPar); |
| 150 | } |
| 151 | |
| 152 | ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, sched_child_type, |
| 153 | tm_sched_cfg->data->has_sched_child_type, |
| 154 | tm_sched_cfg->data->sched_child_type); |
| 155 | |
| 156 | /* rating/shaping */ |
| 157 | BalTmShaping *balShaping = (BalTmShaping *)tm_sched_cfg->data->rate; |
| 158 | bcmbal_tm_shaping val = {}; |
| 159 | if (balShaping != NULL && balShaping->has_presence_mask) |
| 160 | { |
| 161 | val.presence_mask = balShaping->presence_mask; |
| 162 | if (balShaping->has_cir) |
| 163 | { |
| 164 | val.cir = balShaping->cir; |
| 165 | } |
| 166 | if (balShaping->has_pir) |
| 167 | { |
| 168 | val.pir = balShaping->pir; |
| 169 | } |
| 170 | if (balShaping->has_burst) |
| 171 | { |
| 172 | val.burst = balShaping->burst; |
| 173 | } |
| 174 | ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, rate, BCMOS_TRUE, val); |
| 175 | } |
| 176 | |
| 177 | /* Extended itu dba parameters */ |
| 178 | BalExtendedItuDba *tItuDba = (BalExtendedItuDba *)tm_sched_cfg->data->ext_itu_dba; |
| 179 | bcmbal_extended_itu_dba valItuDda = {}; |
| 180 | if (tItuDba != NULL && tItuDba->has_presence_mask) |
| 181 | { |
| 182 | valItuDda.presence_mask = tItuDba->presence_mask; |
| 183 | if(tItuDba->has_extra_bw_elig) |
| 184 | { |
| 185 | valItuDda.extra_bw_elig = tItuDba->extra_bw_elig; |
| 186 | } |
| 187 | if (tItuDba->has_nrt_cbr) |
| 188 | { |
| 189 | valItuDda.nrt_cbr = tItuDba->nrt_cbr; |
| 190 | } |
| 191 | if (tItuDba->has_rt_cbr) |
| 192 | { |
| 193 | valItuDda.rt_cbr = tItuDba->rt_cbr; |
| 194 | } |
| 195 | if (tItuDba->has_nrt_profile) |
| 196 | { |
| 197 | valItuDda.nrt_profile = tItuDba->nrt_profile; |
| 198 | } |
| 199 | if (tItuDba->has_rt_profile) |
| 200 | { |
| 201 | valItuDda.rt_profile = tItuDba->rt_profile; |
| 202 | } |
| 203 | ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, ext_itu_dba, BCMOS_TRUE, valItuDda); |
| 204 | } |
| 205 | |
| 206 | /* Creation mode */ |
| 207 | ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, creation_mode, |
| 208 | tm_sched_cfg->data->has_creation_mode, |
| 209 | tm_sched_cfg->data->creation_mode); |
| 210 | |
| 211 | /* Extended epon dba parameters */ |
| 212 | BalExtendedEponDba *teponDba = (BalExtendedEponDba*)tm_sched_cfg->data->ext_epon_dba; |
| 213 | bcmbal_extended_epon_dba valeponDda = {}; |
| 214 | if (teponDba != NULL && teponDba->has_presence_mask) |
| 215 | { |
| 216 | valeponDda.presence_mask = teponDba->presence_mask; |
| 217 | if (teponDba->has_polling_interval_us) |
| 218 | { |
| 219 | valeponDda.polling_interval_us = teponDba->polling_interval_us; |
| 220 | } |
| 221 | if (teponDba->has_grant_threshold_tq) |
| 222 | { |
| 223 | valeponDda.grant_threshold_tq = teponDba->grant_threshold_tq; |
| 224 | } |
| 225 | if (teponDba->has_cir_priority) |
| 226 | { |
| 227 | valeponDda.cir_priority = teponDba->cir_priority; |
| 228 | } |
| 229 | if (teponDba->has_cir_weight_tq) |
| 230 | { |
| 231 | valeponDda.cir_weight_tq = teponDba->cir_weight_tq; |
| 232 | } |
| 233 | if (teponDba->has_pir_priority) |
| 234 | { |
| 235 | valeponDda.pir_priority = teponDba->pir_priority; |
| 236 | } |
| 237 | if (teponDba->has_pir_weight_tq) |
| 238 | { |
| 239 | valeponDda.pir_weight_tq = teponDba->pir_weight_tq; |
| 240 | } |
| 241 | if (teponDba->has_tdm_grant_size_tq) |
| 242 | { |
| 243 | valeponDda.tdm_grant_size_tq = teponDba->tdm_grant_size_tq; |
| 244 | } |
| 245 | if (teponDba->has_tdm_grant_interval_us) |
| 246 | { |
| 247 | valeponDda.tdm_grant_interval_us = teponDba->tdm_grant_interval_us; |
| 248 | } |
| 249 | ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, ext_epon_dba, BCMOS_TRUE, valeponDda); |
| 250 | } |
| 251 | |
| 252 | /* Subsidiary queues */ |
| 253 | BalIdList *balQueues = (BalIdList *)tm_sched_cfg->data->queues; |
| 254 | bcmbal_tm_queue_id_list_u8 valQueues = {}; |
| 255 | if(balQueues != NULL && balQueues->n_val) |
| 256 | { |
| 257 | valQueues.len = balQueues->n_val; |
| 258 | valQueues.val = (bcmbal_tm_queue_id *)malloc((valQueues.len)*sizeof(bcmbal_tm_queue_id)); |
| 259 | if(!valQueues.val) |
| 260 | { |
| 261 | ASFVOLT_LOG(ASFVOLT_ERROR, |
| 262 | "Failed to configure the tm scheduler cfg(OLT): Memory Exhausted\n"); |
| 263 | return BAL_ERRNO__BAL_ERR_NOMEM; |
| 264 | } |
| 265 | memcpy((void *)valQueues.val, (const void *)balQueues->val, |
| 266 | (balQueues->n_val)*sizeof(uint32_t)); |
| 267 | ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, queues, BCMOS_TRUE, valQueues); |
| 268 | } |
| 269 | |
| 270 | /* Subsidiary schedulers */ |
| 271 | BalIdList *balSubScheds = (BalIdList *)tm_sched_cfg->data->sub_scheds; |
| 272 | bcmbal_tm_sched_id_list_u8 valSubScheds = {}; |
| 273 | if(balSubScheds != NULL && balSubScheds->n_val) |
| 274 | { |
| 275 | valSubScheds.len = balSubScheds->n_val; |
| 276 | valSubScheds.val = (uint32_t *)malloc((valSubScheds.len)*sizeof(uint32_t)); |
| 277 | if(!valSubScheds.val) |
| 278 | { |
| 279 | ASFVOLT_LOG(ASFVOLT_ERROR, |
| 280 | "Failed to configure the tm scheduler cfg(OLT): Memory Exhausted\n"); |
| 281 | return BAL_ERRNO__BAL_ERR_NOMEM; |
| 282 | } |
| 283 | memcpy((void *)valSubScheds.val, (const void *)balSubScheds->val, |
| 284 | (balSubScheds->n_val)*sizeof(uint32_t)); |
| 285 | ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, sub_scheds, BCMOS_TRUE, valSubScheds); |
| 286 | } |
| 287 | |
| 288 | ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, num_priorities, |
| 289 | tm_sched_cfg->data->has_num_priorities, |
| 290 | tm_sched_cfg->data->num_priorities); |
| 291 | |
| 292 | err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(tm_sched_obj.hdr)); |
| 293 | |
| 294 | if(BCM_ERR_OK != err) |
| 295 | { |
| 296 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the tm scheduler Cfg(OLT)\n"); |
| 297 | return err; |
| 298 | } |
| 299 | |
| 300 | ASFVOLT_LOG(ASFVOLT_INFO, "Set tm scheduler configuration sent to OLT. \ |
| 301 | Sched ID(%d) Sched Dir(%d)\n", key.id, key.dir); |
| 302 | return err; |
| 303 | } |
| 304 | |
| 305 | |
| 306 | /********************************************************************\ |
| 307 | * Function : bal_tm_sched_cfg_get * |
| 308 | * Description : get the OLT device tm queue configuration * |
| 309 | ********************************************************************/ |
| 310 | |
| 311 | uint32_t bal_tm_sched_cfg_get(BalTmSchedKey *tm_sched_key, BalTmSchedCfg *tm_sched_cfg) |
| 312 | { |
| 313 | bcmos_errno err = BCM_ERR_OK; |
| 314 | bcmbal_tm_sched_cfg tm_sched_obj; /**< declare main API struct */ |
| 315 | bcmbal_tm_sched_key key = { }; /**< declare key */ |
| 316 | |
| 317 | if((tm_sched_cfg->key->has_dir) && (tm_sched_cfg->key->has_id)) |
| 318 | { |
| 319 | key.dir = tm_sched_cfg->key->dir; |
| 320 | key.id = tm_sched_cfg->key->id; |
| 321 | } |
| 322 | else |
| 323 | { |
| 324 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to get the tm schedule cfg(OLT): Missing Key values\ |
| 325 | Recevied key values Sched-Dir(%d), Sched-Id(%d) \n", |
| 326 | tm_sched_cfg->key->dir, tm_sched_cfg->key->id); |
| 327 | return BAL_ERRNO__BAL_ERR_NOENT; |
| 328 | } |
| 329 | |
| 330 | |
| 331 | ASFVOLT_LOG(ASFVOLT_DEBUG, "Gem tm scheduler cfg (for OLT) starts\n"); |
| 332 | |
| 333 | /* init the API struct */ |
| 334 | BCMBAL_CFG_INIT(&tm_sched_obj, tm_sched, key); |
| 335 | |
| 336 | /* request all properties, include everything */ |
| 337 | BCMBAL_CFG_PROP_GET(&tm_sched_obj, tm_sched, all_properties); |
| 338 | |
| 339 | err = bcmbal_cfg_get(DEFAULT_ATERM_ID, &tm_sched_obj.hdr); |
| 340 | |
| 341 | if(BCM_ERR_OK != err) |
| 342 | { |
| 343 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to get the tm scheduler Cfg(OLT)\n"); |
| 344 | return err; |
| 345 | } |
| 346 | |
| 347 | ASFVOLT_LOG(ASFVOLT_INFO, "Get tm scheduler cfg sent to OLT. \ |
| 348 | Sched ID(%d) Sched Dir(%d)\n", key.id, key.dir); |
| 349 | return err; |
| 350 | } |
| 351 | |
| 352 | |
| 353 | /********************************************************************\ |
| 354 | * Function : bal_tm_sched_cfg_clear * |
| 355 | * Description : Clears the OLT device tm queue configuration * |
| 356 | ********************************************************************/ |
| 357 | |
| 358 | uint32_t bal_tm_sched_cfg_clear(BalTmSchedKey *tm_sched_key) |
| 359 | { |
| 360 | bcmos_errno err = BCM_ERR_OK; |
| 361 | bcmbal_tm_sched_cfg tm_sched_obj; /**< declare main API struct */ |
| 362 | bcmbal_tm_sched_key key = { }; /**< declare key */ |
| 363 | |
| 364 | if((tm_sched_key->has_dir) && (tm_sched_key->has_id)) |
| 365 | { |
| 366 | key.dir = tm_sched_key->dir; |
| 367 | key.id = tm_sched_key->id; |
| 368 | } |
| 369 | else |
| 370 | { |
| 371 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to clear the tm schedule cfg(OLT): Missing Key values\ |
| 372 | Recevied key values Sched-Dir(%d), Sched-Id(%d) \n", |
| 373 | tm_sched_key->dir, tm_sched_key->id); |
| 374 | return BAL_ERRNO__BAL_ERR_NOENT; |
| 375 | } |
| 376 | |
| 377 | ASFVOLT_LOG(ASFVOLT_DEBUG, "Clear tm scheduler cfg(for OLT) starts\n"); |
| 378 | |
| 379 | /* init the API struct */ |
| 380 | BCMBAL_CFG_INIT(&tm_sched_obj, tm_sched, key); |
| 381 | |
| 382 | err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &tm_sched_obj.hdr); |
| 383 | |
| 384 | if(BCM_ERR_OK != err) |
| 385 | { |
| 386 | ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to clear the tm scheduler Cfg(OLT)\n"); |
| 387 | return err; |
| 388 | } |
| 389 | |
| 390 | ASFVOLT_LOG(ASFVOLT_INFO, "Clear tm scheduler clear sent to OLT. \ |
| 391 | Sched ID(%d) Sched Dir(%d)\n", key.id, key.dir); |
| 392 | return err; |
| 393 | } |
| 394 | |
| 395 | |
| 396 | /********************************************************************\ |
| 397 | * Function : bal_tm_sched_indication_cb * |
| 398 | * Description : Call back function registered with BAL to handle * |
| 399 | * event related to access terminal * |
| 400 | ********************************************************************/ |
| 401 | bcmos_errno bal_tm_sched_cfg_indication_cb(bcmbal_obj *obj) |
| 402 | { |
| 403 | bcmos_errno result = BCM_ERR_OK; |
| 404 | ASFVOLT_LOG(ASFVOLT_INFO, "Processing API (%s) IND callback status is (%s)\n", |
| 405 | bcmbal_objtype_str(obj->obj_type), |
| 406 | bcmos_strerror(obj->status)); |
| 407 | |
| 408 | return result; |
| 409 | } |
| 410 | |
| 411 | |