blob: 4ea85c5235c4c89f5c80aca5bd72697188935845 [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/* Define the top level Doxygen groups. */
33
34/**
35 * @defgroup core BAL Core Engine
36 *
37 * @defgroup apps BAL Utils
38 *
39 * @defgroup lib BAL Libraries
40 *
41 */
42
43/**
44 * @file bal_msg.h
45 *
46 * @brief Include files and miscellaneous macros for the BAL messaging
47 *
48 */
49
50#ifndef BALMSG_H
51#define BALMSG_H
52
53#include <bal_objs.h>
54#include <bal_msg_type.h>
55
56
57/*******************************************************************
58 **
59 ** BAL message header helpers
60 **
61 *******************************************************************
62 */
63
64/*
65 * Underlying msg_send timeout units in uS (micro seconds)
66 */
67#define BCMBAL_MSG_TIMEOUT_1_SEC (1000000)
68
69/*
70 * Get a pointer to the message payload given the bcmos_msg pointer
71 */
72static inline void *bcmbal_payload_ptr_get(bal_comm_msg_hdr *_m)
73{
74 /* payload starts from BAL communication header */
75 return (void *)_m;
76}
77
78/*
79 * Get a pointer to the BAL header given the message payload pointer
80 */
81static inline bal_comm_msg_hdr *bcmbal_bal_hdr_get(void *_msg_payload_ptr)
82{
83 /* payload starts from BAL communication header */
84 return (bal_comm_msg_hdr *)_msg_payload_ptr;
85}
86
87/*
88 * Get a pointer to the BAL header given the bcmos header pointer
89 */
90static inline bal_comm_msg_hdr *bcmbal_bal_hdr_get_by_bcmos_hdr(bcmos_msg *m)
91{
92 return container_of(m, bal_comm_msg_hdr, m);
93}
94
95/*
96 * Get a pointer to the BCMOS header given the message payload pointer
97 */
98static inline bcmos_msg *bcmbal_bcmos_hdr_get(void *_msg_payload_ptr)
99{
100 return &(bcmbal_bal_hdr_get(_msg_payload_ptr)->m);
101}
102
103/*
104 * Set the BAL header parameters given the message payload pointer
105 */
106static inline void bcmbal_msg_hdr_set(void *_msg_payload_ptr,
107 bcmos_msg_id _type_major,
108 bcmbal_msg_type _type_minor,
109 bal_subsystem _sender_subsys,
110 bcmbal_obj_id _msg_id_obj,
111 uint16_t _msg_id_oper,
112 uint32_t _ex_id)
113{
114 bcmos_msg *os_msg = bcmbal_bcmos_hdr_get(_msg_payload_ptr);
115 bal_comm_msg_hdr *bal_hdr = bcmbal_bal_hdr_get(_msg_payload_ptr);
116
117 /*
118 * set up the bcmos_msg header fields
119 */
120 os_msg->data = (void *)((char *)(bcmbal_bcmos_hdr_get(_msg_payload_ptr)) + sizeof(bcmos_msg));
121 os_msg->start = os_msg->data;
122 os_msg->type = _type_major;
123 os_msg->instance = 0;
124 os_msg->sender = BCMOS_MODULE_ID_NONE; /* doesn't matter */
125
126 /*
127 * set up the bal msg header fields
128 */
129 bal_hdr->version_major = BAL_HDR_VERSION_MAJOR;
130 bal_hdr->version_minor = BAL_HDR_VERSION_MINOR;
131 bal_hdr->msg_type = _type_minor;
132 bal_hdr->msg_id = ((bal_hdr->msg_id & 0x0000FFFF) | ((_msg_id_oper & 0x0000FFFF) << 16));
133 bal_hdr->msg_id = ((bal_hdr->msg_id & 0xFFFF0000) | (_msg_id_obj & 0x0000FFFF));
134 bal_hdr->ex_id = _ex_id;
135 bal_hdr->sender = _sender_subsys;
136 bal_hdr->timestamp = bcmos_timestamp();
137}
138
139/*
140 * Get the sender field in the BAL header given the message pointer
141 */
142static inline bal_subsystem bcmbal_sender_get(void *_msg_payload_ptr)
143{
144 return bcmbal_bal_hdr_get(_msg_payload_ptr)->sender;
145}
146
147/*
148 * Set the sender field in the BAL header given the message pointer
149 */
150static inline void bcmbal_sender_set(void *_msg_payload_ptr, bal_subsystem _sender_subsys)
151{
152 bcmbal_bal_hdr_get(_msg_payload_ptr)->sender = _sender_subsys;
153}
154
155/*
156 * Get the top level type field in the BAL header given the message pointer
157 */
158static inline bcmos_msg_id bcmbal_type_major_get(void *_msg_payload_ptr)
159{
160 return bcmbal_bcmos_hdr_get(_msg_payload_ptr)->type;
161}
162
163/*
164 * Set the top level type field in the BAL header given the message pointer
165 */
166static inline void bcmbal_type_major_set(void *_msg_payload_ptr, bcmos_msg_id _type_major)
167{
168 bcmbal_bcmos_hdr_get(_msg_payload_ptr)->type = _type_major;
169}
170
171/*
172 * Get the inner type field in the BAL header given the message pointer
173 */
174static inline bcmbal_msg_type bcmbal_type_minor_get(void *_msg_payload_ptr)
175{
176 return bcmbal_bal_hdr_get(_msg_payload_ptr)->msg_type;
177}
178
179/*
180 * Set the inner type field in the BAL header given the message pointer
181 */
182static inline void bcmbal_type_minor_set(void *_msg_payload_ptr, bcmbal_msg_type _type_minor)
183{
184 bcmbal_bal_hdr_get(_msg_payload_ptr)->msg_type = _type_minor;
185}
186
187
188/*
189 * Get the msg_id_oper field in the BAL header given the message pointer
190 */
191static inline uint16_t bcmbal_msg_id_oper_get(void *_msg_payload_ptr)
192{
193 return ((bcmbal_bal_hdr_get(_msg_payload_ptr)->msg_id & 0xFFFF0000) >> 16);
194}
195
196/*
197 * Set the msg_id_oper field in the BAL header given the message pointer
198 */
199static inline void bcmbal_msg_id_oper_set(void *_msg_payload_ptr, uint16_t _msg_id_oper)
200{
201 bcmbal_bal_hdr_get(_msg_payload_ptr)->msg_id =
202 ((bcmbal_bal_hdr_get(_msg_payload_ptr)->msg_id & 0x0000FFFF) | ((_msg_id_oper & 0x0000FFFF) << 16));
203}
204
205/*
206 * Get the msg_id_obj field in the BAL header given the message pointer
207 */
208static inline bcmbal_obj_id bcmbal_msg_id_obj_get(void *_msg_payload_ptr)
209{
210 return (bcmbal_bal_hdr_get(_msg_payload_ptr)->msg_id & 0x0000FFFF );
211}
212
213/*
214 * Set the msg_id_obj field in the BAL header given the message pointer
215 */
216static inline void bcmbal_msg_id_obj_set(void *_msg_payload_ptr, bcmbal_obj_id _msg_id_obj)
217{
218 bcmbal_bal_hdr_get(_msg_payload_ptr)->msg_id =
219 ((bcmbal_bal_hdr_get(_msg_payload_ptr)->msg_id & 0xFFFF0000) | (_msg_id_obj & 0x0000FFFF));
220}
221
222/*
223 * Get the ex_id field in the BAL header given the message pointer
224 */
225static inline uint32_t bcmbal_ex_id_get(void *_msg_payload_ptr)
226{
227 return bcmbal_bal_hdr_get(_msg_payload_ptr)->ex_id;
228}
229
230/*
231 * Set the ex_id field in the BAL header given the message pointer
232 */
233static inline void bcmbal_ex_id_set(void *_msg_payload_ptr, uint32_t _ex_id)
234{
235 bcmbal_bal_hdr_get(_msg_payload_ptr)->ex_id = _ex_id;
236}
237
238/*
239 * Get the major version field in the BAL header given the message pointer
240 */
241static inline uint16_t bcmbal_major_version_get(void *_msg_payload_ptr)
242{
243 return bcmbal_bal_hdr_get(_msg_payload_ptr)->version_major;
244}
245
246/*
247 * Set the major version field in the BAL header given the message pointer
248 */
249static inline void bcmbal_major_version_set(void *_msg_payload_ptr, uint16_t _version_major)
250{
251 bcmbal_bal_hdr_get(_msg_payload_ptr)->version_major = _version_major;
252}
253
254/*
255 * Get the minor version field in the BAL header given the message pointer
256 */
257static inline uint16_t bcmbal_minor_version_get(void *_msg_payload_ptr)
258{
259 return bcmbal_bal_hdr_get(_msg_payload_ptr)->version_minor;
260}
261
262/*
263 * Set the minor version field in the BAL header given the message pointer
264 */
265static inline void bcmbal_minor_version_set(void *_msg_payload_ptr, uint16_t _version_major)
266{
267 bcmbal_bal_hdr_get(_msg_payload_ptr)->version_major = _version_major;
268}
269
270/*
271 * Get the scratchpad field in the BAL header given the message pointer
272 */
273static inline void *bcmbal_scratchpad_get(void *_msg_payload_ptr)
274{
275 return bcmbal_bal_hdr_get(_msg_payload_ptr)->scratchpad;
276}
277
278/*
279 * Set the scratchpad field in the BAL header given the message pointer
280 */
281static inline void bcmbal_scratchpad_set(void *_msg_payload_ptr, void *_scratchpad)
282{
283 bcmbal_bal_hdr_get(_msg_payload_ptr)->scratchpad = _scratchpad;
284}
285
286/*
287 * Allocate a BAL message given the payload pointer
288 */
289static inline void *bcmbal_msg_calloc(uint32_t _msg_payload_size)
290{
291 /* Payload includes comm header */
292 bal_comm_msg_hdr *m = bcmos_calloc(_msg_payload_size);
293 if (NULL == m)
294 return NULL;
295 return bcmbal_payload_ptr_get(m);
296}
297
298/*
299 * Free a BAL message given the payload pointer
300 */
301static inline void bcmbal_msg_free(void *msg)
302{
303 return bcmos_msg_free(bcmbal_bcmos_hdr_get(msg));
304}
305
306/*
307 * External functions implemented in bal_msg.c
308 */
309
310/*
311 * Clone BAL message
312 * Returns payload_ptr of the clone
313 */
314void *bcmbal_msg_clone(void *bal_obj);
315
316/*
317 * Send a BAL message given the payload pointer
318 */
319bcmos_errno bcmbal_msg_send(bcmos_msg_queue *queue, void *msg_payload, bcmos_msg_send_flags flags);
320
321/*
322 * Call callback in the context of the target module and pass it the BAL message pointer
323 */
324bcmos_errno bcmbal_msg_call(void *msg_payload, bcmos_module_id module, F_bcmos_msg_handler cb, bcmos_msg_send_flags flags);
325
326/*
327 * Receive a BAL message given the payload pointer
328 *
329 * NOTE: The timeout argument is in units of uS (micro seconds). Use the #defined timeout values above.
330 *
331 */
332bcmos_errno bcmbal_msg_recv(bcmos_msg_queue *queue, uint32_t timeout, void **msg_payload);
333
334/** Get packed bal_comm_msg_hdr length */
335int32_t bcmbal_bal_msg_hdr_get_packed_length(void);
336
337/** Pack a BAL message header to a byte stream */
338bcmos_errno bcmbal_bal_msg_hdr_pack(const bal_comm_msg_hdr *msg, bcmbal_buf *buf);
339
340/** Unpack a BAL message header from a byte stream */
341bcmos_errno bcmbal_bal_msg_hdr_unpack(bal_comm_msg_hdr *msg, bcmbal_buf *buf);
342
343/** Peek exchange_id in the received message without unpacking */
344bcmos_errno bcmbal_bal_msg_peek_ex_id(bcmos_msg *msg, uint32_t *ex_id);
345
346#endif /* #ifndef BALMSG_H */
347
348
349