blob: eb52db97dac5824216a2f2ce82d832e5765023a6 [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_tmqueue_hdlr.h"
25
26
27/********************************************************************\
28 * Function : bal_tm_queue_cfg_set *
29 * Description : Configures the tm queue for OLT device *
30 ********************************************************************/
31
32uint32_t bal_tm_queue_cfg_set(BalTmQueueCfg *tm_queue_cfg)
33{
34 bcmos_errno err = BCM_ERR_OK;
35 bcmbal_tm_queue_cfg tm_queue_obj; /**< declare main API struct */
36 bcmbal_tm_queue_key key = { }; /**< declare key */
37
38 if((tm_queue_cfg->key->has_id) && (tm_queue_cfg->key->has_sched_id) && (tm_queue_cfg->key->has_sched_dir))
39 {
40 key.id = tm_queue_cfg->key->id;
41 key.sched_id = tm_queue_cfg->key->sched_id;
42 key.sched_dir = tm_queue_cfg->key->sched_dir;
43 }
44 else
45 {
Kim Kempfafa1ab42017-11-13 09:31:47 -080046 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the tm queue cfg(OLT): Missing Key values "
47 "Received key values Id(%d), Sched-Dir(%d), Sched-Id(%d)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053048 tm_queue_cfg->key->sched_id, tm_queue_cfg->key->sched_dir, tm_queue_cfg->key->id);
49 return BAL_ERRNO__BAL_ERR_NOENT;
50 }
51
Kim Kempfafa1ab42017-11-13 09:31:47 -080052 ASFVOLT_LOG(ASFVOLT_DEBUG, "Configuration of OLT(tm Queue) starts");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053053
54 /* init the API struct */
55 BCMBAL_CFG_INIT(&tm_queue_obj, tm_queue, key);
56
Suhas Gururaj07da86a2018-05-11 14:37:03 +053057 if (NULL != tm_queue_cfg->data)
58 {
59 /* decode API parameters from GRPC */
60 ASFVOLT_CFG_PROP_SET(tm_queue_obj, tm_queue, priority,
61 tm_queue_cfg->data->has_priority,
62 tm_queue_cfg->data->priority);
63 ASFVOLT_CFG_PROP_SET(tm_queue_obj, tm_queue, weight,
64 tm_queue_cfg->data->has_weight,
65 tm_queue_cfg->data->weight);
66 ASFVOLT_CFG_PROP_SET(tm_queue_obj, tm_queue, creation_mode,
67 tm_queue_cfg->data->has_creation_mode,
68 tm_queue_cfg->data->creation_mode);
69 ASFVOLT_CFG_PROP_SET(tm_queue_obj, tm_queue, ref_count,
70 tm_queue_cfg->data->has_ref_count,
71 tm_queue_cfg->data->ref_count);
72 }
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053073 /* rating/shaping */
74 BalTmShaping *balShaping = (BalTmShaping *)tm_queue_cfg->data->rate;
75 bcmbal_tm_shaping val = {};
Suhas Gururaj07da86a2018-05-11 14:37:03 +053076 if ((NULL != balShaping) && (balShaping->has_presence_mask))
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053077 {
78 val.presence_mask = balShaping->presence_mask;
79 if (balShaping->has_cir)
80 {
81 val.cir = balShaping->cir;
82 }
83 if (balShaping->has_pir)
84 {
85 val.pir = balShaping->pir;
86 }
87 if (balShaping->has_burst)
88 {
89 val.burst = balShaping->burst;
90 }
91 ASFVOLT_CFG_PROP_SET(tm_queue_obj, tm_queue, rate, BCMOS_TRUE, val);
92 }
93
94 /* bac - Buffer addmission Control */
95 BalTmBac *balBac = (BalTmBac *)tm_queue_cfg->data->bac;
96 bcmbal_tm_bac valBac = {};
Suhas Gururaj07da86a2018-05-11 14:37:03 +053097 if((NULL != balBac) && (balBac->has_type))
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +053098 {
99 valBac.type = balBac->type;
100 switch(valBac.type)
101 {
102 case BAL_TM_BAC__U_TAILDROP:
103 if(balBac->taildrop->has_max_size)
104 {
105 valBac.u.taildrop.max_size = balBac->taildrop->max_size;
106 }
107 break;
108 case BAL_TM_BAC__U_RED:
109 if(balBac->red->red->has_min_threshold)
110 {
111 valBac.u.red.red.min_threshold = balBac->red->red->min_threshold;
112 }
113 if(balBac->red->red->has_max_threshold)
114 {
115 valBac.u.red.red.max_threshold = balBac->red->red->max_threshold;
116 }
117 if(balBac->red->red->has_max_probability)
118 {
119 valBac.u.red.red.max_probability = balBac->red->red->max_probability;
120 }
121 break;
122 case BAL_TM_BAC__U_WRED:
123 if(balBac->wred->red->has_min_threshold)
124 {
125 valBac.u.wred.red.min_threshold = balBac->wred->red->min_threshold;
126 }
127 if(balBac->wred->red->has_max_threshold)
128 {
129 valBac.u.wred.red.max_threshold = balBac->wred->red->max_threshold;
130 }
131 if(balBac->wred->red->has_max_probability)
132 {
133 valBac.u.wred.red.max_probability= balBac->wred->red->max_probability;
134 }
135 if(balBac->wred->green->has_min_threshold)
136 {
137 valBac.u.wred.green.min_threshold = balBac->wred->green->min_threshold;
138 }
139 if(balBac->wred->green->has_max_threshold)
140 {
141 valBac.u.wred.green.max_threshold = balBac->wred->green->max_threshold;
142 }
143 if(balBac->wred->green->has_max_probability)
144 {
145 valBac.u.wred.green.max_probability= balBac->wred->green->max_probability;
146 }
147 if(balBac->wred->yellow->has_min_threshold)
148 {
149 valBac.u.wred.yellow.min_threshold = balBac->wred->yellow->min_threshold;
150 }
151 if(balBac->wred->yellow->has_max_threshold)
152 {
153 valBac.u.wred.yellow.max_threshold = balBac->wred->yellow->max_threshold;
154 }
155 if(balBac->wred->yellow->has_max_probability)
156 {
157 valBac.u.wred.yellow.max_probability= balBac->wred->yellow->max_probability;
158 }
159 break;
160 default:
161 break;
162 }
163 ASFVOLT_CFG_PROP_SET(tm_queue_obj, tm_queue, bac, BCMOS_TRUE, valBac);
164 }
165
166 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(tm_queue_obj.hdr));
167
168 if(BCM_ERR_OK != err)
169 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800170 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to configure the tm Queue Cfg(OLT)");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530171 return err;
172 }
173
Kim Kempfafa1ab42017-11-13 09:31:47 -0800174 ASFVOLT_LOG(ASFVOLT_INFO, "Set tm Queue configuration sent to OLT. "
175 "Queue ID(%d) Sched ID(%d) Sched Dir(%d)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530176 key.id, key.sched_id, key.sched_dir );
177 return err;
178}
179
180
181/********************************************************************\
182 * Function : bal_tm_queue_cfg_clear *
183 * Description : clear the OLT device tm queue configuration *
184 ********************************************************************/
185
186uint32_t bal_tm_queue_cfg_clear(BalTmQueueKey *tm_queue_key)
187{
188 bcmos_errno err = BCM_ERR_OK;
189 bcmbal_tm_queue_cfg tm_queue_obj; /**< declare main API struct */
190 bcmbal_tm_queue_key key = { }; /**< declare key */
Kim Kempfafa1ab42017-11-13 09:31:47 -0800191
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530192 if((tm_queue_key->has_id) && (tm_queue_key->has_sched_id) && (tm_queue_key->has_sched_dir))
193 {
194 key.id = tm_queue_key->id;
195 key.sched_id = tm_queue_key->sched_id;
196 key.sched_dir = tm_queue_key->sched_dir;
197 }
198 else
199 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800200 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to clear the tm queue cfg(OLT): Missing Key values "
201 "Received key values Id(%d), Sched-Dir(%d), Sched-Id(%d) ",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530202 tm_queue_key->sched_id, tm_queue_key->sched_dir, tm_queue_key->id);
203 return BAL_ERRNO__BAL_ERR_NOENT;
204 }
205
Kim Kempfafa1ab42017-11-13 09:31:47 -0800206 ASFVOLT_LOG(ASFVOLT_DEBUG, "Clearing of OLT(tm Queue) starts");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530207
208 /* init the API struct */
209 BCMBAL_CFG_INIT(&tm_queue_obj, tm_queue, key);
210
211 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &tm_queue_obj.hdr);
212
213 if(BCM_ERR_OK != err)
214 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800215 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to clear the tm Queue Cfg(OLT)");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530216 return err;
217 }
218
Kim Kempfafa1ab42017-11-13 09:31:47 -0800219 ASFVOLT_LOG(ASFVOLT_INFO, "Clear tm Queue sent to OLT. "
220 "Queue ID(%d) Sched ID(%d) Sched Dir(%d)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530221 key.id, key.sched_id, key.sched_dir );
222 return err;
223}
224
225
226/********************************************************************\
227 * Function : bal_tm_queue_cfg_get *
228 * Description : Get the OLT device tm queue configuration *
229 ********************************************************************/
230
231uint32_t bal_tm_queue_cfg_get(BalTmQueueKey *tm_queue_key, BalTmQueueCfg *tm_queue_cfg)
232{
233 bcmos_errno err = BCM_ERR_OK;
234 bcmbal_tm_queue_cfg tm_queue_obj; /**< declare main API struct */
235 bcmbal_tm_queue_key key = { }; /**< declare key */
Kim Kempfafa1ab42017-11-13 09:31:47 -0800236
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530237 if((tm_queue_key->has_id) && (tm_queue_key->has_sched_id) && (tm_queue_key->has_sched_dir))
238 {
239 key.id = tm_queue_key->id;
240 key.sched_id = tm_queue_key->sched_id;
241 key.sched_dir = tm_queue_key->sched_dir;
242 }
243 else
244 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800245 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to get the tm queue cfg(OLT): Missing Key values "
246 "Received key values Id(%d), Sched-Dir(%d), Sched-Id(%d)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530247 tm_queue_key->sched_id, tm_queue_key->sched_dir, tm_queue_key->id);
248 return BAL_ERRNO__BAL_ERR_NOENT;
249 }
250
Kim Kempfafa1ab42017-11-13 09:31:47 -0800251 ASFVOLT_LOG(ASFVOLT_DEBUG, "Get tm queue cfg(for OLT) starts");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530252
253 /* init the API struct */
254 BCMBAL_CFG_INIT(&tm_queue_obj, tm_queue, key);
255
256 /* request all properties, include everything */
257 BCMBAL_CFG_PROP_GET(&tm_queue_obj, tm_queue, all_properties);
258
259 err = bcmbal_cfg_get(DEFAULT_ATERM_ID, &tm_queue_obj.hdr);
260
261 if(BCM_ERR_OK != err)
262 {
Kim Kempfafa1ab42017-11-13 09:31:47 -0800263 ASFVOLT_LOG(ASFVOLT_ERROR, "Failed to get the tm Queue Cfg(OLT)");
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530264 return err;
265 }
266
Kim Kempfafa1ab42017-11-13 09:31:47 -0800267 ASFVOLT_LOG(ASFVOLT_INFO, "Get tm Queue sent to OLT. "
268 "Queue ID(%d) Sched ID(%d) Sched Dir(%d)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530269 key.id, key.sched_id, key.sched_dir );
270 return err;
271}
272
273
274/********************************************************************\
275 * Function : bal_tm_queue_indication_cb *
276 * Description : Call back function registered with BAL to handle *
277 * event related to access terminal *
278 ********************************************************************/
279bcmos_errno bal_tm_queue_cfg_indication_cb(bcmbal_obj *obj)
280{
281 bcmos_errno result = BCM_ERR_OK;
Kim Kempfafa1ab42017-11-13 09:31:47 -0800282 ASFVOLT_LOG(ASFVOLT_INFO, "Processing API \'%s\' IND callback (status is %s)",
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530283 bcmbal_objtype_str(obj->obj_type),
284 bcmos_strerror(obj->status));
Kim Kempfafa1ab42017-11-13 09:31:47 -0800285
Rajeswara Raof6b4e6c2017-08-31 17:26:27 +0530286 return result;
287}