blob: 5a330b137d17bf6b8194f921bad0a6cb2d4eda74 [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#include "asfvolt16_driver.h"
23#include "bal_flow_hdlr.h"
24
25
26/********************************************************************\
27 * Function : bal_fill_queue_cfg *
28 * Description : copy queue information from proto structure to *
29 * BAL structure *
30 ********************************************************************/
31static uint32_t bal_fill_queue_cfg(BalTmQueueRef *tmp_que,
32 bcmbal_tm_queue_ref *que_val)
33{
34 if(tmp_que->has_sched_id)
35 {
36 que_val->sched_id = tmp_que->sched_id;
37 ASFVOLT_LOG(ASFVOLT_DEBUG, "que_val->sched_id = %d\n", que_val->sched_id);
38 }
39
40 if(tmp_que->has_queue_id)
41 {
42 que_val->queue_id = tmp_que->queue_id;
43 ASFVOLT_LOG(ASFVOLT_DEBUG, "que_val->queue_id = %d\n", que_val->queue_id);
44 }
45
46 return BAL_ERRNO__BAL_ERR_OK;
47}
48
49
50/********************************************************************\
51 * Function : bal_fill_action_cfg *
52 * Description : copy action information from proto structure to *
53 * BAL structure *
54 ********************************************************************/
55static uint32_t bal_fill_action_cfg(BalAction *tmp_action,
56 bcmbal_action *action_val)
57{
58
59 if(tmp_action->has_presence_mask)
60 {
61 action_val->presence_mask = tmp_action->presence_mask;
62 if (action_val->presence_mask & BCMBAL_ACTION_ID_CMDS_BITMASK)
63 {
64 action_val->cmds_bitmask = tmp_action->cmds_bitmask;
65 ASFVOLT_LOG(ASFVOLT_DEBUG, "action_val->cmds_bitmask = %x\n", action_val->cmds_bitmask);
66 }
67
68 if (action_val->presence_mask & BCMBAL_ACTION_ID_O_VID)
69 {
70 action_val->o_vid = tmp_action->o_vid;
71 ASFVOLT_LOG(ASFVOLT_DEBUG, "action_val->o_vid = %d\n", action_val->o_vid);
72 }
73
74 if (action_val->presence_mask & BCMBAL_ACTION_ID_O_PBITS)
75 {
76 action_val->o_pbits = tmp_action->o_pbits;
77 ASFVOLT_LOG(ASFVOLT_DEBUG, "action_val->o_pbits = %d\n", action_val->o_pbits);
78 }
79
80 if (action_val->presence_mask & BCMBAL_ACTION_ID_O_TPID)
81 {
82 action_val->o_tpid = tmp_action->o_tpid;
83 ASFVOLT_LOG(ASFVOLT_DEBUG, "action_val->o_tpid = %d\n", action_val->o_tpid);
84 }
85
86 if (action_val->presence_mask & BCMBAL_ACTION_ID_I_VID)
87 {
88 action_val->i_vid = tmp_action->i_vid;
89 ASFVOLT_LOG(ASFVOLT_DEBUG, "action_val->i_vid = %d\n", action_val->i_vid);
90 }
91
92 if (action_val->presence_mask & BCMBAL_ACTION_ID_I_PBITS)
93 {
94 action_val->i_pbits = tmp_action->i_pbits;
95 ASFVOLT_LOG(ASFVOLT_DEBUG, "action_val->i_pbits = %d\n", action_val->i_pbits);
96 }
97
98 if (action_val->presence_mask & BCMBAL_ACTION_ID_I_TPID)
99 {
100 action_val->i_tpid = tmp_action->i_tpid;
101 ASFVOLT_LOG(ASFVOLT_DEBUG, "action_val->i_tpid = %d\n", action_val->i_tpid);
102 }
103 ASFVOLT_LOG(ASFVOLT_DEBUG, "action_val->presence_mask = %x\n", action_val->presence_mask);
104 }
105 else
106 {
107 ASFVOLT_LOG(ASFVOLT_ERROR, "Action is not present in the flow\n");
108 return BAL_ERRNO__BAL_ERR_PARM;
109 }
110
111 return BAL_ERRNO__BAL_ERR_OK;
112}
113
114
115/********************************************************************\
116 * Function : bal_fill_classifier_cfg *
117 * Description : copy classifier information from proto structure to*
118 * BAL structure
119 ********************************************************************/
120uint32_t bal_fill_classifier_cfg(BalClassifier *tmp_classifier,
121 bcmbal_classifier *classifier_val)
122{
123
124 if(tmp_classifier->has_presence_mask)
125 {
126 classifier_val->presence_mask = tmp_classifier->presence_mask;
127 if (classifier_val->presence_mask & BCMBAL_CLASSIFIER_ID_O_TPID)
128 {
129 classifier_val->o_tpid = tmp_classifier->o_tpid;
130 ASFVOLT_LOG(ASFVOLT_DEBUG, "classifier_val->o_tpid = %d\n", classifier_val->o_tpid);
131 }
132
133 if (classifier_val->presence_mask & BCMBAL_CLASSIFIER_ID_O_VID)
134 {
135 classifier_val->o_vid = tmp_classifier->o_vid;
136 ASFVOLT_LOG(ASFVOLT_DEBUG, "classifier_val->o_vid = %d\n", classifier_val->o_vid);
137 }
138
139 if (classifier_val->presence_mask & BCMBAL_CLASSIFIER_ID_I_TPID)
140 {
141 classifier_val->i_tpid = tmp_classifier->i_tpid;
142 ASFVOLT_LOG(ASFVOLT_DEBUG, "classifier_val->i_tpid = %d\n", classifier_val->i_tpid);
143 }
144
145 if (classifier_val->presence_mask & BCMBAL_CLASSIFIER_ID_I_VID)
146 {
147 classifier_val->i_vid = tmp_classifier->i_vid;
148 ASFVOLT_LOG(ASFVOLT_DEBUG, "classifier_val->i_vid = %d\n", classifier_val->i_vid);
149 }
150
151 if (classifier_val->presence_mask & BCMBAL_CLASSIFIER_ID_O_PBITS)
152 {
153 classifier_val->o_pbits = tmp_classifier->o_pbits;
154 ASFVOLT_LOG(ASFVOLT_DEBUG, "classifier_val->o_pbits = %d\n", classifier_val->o_pbits);
155 }
156
157 if (classifier_val->presence_mask & BCMBAL_CLASSIFIER_ID_I_PBITS)
158 {
159 classifier_val->i_pbits = tmp_classifier->i_pbits;
160 ASFVOLT_LOG(ASFVOLT_DEBUG, "classifier_val->i_pbits = %d\n", classifier_val->i_pbits);
161 }
162
163 if (classifier_val->presence_mask & BCMBAL_CLASSIFIER_ID_ETHER_TYPE)
164 {
165 classifier_val->ether_type = tmp_classifier->ether_type;
166 ASFVOLT_LOG(ASFVOLT_DEBUG, "classifier_val->ether_type = %x\n", classifier_val->ether_type);
167 }
168
169 if (classifier_val->presence_mask & BCMBAL_CLASSIFIER_ID_DST_MAC)
170 {
171 if(tmp_classifier->dst_mac.len > BCMOS_ETH_ALEN)
172 {
173 memcpy(classifier_val->dst_mac.u8,
174 tmp_classifier->dst_mac.data, tmp_classifier->dst_mac.len);
175 /*ASFVOLT_LOG(ASFVOLT_DEBUG, "classifier_val->dst_mac= %d\n", classifier_val->dst_mac);*/
176 }
177 else
178 {
179 ASFVOLT_LOG(ASFVOLT_ERROR, "dst_mac should not be more than 6 bytes."
180 "actual bytes %lud\n", tmp_classifier->dst_mac.len);
181 return BAL_ERRNO__BAL_ERR_PARM;
182 }
183 }
184
185 if (classifier_val->presence_mask & BCMBAL_CLASSIFIER_ID_SRC_MAC)
186 {
187 if(tmp_classifier->src_mac.len > BCMOS_ETH_ALEN)
188 {
189 memcpy(classifier_val->src_mac.u8,
190 tmp_classifier->src_mac.data, tmp_classifier->src_mac.len);
191 /*ASFVOLT_LOG(ASFVOLT_DEBUG, "classifier_val->src_mac= %x\n", classifier_val->src_mac);*/
192 }
193 else
194 {
195 ASFVOLT_LOG(ASFVOLT_ERROR, "src_mac should not be more than 6 bytes."
196 "actual bytes %lud\n", tmp_classifier->src_mac.len);
197 return BAL_ERRNO__BAL_ERR_PARM;
198 }
199
200 }
201
202 if (classifier_val->presence_mask & BCMBAL_CLASSIFIER_ID_IP_PROTO)
203 {
204 classifier_val->ip_proto = tmp_classifier->ip_proto;
205 ASFVOLT_LOG(ASFVOLT_DEBUG, "classifier_val->ip_proto = %x\n", classifier_val->ip_proto);
206 }
207
208 if (classifier_val->presence_mask & BCMBAL_CLASSIFIER_ID_DST_IP)
209 {
210 classifier_val->dst_ip.u32 = tmp_classifier->dst_ip;
211 ASFVOLT_LOG(ASFVOLT_DEBUG, "classifier_val->dst_ip = %x\n", classifier_val->dst_ip.u32);
212 }
213
214 if (classifier_val->presence_mask & BCMBAL_CLASSIFIER_ID_SRC_IP)
215 {
216 classifier_val->src_ip.u32 = tmp_classifier->src_ip;
217 ASFVOLT_LOG(ASFVOLT_DEBUG, "classifier_val->src_ip = %x\n", classifier_val->src_ip.u32);
218 }
219
220 if (classifier_val->presence_mask & BCMBAL_CLASSIFIER_ID_SRC_PORT)
221 {
222 classifier_val->src_port = tmp_classifier->src_port;
223 ASFVOLT_LOG(ASFVOLT_DEBUG, "classifier_val->src_port = %d\n", classifier_val->src_port);
224 }
225
226 if (classifier_val->presence_mask & BCMBAL_CLASSIFIER_ID_DST_PORT)
227 {
228 classifier_val->dst_port = tmp_classifier->dst_port;
229 ASFVOLT_LOG(ASFVOLT_DEBUG, "classifier_val->dst_port = %d\n", classifier_val->dst_port);
230 }
231
232 if (classifier_val->presence_mask & BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE)
233 {
234 classifier_val->pkt_tag_type = tmp_classifier->pkt_tag_type;
235 ASFVOLT_LOG(ASFVOLT_DEBUG, "classifier_val->pkt_tag_type = %x\n", classifier_val->pkt_tag_type);
236 }
237
238 ASFVOLT_LOG(ASFVOLT_DEBUG, "classifier_val->presence_mask = %x\n", classifier_val->presence_mask);
239 }
240 else
241 {
242 ASFVOLT_LOG(ASFVOLT_ERROR, "Classifier is not present in the flow\n");
243 return BAL_ERRNO__BAL_ERR_PARM;
244 }
245
246 return BAL_ERRNO__BAL_ERR_OK;
247}
248
249/********************************************************************\
250 * Function : bal_flow_cfg_req *
251 * Description : Configure the the OLT DEVICE with flow information *
252 * using BAL Apis *
253 ********************************************************************/
254uint32_t bal_flow_cfg_set(BalFlowCfg *flow_cfg)
255{
256 bcmos_errno err = BCM_ERR_OK;
257 BalErrno bal_err = BAL_ERRNO__BAL_ERR_OK;
258 bcmbal_flow_cfg cfg; /**< declare main API struct */
259 bcmbal_flow_key key = { 0, 0}; /**< declare key */
260 bcmbal_classifier classifier_value = {};
261 bcmbal_action action_value = {};
262 bcmbal_tm_queue_ref queue_value = {};
263
264 /* build key from CLI parameters */
265 if(flow_cfg->key->has_flow_id)
266 {
267 key.flow_id = (bcmbal_flow_id) flow_cfg->key->flow_id;
268 }
269 else
270 {
271 ASFVOLT_LOG(ASFVOLT_ERROR, "Invalid Flow Id (%d)\n", flow_cfg->key->flow_id);
272 return BAL_ERRNO__BAL_ERR_PARM;
273 }
274
275
276 ASFVOLT_LOG(ASFVOLT_INFO, "Adding the flow to OLT. FlowID(%d)\n", flow_cfg->key->flow_id);
277
278 if (!flow_cfg->key->has_flow_type &&
279 ((flow_cfg->key->flow_type < BAL_FLOW_TYPE__BAL_FLOW_TYPE_UPSTREAM) ||
280 flow_cfg->key->flow_type > BAL_FLOW_TYPE__BAL_FLOW_TYPE_MULTICAST ))
281 {
282 ASFVOLT_LOG(ASFVOLT_ERROR, "Flow type is not supported (%d)\n", flow_cfg->key->flow_type);
283 return BAL_ERRNO__BAL_ERR_PARM;
284 }
285 else
286 {
287 ASFVOLT_LOG(ASFVOLT_DEBUG, "flow_type = %d\n", flow_cfg->key->flow_type);
288 key.flow_type = (bcmbal_flow_type) flow_cfg->key->flow_type;
289 }
290
291 /* init the API struct */
292 BCMBAL_CFG_INIT(&cfg, flow, key);
293
294 /* decode API parameters from grpc-c */
295 /* Admin State */
296 ASFVOLT_CFG_PROP_SET(cfg, flow, admin_state,
297 flow_cfg->data->has_admin_state,
298 flow_cfg->data->admin_state);
299 ASFVOLT_LOG(ASFVOLT_DEBUG, "admin state = %d\n", flow_cfg->data->admin_state);
300
301 /* Operational status */
302 ASFVOLT_CFG_PROP_SET(cfg, flow, oper_status,
303 flow_cfg->data->has_oper_status,
304 flow_cfg->data->oper_status);
305 ASFVOLT_LOG(ASFVOLT_DEBUG, "Oper. status = %d\n", flow_cfg->data->oper_status);
306
307 /* Access Side interface ID */
308 ASFVOLT_CFG_PROP_SET(cfg, flow, access_int_id,
309 BCMOS_TRUE,
310 flow_cfg->data->access_int_id);
311 ASFVOLT_LOG(ASFVOLT_DEBUG, "access_int_id = %d\n", flow_cfg->data->access_int_id);
312
313 /* Network interface ID */
314 ASFVOLT_CFG_PROP_SET(cfg, flow, network_int_id,
315 BCMOS_TRUE,
316 flow_cfg->data->network_int_id);
317 ASFVOLT_LOG(ASFVOLT_DEBUG, "network_int_id = %d\n", flow_cfg->data->network_int_id);
318
319 /* ONU ID */
320 if(BAL_FLOW_TYPE__BAL_FLOW_TYPE_MULTICAST != flow_cfg->key->flow_type)
321 {
322 ASFVOLT_CFG_PROP_SET(cfg, flow, sub_term_id,
323 flow_cfg->data->has_sub_term_id,
324 flow_cfg->data->sub_term_id);
325 ASFVOLT_LOG(ASFVOLT_DEBUG, "sub_term_id = %d\n", flow_cfg->data->sub_term_id);
326 }
327 else if (BAL_FLOW_TYPE__BAL_FLOW_TYPE_MULTICAST == flow_cfg->key->flow_type)
328 {
329 /* In case of Multicast the flow belongs to particular group */
330 ASFVOLT_CFG_PROP_SET(cfg, flow, group_id,
331 flow_cfg->data->has_group_id,
332 flow_cfg->data->group_id);
333 ASFVOLT_LOG(ASFVOLT_DEBUG, "group_id = %d\n", flow_cfg->data->group_id);
334 }
335
336 /*Subscriber Terminal UNI index*/
337 ASFVOLT_CFG_PROP_SET(cfg, flow, sub_term_uni_idx,
338 flow_cfg->data->has_sub_term_uni_idx,
339 flow_cfg->data->sub_term_uni_idx);
340 ASFVOLT_LOG(ASFVOLT_DEBUG, "sub_term_uni_idx = %d\n", flow_cfg->data->sub_term_uni_idx);
341
342 /*Resolve MAC*/
343 ASFVOLT_CFG_PROP_SET(cfg, flow, resolve_mac,
344 flow_cfg->data->has_resolve_mac,
345 flow_cfg->data->resolve_mac);
346 ASFVOLT_LOG(ASFVOLT_DEBUG, "resolve_mac = %d\n", flow_cfg->data->resolve_mac);
347
348 /*Gem port*/
349 ASFVOLT_CFG_PROP_SET(cfg, flow, svc_port_id,
350 flow_cfg->data->has_svc_port_id,
351 flow_cfg->data->svc_port_id);
352 ASFVOLT_LOG(ASFVOLT_DEBUG, "svc_port_id = %d\n", flow_cfg->data->svc_port_id);
353
354 /*priority*/
355 ASFVOLT_CFG_PROP_SET(cfg, flow, priority,
356 flow_cfg->data->has_priority,
357 flow_cfg->data->priority);
358 ASFVOLT_LOG(ASFVOLT_DEBUG, "priority = %d\n",flow_cfg->data->priority);
359
360 BalClassifier *tmp_classifier = (BalClassifier*)(flow_cfg->data->classifier);
361
362 if (tmp_classifier != NULL)
363 {
364 bal_err = bal_fill_classifier_cfg(tmp_classifier, &classifier_value);
365
366 if(bal_err != BAL_ERRNO__BAL_ERR_OK)
367 {
368 ASFVOLT_LOG(ASFVOLT_ERROR,
369 "Addition of flow %d failed while processing classifier\n",
370 flow_cfg->key->flow_id);
371 return bal_err;
372 }
373
374 ASFVOLT_CFG_PROP_SET(cfg, flow, classifier, BCMOS_TRUE, classifier_value);
375 }
376 else
377 {
378 ASFVOLT_LOG(ASFVOLT_DEBUG, "No Classifier for flow\n");
379 }
380
381 BalAction *tmp_action = (BalAction*)(flow_cfg->data->action);
382
383 if (tmp_action != NULL)
384 {
385 bal_err = bal_fill_action_cfg(tmp_action, &action_value);
386
387 if(bal_err != BAL_ERRNO__BAL_ERR_OK)
388 {
389 ASFVOLT_LOG(ASFVOLT_ERROR,
390 "Addition of flow %d failed while processing action\n",
391 flow_cfg->key->flow_id);
392 return bal_err;
393 }
394 ASFVOLT_CFG_PROP_SET(cfg, flow, action, BCMOS_TRUE, action_value);
395 }
396 else
397 {
398 ASFVOLT_LOG(ASFVOLT_DEBUG, "No Action for flow\n");
399 }
400
401 /*cookie*/
402 ASFVOLT_CFG_PROP_SET(cfg, flow, cookie,
403 flow_cfg->data->has_cookie,
404 flow_cfg->data->cookie);
405 ASFVOLT_LOG(ASFVOLT_DEBUG, "priority = %lx\n",flow_cfg->data->cookie);
406
407 /*Egress queue*/
408 BalTmQueueRef *tmp_que = (BalTmQueueRef*)(flow_cfg->data->queue);
409
410 if (tmp_que != NULL)
411 {
412 bal_err = bal_fill_queue_cfg(tmp_que, &queue_value);
413
414 if(bal_err != BAL_ERRNO__BAL_ERR_OK)
415 {
416 ASFVOLT_LOG(ASFVOLT_ERROR,
417 "Addition of flow %d failed while processing queue\n",
418 flow_cfg->key->flow_id);
419 return bal_err;
420 }
421 ASFVOLT_CFG_PROP_SET(cfg, flow, queue, BCMOS_TRUE, queue_value);
422 }
423 else
424 {
425 ASFVOLT_LOG(ASFVOLT_DEBUG, "No queue Information for flow");
426 }
427 /*dba_tm_sched_id*/
428 ASFVOLT_CFG_PROP_SET(cfg, flow, dba_tm_sched_id,
429 flow_cfg->data->has_dba_tm_sched_id,
430 flow_cfg->data->dba_tm_sched_id);
431 ASFVOLT_LOG(ASFVOLT_DEBUG, "tm_sched used for dba = %d\n",flow_cfg->data->dba_tm_sched_id);
432
433 err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr);
434 if(err != BCM_ERR_OK)
435 {
436 ASFVOLT_LOG(ASFVOLT_ERROR,
437 "Failed to configure the flow. FlowId(%d)\n", key.flow_id);
438 return BAL_ERRNO__BAL_ERR_INTERNAL;
439 }
440 return BAL_ERRNO__BAL_ERR_OK;
441}
442
443
444/********************************************************************\
445 * Function : bal_flow_cfg_clear *
446 * Description : Deletes/Clears the OLT DEVICE with flow
447 * information using BAL Apis *
448 ********************************************************************/
449uint32_t bal_flow_cfg_clear(BalFlowKey *flow_key)
450{
451 bcmos_errno err = BCM_ERR_OK;
452 bcmbal_flow_cfg cfg; /**< declare main API struct */
453 bcmbal_flow_key key = { }; /**< declare key */
454
455 if (flow_key->has_flow_id && flow_key->has_flow_type)
456 {
457 key.flow_id = flow_key->flow_id;
458 key.flow_type = flow_key->flow_type;
459 }
460 else
461 {
462 ASFVOLT_LOG(ASFVOLT_DEBUG, "Invalid Flow Parameters to clear FlowId(%d), FlowType(%d)\n",
463 key.flow_id, key.flow_type);
464 return BAL_ERRNO__BAL_ERR_PARM;
465 }
466
467 ASFVOLT_LOG(ASFVOLT_DEBUG, "FlowId(%d), FlowType(%d)\n", key.flow_id, key.flow_type);
468
469 /* init the API struct */
470 BCMBAL_CFG_INIT(&cfg, flow, key);
471
472 /* call API */
473 err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr);
474 if( err != BCM_ERR_OK)
475 {
476 ASFVOLT_LOG(ASFVOLT_INFO,
477 "Failed to clear the Flow. FlowID(%d) FlowType(%d)\n",
478 key.flow_id, key.flow_type);
479 return BAL_ERRNO__BAL_ERR_INTERNAL;
480 }
481 return BAL_ERRNO__BAL_ERR_OK;
482}
483
484
485/********************************************************************\
486 * Function : bal_flow_cfg_get *
487 * Description : Get flow information from BAL. *
488 ********************************************************************/
489uint32_t bal_flow_cfg_get(BalFlowKey *flow_key, BalFlowCfg *flow_cfg)
490{
491
492 bcmos_errno err = BCM_ERR_OK;
493 bcmbal_flow_cfg cfg; /**< declare main API struct */
494 bcmbal_flow_key key = { }; /**< declare key */
495
496 if (flow_key->has_flow_id && flow_key->has_flow_type)
497 {
498 key.flow_id = flow_key->flow_id;
499 key.flow_type = flow_key->flow_type;
500 }
501 else
502 {
503 ASFVOLT_LOG(ASFVOLT_DEBUG, "Invalid Flow Parameters to get cfg FlowId(%d), FlowType(%d)\n",
504 key.flow_id, key.flow_type);
505 return BAL_ERRNO__BAL_ERR_PARM;
506 }
507
508 /* init the API struct */
509 BCMBAL_CFG_INIT(&cfg, flow, key);
510
511 BCMBAL_CFG_PROP_GET(&cfg, flow, all_properties);
512
513 /* call API */
514 err = bcmbal_cfg_get(DEFAULT_ATERM_ID, &cfg.hdr);
515 if( err != BCM_ERR_OK)
516 {
517 ASFVOLT_LOG(ASFVOLT_INFO,
518 "Failed to get Flow Info. FlowID(%d) FlowType(%d)\n",
519 key.flow_id, key.flow_type);
520 return BAL_ERRNO__BAL_ERR_INTERNAL;
521 }
522
523 ASFVOLT_LOG(ASFVOLT_INFO,
524 "To-Do. Send Flow details to Adapter\n");
525
526 return BAL_ERRNO__BAL_ERR_OK;
527}