blob: 0e1a8e5c14d69df106ed99a1728c17e22508126c [file] [log] [blame]
Shad Ansari2f7f9be2017-06-07 13:34:53 -07001/******************************************************************************
2 *
3 * <:copyright-BRCM:2016:DUAL/GPL:standard
4 *
5 * Copyright (c) 2016 Broadcom
6 * All Rights Reserved
7 *
8 * Unless you and Broadcom execute a separate written software license
9 * agreement governing use of this software, this software is licensed
10 * to you under the terms of the GNU General Public License version 2
11 * (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php,
12 * with the following added to such license:
13 *
14 * As a special exception, the copyright holders of this software give
15 * you permission to link this software with independent modules, and
16 * to copy and distribute the resulting executable under terms of your
17 * choice, provided that you also meet, for each linked independent
18 * module, the terms and conditions of the license of that module.
19 * An independent module is a module which is not derived from this
20 * software. The special exception does not apply to any modifications
21 * of the software.
22 *
23 * Not withstanding the above, under no circumstances may you combine
24 * this software in any way with any other Broadcom software provided
25 * under a license other than the GPL, without Broadcom's express prior
26 * written consent.
27 *
28 * :>
29 *
30 *****************************************************************************/
31
32/**
33 * @file fsm_common.c
34 * @brief Common code to support the BAL access terminal FSMs
35 *
36 * @addtogroup core
37 */
38
39/*@{*/
40
41/*--- project includes ---*/
42#include <bcmos_system.h>
43#include <acc_term_fsm.h>
44#include <bal_msg.h>
45#include <bal_api.h>
46#include "bal_worker.h"
47#include "bal_mac_util.h"
48#include "bal_switch_util.h"
49#include <bal_osmsg.h>
50#include <fsm_common.h>
51
52#ifdef ENABLE_LOG
53#include <bcm_dev_log.h>
54#endif
55
56
57/*****************************************************************************/
58/**
59 * @brief Send a management message response
60 *
61 * A Worker module function that sends the specified message to the
62 * BAL Public API.
63 *
64 * @param cmd_status The results of the command associated with the message
65 *
66 * @param msg_payload A pointer to the message to be sent
67 *
68 * @param oper_type The operation type of the object in this response
69 *
70 * @param log_id The log id of the calling component
71 *
72 * @returns bcmos_errno
73 *
74 *****************************************************************************/
75bcmos_errno mgmt_msg_send_balapi_rsp(bcmos_errno cmd_status,
76 void *msg_payload,
77 bcmbal_obj_msg_type oper_type,
78 dev_log_id log_id)
79{
80
81 bcmos_errno ret = BCM_ERR_OK;
82
83 /* Parameter checks */
84 BUG_ON(NULL == msg_payload);
85
86 BCM_LOG(DEBUG, log_id, "sending rsp message to the public api (payload at %p)\n",
87 msg_payload);
88
89 /*
90 * Send the response back to the BAL Public API backend
91 */
92 bcmbal_msg_hdr_set(msg_payload,
93 bcmbal_type_major_get(msg_payload),
94 BAL_MSG_TYPE_RSP,
95 BAL_SUBSYSTEM_CORE,
96 bcmbal_msg_id_obj_get(msg_payload),
97 bcmbal_msg_id_oper_get(msg_payload),
98 bcmbal_ex_id_get(msg_payload));
99
100 /* Return the command status to the Public API backend */
101 ((bcmbal_obj *)(msg_payload))->status = cmd_status;
102
103 ((bcmbal_obj *)(msg_payload))->dir = BCMBAL_OBJ_MSG_DIR_RESPONSE;
104
105 ((bcmbal_obj *)(msg_payload))->type = oper_type;
106
107 if(BCM_ERR_OK != cmd_status)
108 {
109 ((bcmbal_obj *)(msg_payload))->presence_mask = 0;
110 }
111
112 /* Send message, but don't free it. It is still being used by FSM */
113 if(BCM_ERR_OK != (ret = bcmbal_msg_send(p_bal_core_to_api_queue, msg_payload, BCMOS_MSG_SEND_NO_FREE_ON_ERROR)))
114 {
115 BCM_LOG(ERROR, log_id, "msg_send failed to send rsp to core (error:%s)\n",
116 bcmos_strerror(ret));
117 }
118 else
119 {
120 BCM_LOG(DEBUG, log_id, "RSP message sent to the public api with status=%s\n",
121 bcmos_strerror(cmd_status));
122 }
123
124 return ret;
125
126}
127
128
129/*****************************************************************************/
130/**
131 * @brief Send a management message indication
132 *
133 * A Worker module function that sends the specified message to the
134 * BAL Public API.
135 *
136 * @param cmd_status The results of the command associated with the message
137 *
138 * @param is_auto_ind Set to BCMOS_TRUE if the indication to be sent is an AUTO IND
139 *
140 * @param msg_payload A pointer to the message to be sent (a BAL object!) (may be NULL)
141 *
142 * @param log_id The log id of the calling component
143 *
144 * @returns bcmos_errno
145 *
146 *****************************************************************************/
147static bcmos_errno _mgmt_msg_send_balapi_ind(bcmos_errno cmd_status,
148 bcmos_bool is_auto_ind,
149 void *msg_payload, /* If this is NULL, there is no message body */
150 dev_log_id log_id)
151{
152
153 bcmos_errno ret = BCM_ERR_OK;
154 uint16_t payload_size;
155 void *p_ind_msg;
156 bcmbal_obj_id obj_type;
157
158 if(NULL == msg_payload)
159 {
160 obj_type = BCMBAL_OBJ_ID_ANY;
161 payload_size = sizeof(bcmbal_obj);
162 }
163 else
164 {
165 switch(((bcmbal_obj *)msg_payload)->obj_type)
166 {
167 case (BCMBAL_OBJ_ID_FLOW):
168 {
169 payload_size = sizeof(bcmbal_flow_cfg);
170 break;
171 }
172
173 case (BCMBAL_OBJ_ID_ACCESS_TERMINAL):
174 {
175 payload_size = sizeof(bcmbal_access_terminal_cfg);
176 break;
177 }
178
179 case (BCMBAL_OBJ_ID_INTERFACE):
180 {
181 payload_size = sizeof(bcmbal_interface_cfg);
182 break;
183 }
184
185 case (BCMBAL_OBJ_ID_SUBSCRIBER_TERMINAL):
186 {
187 payload_size = sizeof(bcmbal_subscriber_terminal_cfg);
188 break;
189 }
190
191 case (BCMBAL_OBJ_ID_GROUP):
192 {
193 payload_size = sizeof(bcmbal_group_cfg);
194 break;
195 }
196
197 case (BCMBAL_OBJ_ID_TM_SCHED):
198 {
199 payload_size = sizeof(bcmbal_tm_sched_cfg);
200 break;
201 }
202
203 case (BCMBAL_OBJ_ID_TM_QUEUE):
204 {
205 payload_size = sizeof(bcmbal_tm_queue_cfg);
206 break;
207 }
208
209 default:
210 {
211 BCM_LOG(ERROR, log_id, "indication for object (%d) not supported\n",
212 ((bcmbal_obj *)msg_payload)->obj_type);
213 ret = BCM_ERR_PARM;
214 goto out;
215 }
216 }
217
218 }
219
220 p_ind_msg = bcmbal_msg_calloc(payload_size);
221
222 if(NULL == msg_payload)
223 {
224 ((bcmbal_obj *)p_ind_msg)->obj_type = obj_type;
225 }
226 else
227 {
228 memcpy(p_ind_msg, msg_payload, payload_size);
229 }
230
231 /*
232 * Send the indication back to the BAL Public API backend
233 */
234 bcmbal_msg_hdr_set(p_ind_msg,
235 BCMBAL_MGMT_API_IND_MSG,
236 (BCMOS_TRUE == is_auto_ind) ? BAL_MSG_TYPE_AUTO_IND : BAL_MSG_TYPE_IND,
237 BAL_SUBSYSTEM_CORE,
238 ((bcmbal_obj *)p_ind_msg)->obj_type,
239 0,
240 0);
241
242 /* Return the command status to the Public API backend */
243 ((bcmbal_obj *)(p_ind_msg))->status = cmd_status;
244
245 ((bcmbal_obj *)(p_ind_msg))->type = BCMBAL_OBJ_MSG_TYPE_GET;
246 ((bcmbal_obj *)(p_ind_msg))->dir = BCMBAL_OBJ_MSG_DIR_RESPONSE;
247
248 BCM_LOG(DEBUG, log_id, "sending IND message to the public api (payload at %p)\n", p_ind_msg);
249
250 if(BCM_ERR_OK != (ret = bcmbal_msg_send(p_bal_core_to_api_ind_queue, p_ind_msg, BCMOS_MSG_SEND_AUTO_FREE)))
251 {
252 BCM_LOG(ERROR, log_id, "msg_send failed to send IND to public API (%s)\n", bcmos_strerror(ret));
253 }
254 else
255 {
256 BCM_LOG(DEBUG, log_id, "IND message sent to the public api with status=%s\n",
257 bcmos_strerror(cmd_status));
258 }
259
260 out:
261 return ret;
262
263}
264
265bcmos_errno mgmt_msg_send_balapi_ind(bcmos_errno cmd_status,
266 void *msg_payload, /* If this is NULL, there is no message body */
267 dev_log_id log_id)
268{
269
270 return _mgmt_msg_send_balapi_ind(cmd_status,
271 BCMOS_FALSE,
272 msg_payload,
273 log_id);
274}
275
276bcmos_errno mgmt_msg_send_balapi_auto_ind(bcmos_errno cmd_status,
277 void *msg_payload, /* If this is NULL, there is no message body */
278 dev_log_id log_id)
279{
280
281 return _mgmt_msg_send_balapi_ind(cmd_status,
282 BCMOS_TRUE,
283 msg_payload,
284 log_id);
285}
286
287/*****************************************************************************/
288/**
289 * @brief Create and Start the FSM timer
290 *
291 * @param p_timer_inst A pointer to an instance of a timer data structure
292 *
293 * @param p_inst An opaque pointer to an FSM instance to be passed to the timer
294 * expiry handler
295 *
296 * @param p_timer_expiry_handler A timer expiry handler function
297 *
298 * @param delay The delay interval (in mS) for this timer to run before the
299 * expiry handler is called
300 *
301 * @param log_id The log_id to use when logging errors encountered in this
302 * function
303 *
304 * @returns bcmos_errno
305 */
306bcmos_errno fsm_timer_start(bcmos_timer *p_timer_inst,
307 void *p_inst,
308 F_bcmos_timer_handler p_timer_expiry_handler,
309 uint32_t delay, /* delay is in mS */
310 dev_log_id log_id)
311{
312
313 bcmos_errno ret = BCM_ERR_OK;
314 bcmos_timer_parm timer_spec;
315
316 /* Parameter checks */
317 BUG_ON(p_inst == NULL);
318 BUG_ON(p_timer_expiry_handler == NULL);
319 BUG_ON(p_timer_inst == NULL);
320
321
322 /* Create bcm_os timer */
323 timer_spec.owner = BCMOS_MODULE_ID_WORKER_MGMT;
324 timer_spec.handler = p_timer_expiry_handler;
325 timer_spec.data = (long) p_inst;
326 timer_spec.periodic = BCMOS_FALSE;
327
328 if (BCM_ERR_OK != bcmos_timer_create(p_timer_inst, &timer_spec))
329 {
330 BCM_LOG(ERROR, log_id, "Can't create timer for FSM\n");
331 ret = BCM_ERR_NORES;
332 }
333 else
334 {
335 /* Start the timer. Timer resolution is in uS*/
336 bcmos_timer_start(p_timer_inst, delay*1000);
337 }
338
339 return ret;
340
341}
342
343/*****************************************************************************/
344/**
345 * @brief Stop and delete the specified FSM timer
346 *
347 * @param p_timer_inst A pointer to an instance of a timer data structure
348 *
349 */
350void fsm_timer_stop(bcmos_timer *p_timer_inst)
351{
352 /* Parameter checks */
353 BUG_ON(p_timer_inst == NULL);
354
355 bcmos_timer_destroy(p_timer_inst);
356}
357
358/*@}*/