blob: a0a92acf5818f0fa0cc6d0b4fb73313028965248 [file] [log] [blame]
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +05301/*
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
31uint32_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 */
Kim Kempfafa1ab42017-11-13 09:31:47 -080036
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053037 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 {
Kim Kempfafa1ab42017-11-13 09:31:47 -080044 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the tm schedule cfg(OLT): Missing Key values "
45 "Received key values Sched-Dir(%d), Sched-Id(%d)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053046 tm_sched_cfg->key->dir, tm_sched_cfg->key->id);
47 return BAL_ERRNO__BAL_ERR_NOENT;
48 }
49
Kim Kempfafa1ab42017-11-13 09:31:47 -080050 ASFVOLT_LOG(ASFVOLT_DEBUG, "Configuration of OLT(tm Sched) starts");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053051 /* 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;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530101 case BCMBAL_TM_SCHED_OWNER_TYPE_VIRTUAL:
102 if(tmScOwn->virtual_->has_idx)
103 {
104 valtmScOwn.u.virtual.idx = tmScOwn->virtual_->idx;
105 }
106 break;
107 default:
108 break;
109 }
110 ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, owner, BCMOS_TRUE, valtmScOwn);
111 }
112
Kim Kempfafa1ab42017-11-13 09:31:47 -0800113 ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, sched_type,
114 tm_sched_cfg->data->has_sched_type,
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530115 tm_sched_cfg->data->sched_type);
116
117 /* scheduler parent */
118 BalTmSchedParent *schedPar = (BalTmSchedParent *)tm_sched_cfg->data->sched_parent;
119 bcmbal_tm_sched_parent valSchedPar = {};
120 if(schedPar != NULL && schedPar->has_presence_mask)
121 {
122 valSchedPar.presence_mask = schedPar->presence_mask;
123 if(schedPar->has_sched_id)
124 {
125 valSchedPar.sched_id = schedPar->sched_id;
Kim Kempfafa1ab42017-11-13 09:31:47 -0800126 }
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530127 if(schedPar->has_priority)
128 {
129 valSchedPar.priority = schedPar->priority;
Kim Kempfafa1ab42017-11-13 09:31:47 -0800130 }
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530131 if(schedPar->has_weight)
132 {
133 valSchedPar.weight = schedPar->weight;
Kim Kempfafa1ab42017-11-13 09:31:47 -0800134 }
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530135 ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, sched_parent, BCMOS_TRUE, valSchedPar);
136 }
Kim Kempfafa1ab42017-11-13 09:31:47 -0800137
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530138 /* rating/shaping */
139 BalTmShaping *balShaping = (BalTmShaping *)tm_sched_cfg->data->rate;
140 bcmbal_tm_shaping val = {};
141 if (balShaping != NULL && balShaping->has_presence_mask)
142 {
143 val.presence_mask = balShaping->presence_mask;
144 if (balShaping->has_cir)
145 {
146 val.cir = balShaping->cir;
147 }
148 if (balShaping->has_pir)
149 {
150 val.pir = balShaping->pir;
151 }
152 if (balShaping->has_burst)
153 {
154 val.burst = balShaping->burst;
155 }
156 ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, rate, BCMOS_TRUE, val);
157 }
158
159 /* Extended itu dba parameters */
160 BalExtendedItuDba *tItuDba = (BalExtendedItuDba *)tm_sched_cfg->data->ext_itu_dba;
Kim Kempfafa1ab42017-11-13 09:31:47 -0800161 bcmbal_extended_itu_dba valItuDda = {};
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530162 if (tItuDba != NULL && tItuDba->has_presence_mask)
163 {
164 valItuDda.presence_mask = tItuDba->presence_mask;
165 if(tItuDba->has_extra_bw_elig)
166 {
167 valItuDda.extra_bw_elig = tItuDba->extra_bw_elig;
168 }
169 if (tItuDba->has_nrt_cbr)
170 {
171 valItuDda.nrt_cbr = tItuDba->nrt_cbr;
172 }
173 if (tItuDba->has_rt_cbr)
174 {
175 valItuDda.rt_cbr = tItuDba->rt_cbr;
176 }
177 if (tItuDba->has_nrt_profile)
178 {
179 valItuDda.nrt_profile = tItuDba->nrt_profile;
180 }
181 if (tItuDba->has_rt_profile)
182 {
183 valItuDda.rt_profile = tItuDba->rt_profile;
184 }
185 ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, ext_itu_dba, BCMOS_TRUE, valItuDda);
186 }
187
188 /* Creation mode */
Kim Kempfafa1ab42017-11-13 09:31:47 -0800189 ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, creation_mode,
190 tm_sched_cfg->data->has_creation_mode,
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530191 tm_sched_cfg->data->creation_mode);
192
193 /* Extended epon dba parameters */
194 BalExtendedEponDba *teponDba = (BalExtendedEponDba*)tm_sched_cfg->data->ext_epon_dba;
Kim Kempfafa1ab42017-11-13 09:31:47 -0800195 bcmbal_extended_epon_dba valeponDda = {};
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530196 if (teponDba != NULL && teponDba->has_presence_mask)
197 {
198 valeponDda.presence_mask = teponDba->presence_mask;
199 if (teponDba->has_polling_interval_us)
200 {
201 valeponDda.polling_interval_us = teponDba->polling_interval_us;
202 }
203 if (teponDba->has_grant_threshold_tq)
204 {
205 valeponDda.grant_threshold_tq = teponDba->grant_threshold_tq;
206 }
207 if (teponDba->has_cir_priority)
208 {
209 valeponDda.cir_priority = teponDba->cir_priority;
210 }
211 if (teponDba->has_cir_weight_tq)
212 {
213 valeponDda.cir_weight_tq = teponDba->cir_weight_tq;
214 }
215 if (teponDba->has_pir_priority)
216 {
217 valeponDda.pir_priority = teponDba->pir_priority;
218 }
219 if (teponDba->has_pir_weight_tq)
220 {
221 valeponDda.pir_weight_tq = teponDba->pir_weight_tq;
222 }
223 if (teponDba->has_tdm_grant_size_tq)
224 {
225 valeponDda.tdm_grant_size_tq = teponDba->tdm_grant_size_tq;
226 }
227 if (teponDba->has_tdm_grant_interval_us)
228 {
229 valeponDda.tdm_grant_interval_us = teponDba->tdm_grant_interval_us;
230 }
231 ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, ext_epon_dba, BCMOS_TRUE, valeponDda);
232 }
233
234 /* Subsidiary queues */
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700235 BalTmQueueIdList *balQueues = (BalTmQueueIdList *)tm_sched_cfg->data->queues;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530236 bcmbal_tm_queue_id_list_u8 valQueues = {};
237 if(balQueues != NULL && balQueues->n_val)
238 {
239 valQueues.len = balQueues->n_val;
240 valQueues.val = (bcmbal_tm_queue_id *)malloc((valQueues.len)*sizeof(bcmbal_tm_queue_id));
241 if(!valQueues.val)
242 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800243 ASFVOLT_LOG(ASFVOLT_ERROR,
244 "Failed to configure the tm scheduler cfg(OLT): Memory Exhausted");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530245 return BAL_ERRNO__BAL_ERR_NOMEM;
246 }
Kim Kempfafa1ab42017-11-13 09:31:47 -0800247 memcpy((void *)valQueues.val, (const void *)balQueues->val,
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530248 (balQueues->n_val)*sizeof(uint32_t));
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700249 ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, queue_list, BCMOS_TRUE, valQueues);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530250 }
251
252 /* Subsidiary schedulers */
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700253 BalTmSchedIdList *balSubScheds = (BalTmSchedIdList *)tm_sched_cfg->data->sub_scheds;
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530254 bcmbal_tm_sched_id_list_u8 valSubScheds = {};
255 if(balSubScheds != NULL && balSubScheds->n_val)
256 {
257 valSubScheds.len = balSubScheds->n_val;
258 valSubScheds.val = (uint32_t *)malloc((valSubScheds.len)*sizeof(uint32_t));
259 if(!valSubScheds.val)
260 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800261 ASFVOLT_LOG(ASFVOLT_ERROR,
262 "Failed to configure the tm scheduler cfg(OLT): Memory Exhausted");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530263 return BAL_ERRNO__BAL_ERR_NOMEM;
264 }
Kim Kempfafa1ab42017-11-13 09:31:47 -0800265 memcpy((void *)valSubScheds.val, (const void *)balSubScheds->val,
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530266 (balSubScheds->n_val)*sizeof(uint32_t));
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700267 ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, sub_sched_list, BCMOS_TRUE, valSubScheds);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530268 }
269
Kim Kempfafa1ab42017-11-13 09:31:47 -0800270 ASFVOLT_CFG_PROP_SET(tm_sched_obj, tm_sched, num_priorities,
271 tm_sched_cfg->data->has_num_priorities,
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530272 tm_sched_cfg->data->num_priorities);
273
274 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(tm_sched_obj.hdr));
275
276 if(BCM_ERR_OK != err)
277 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800278 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the tm scheduler Cfg(OLT)");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530279 return err;
280 }
281
Kim Kempfafa1ab42017-11-13 09:31:47 -0800282 ASFVOLT_LOG(ASFVOLT_INFO, "Set tm scheduler configuration sent to OLT. "
283 "Sched ID(%d) Sched Dir(%d)", key.id, key.dir);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530284 return err;
285}
286
287
288/********************************************************************\
289 * Function : bal_tm_sched_cfg_get *
290 * Description : get the OLT device tm queue configuration *
291 ********************************************************************/
292
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700293uint32_t bal_tm_sched_cfg_get(BalTmSchedCfg *tm_sched_cfg)
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530294{
295 bcmos_errno err = BCM_ERR_OK;
296 bcmbal_tm_sched_cfg tm_sched_obj; /**< declare main API struct */
297 bcmbal_tm_sched_key key = { }; /**< declare key */
Kim Kempfafa1ab42017-11-13 09:31:47 -0800298
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700299 key.dir = tm_sched_cfg->key->dir;
300 key.id = tm_sched_cfg->key->id;
Kim Kempfafa1ab42017-11-13 09:31:47 -0800301
302 ASFVOLT_LOG(ASFVOLT_DEBUG, "Gem tm scheduler cfg (for OLT) starts");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530303
304 /* init the API struct */
305 BCMBAL_CFG_INIT(&tm_sched_obj, tm_sched, key);
306
307 /* request all properties, include everything */
308 BCMBAL_CFG_PROP_GET(&tm_sched_obj, tm_sched, all_properties);
309
310 err = bcmbal_cfg_get(DEFAULT_ATERM_ID, &tm_sched_obj.hdr);
311
312 if(BCM_ERR_OK != err)
313 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800314 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to get the tm scheduler Cfg(OLT)");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530315 return err;
316 }
317
Kim Kempfafa1ab42017-11-13 09:31:47 -0800318 ASFVOLT_LOG(ASFVOLT_INFO, "Get tm scheduler cfg sent to OLT. "
319 "Sched ID(%d) Sched Dir(%d)", key.id, key.dir);
Girish Gowdru9ebd8b22018-09-26 03:21:03 -0700320
321 memcpy(tm_sched_cfg->key, &key, sizeof(BalTmSchedKey));
322 memcpy(tm_sched_cfg->data, &tm_sched_obj, sizeof(BalTmSchedCfgData));
323
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530324 return err;
325}
326
327
328/********************************************************************\
329 * Function : bal_tm_sched_cfg_clear *
330 * Description : Clears the OLT device tm queue configuration *
331 ********************************************************************/
332
333uint32_t bal_tm_sched_cfg_clear(BalTmSchedKey *tm_sched_key)
334{
335 bcmos_errno err = BCM_ERR_OK;
336 bcmbal_tm_sched_cfg tm_sched_obj; /**< declare main API struct */
337 bcmbal_tm_sched_key key = { }; /**< declare key */
Kim Kempfafa1ab42017-11-13 09:31:47 -0800338
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530339 if((tm_sched_key->has_dir) && (tm_sched_key->has_id))
340 {
341 key.dir = tm_sched_key->dir;
342 key.id = tm_sched_key->id;
343 }
344 else
345 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800346 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to clear the tm schedule cfg(OLT): Missing Key values "
347 "Received key values Sched-Dir(%d), Sched-Id(%d)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530348 tm_sched_key->dir, tm_sched_key->id);
349 return BAL_ERRNO__BAL_ERR_NOENT;
350 }
351
Kim Kempfafa1ab42017-11-13 09:31:47 -0800352 ASFVOLT_LOG(ASFVOLT_DEBUG, "Clear tm scheduler cfg(for OLT) starts");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530353
354 /* init the API struct */
355 BCMBAL_CFG_INIT(&tm_sched_obj, tm_sched, key);
356
357 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &tm_sched_obj.hdr);
358
359 if(BCM_ERR_OK != err)
360 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800361 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to clear the tm scheduler Cfg(OLT)");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530362 return err;
363 }
364
Kim Kempfafa1ab42017-11-13 09:31:47 -0800365 ASFVOLT_LOG(ASFVOLT_INFO, "Clear tm scheduler clear sent to OLT. "
366 "Sched ID(%d) Sched Dir(%d)", key.id, key.dir);
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530367 return err;
368}
369
370
371/********************************************************************\
372 * Function : bal_tm_sched_indication_cb *
373 * Description : Call back function registered with BAL to handle *
374 * event related to access terminal *
375 ********************************************************************/
376bcmos_errno bal_tm_sched_cfg_indication_cb(bcmbal_obj *obj)
377{
378 bcmos_errno result = BCM_ERR_OK;
Kim Kempfafa1ab42017-11-13 09:31:47 -0800379 ASFVOLT_LOG(ASFVOLT_INFO, "Processing API (%s) IND callback status is (%s)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530380 bcmbal_objtype_str(obj->obj_type),
381 bcmos_strerror(obj->status));
Kim Kempfafa1ab42017-11-13 09:31:47 -0800382
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530383 return result;
384}
385
386