2 \brief Declaration of library functions
4 Any definitions in this file will be shared among GLUE Layer and internal Driver Stack.
12 #include "osal_typedef.h"
17 /*******************************************************************************
18 * C O M P I L E R F L A G S
19 ********************************************************************************
22 /*******************************************************************************
24 ********************************************************************************
27 #define CONFIG_POWER_SAVING_SUPPORT
28 #if WMT_UART_RX_MODE_WORK
29 #define CFG_STP_CORE_CTX_SPIN_LOCK 0
31 #define CFG_STP_CORE_CTX_SPIN_LOCK 1
38 #define STP_LOG_PKHEAD 3
39 #define STP_LOG_INFO 2
40 #define STP_LOG_WARN 1
43 extern unsigned int gStpDbgLvl;
45 #define STP_DBG_FUNC(fmt, arg...) if(gStpDbgLvl >= STP_LOG_DBG){ osal_dbg_print(PFX "%s: " fmt, __FUNCTION__ ,##arg);}
46 #define STP_INFO_FUNC(fmt, arg...) if(gStpDbgLvl >= STP_LOG_INFO){ osal_dbg_print(PFX "%s:[I] " fmt, __FUNCTION__ ,##arg);}
47 #define STP_WARN_FUNC(fmt, arg...) if(gStpDbgLvl >= STP_LOG_WARN){ osal_dbg_print(PFX "%s:[W] " fmt, __FUNCTION__ ,##arg);}
48 #define STP_ERR_FUNC(fmt, arg...) if(gStpDbgLvl >= STP_LOG_ERR){ osal_dbg_print(PFX "%s:[E] " fmt, __FUNCTION__ ,##arg);}
49 #define STP_TRC_FUNC(f) if(gStpDbgLvl >= STP_LOG_DBG){ osal_dbg_print(PFX "<%s> <%d>\n", __FUNCTION__, __LINE__);}
51 #define STP_DUMP_PACKET_HEAD(a, b, c) if(gStpDbgLvl >= STP_LOG_PKHEAD){stp_dump_data(a, b, c);}
52 #define STP_TRACE_FUNC(fmt, arg...) if(gStpDbgLvl >= STP_LOG_DBG){ osal_dbg_print(PFX "%s: " fmt, __FUNCTION__ ,##arg);}
54 #define MTKSTP_UART_FULL_MODE 0x01
55 #define MTKSTP_UART_MAND_MODE 0x02
56 #define MTKSTP_SDIO_MODE 0x04
58 #define MTKSTP_BUFFER_SIZE (16384)
60 /*To check function driver's status by the the interface*/
61 /*Operation definition*/
62 #define OP_FUNCTION_ACTIVE 0
65 #define STATUS_OP_INVALID 0
66 #define STATUS_FUNCTION_INVALID 1
68 #define STATUS_FUNCTION_ACTIVE 31
69 #define STATUS_FUNCTION_INACTIVE 32
71 #define MTKSTP_CRC_SIZE (2)
72 #define MTKSTP_HEADER_SIZE (4)
73 #define MTKSTP_SEQ_SIZE (8)
75 /*#define MTKSTP_WINSIZE (4)*/
76 #define MTKSTP_WINSIZE (7)
77 #define MTKSTP_TX_TIMEOUT (180) /*TODO: Baudrate to decide this*/
78 #define MTKSTP_RETRY_LIMIT (10)
80 #define INDEX_INC(idx) \
86 #define INDEX_DEC(idx) \
92 /*******************************************************************************
93 * E X T E R N A L R E F E R E N C E S
94 ********************************************************************************
99 /*******************************************************************************
101 ********************************************************************************
104 /*******************************************************************************
106 ********************************************************************************
108 typedef INT32 (*IF_TX)(const UINT8 *data, const UINT32 size, UINT32 *written_size);
110 typedef INT32 (*EVENT_SET)(UINT8 function_type);
111 typedef INT32 (*EVENT_TX_RESUME)(UINT8 winspace);
112 typedef INT32 (*FUNCTION_STATUS)(UINT8 type, UINT8 op);
113 typedef INT32 (*WMT_NOTIFY_FUNC_T)(UINT32 action);
114 typedef INT32 (*BTM_NOTIFY_WMT_FUNC_T)(INT32);
119 /* common interface */
122 EVENT_SET cb_event_set;
123 EVENT_TX_RESUME cb_event_tx_resume;
124 FUNCTION_STATUS cb_check_funciton_status;
144 } mtkstp_parser_state;
148 mtkstp_parser_state state;
156 } mtkstp_parser_context_struct;
160 UINT8 txseq; // last tx pkt's seq + 1
161 UINT8 txack; // last tx pkt's ack
162 UINT8 rxack; // last rx pkt's ack
163 UINT8 winspace; // current sliding window size
164 UINT8 expected_rxseq; // last rx pkt's seq + 1
166 } mtkstp_sequence_context_struct;
171 OSAL_UNSLEEPABLE_LOCK mtx;
172 UINT8 buffer[MTKSTP_BUFFER_SIZE];
175 } mtkstp_ring_buffer_struct;
179 UINT8 inband_rst_set;
180 UINT32 rx_counter; // size of current processing pkt in rx_buf[]
181 UINT8 rx_buf[MTKSTP_BUFFER_SIZE]; // input buffer of STP, room for current processing pkt
182 UINT32 tx_read; // read ptr of tx_buf[]
183 UINT32 tx_write; // write ptr of tx_buf[]
184 UINT8 tx_buf[MTKSTP_BUFFER_SIZE]; // output buffer of STP
185 UINT32 tx_start_addr[MTKSTP_SEQ_SIZE]; // ptr of each pkt in tx_buf[]
186 UINT32 tx_length[MTKSTP_SEQ_SIZE]; // length of each pkt in tx_buf[]
187 mtkstp_ring_buffer_struct ring[MTKSTP_MAX_TASK_NUM]; // ring buffers for each function driver
188 mtkstp_parser_context_struct parser; // current rx pkt's content
189 mtkstp_sequence_context_struct sequence; // state machine's current status
190 //MTK_WCN_MUTEX stp_mutex;
191 #if CFG_STP_CORE_CTX_SPIN_LOCK
192 OSAL_UNSLEEPABLE_LOCK stp_mutex;
194 OSAL_SLEEPABLE_LOCK stp_mutex;
196 //MTK_WCN_TIMER tx_timer; // timer for tx timeout handling
201 UINT8 f_enable; /* default disabled */
202 UINT8 f_ready; /* default non-ready */
203 UINT8 f_pending_type;
204 UINT8 f_coredump; /*block tx flag, for now, only when f/w assert happens, we will set this bit on*/
206 /* Flag to identify Blueztooth is Bluez/or MTK Stack*/
207 MTK_WCN_BOOL f_bluez;
208 MTK_WCN_BOOL f_dbg_en;
209 MTK_WCN_BOOL f_autorst_en;
213 /* Flag to identify STP by SDIO or UART */
216 /* Flag to indicate the last WMT CLOSE*/
217 UINT32 f_wmt_last_close;
218 }mtkstp_context_struct;
220 /*******************************************************************************
221 * P U B L I C D A T A
222 ********************************************************************************
225 /*******************************************************************************
226 * P R I V A T E D A T A
227 ********************************************************************************
231 /*******************************************************************************
232 * F U N C T I O N D E C L A R A T I O N S
233 ********************************************************************************
236 INT32 stp_send_data_no_ps(UINT8 *buffer, UINT32 length, UINT8 type);
238 /*****************************************************************************
244 * cb_func [IN] function pointers of system APIs
246 * INT32 0 = success, others = failure
247 *****************************************************************************/
248 extern INT32 mtk_wcn_stp_init(const mtkstp_callback * const cb_func);
250 /*****************************************************************************
258 * INT32 0 = success, others = failure
259 *****************************************************************************/
260 extern INT32 mtk_wcn_stp_deinit(void);
262 /*****************************************************************************
268 * value [IN] 0 = disable, others = enable
270 * INT32 0 = success, others = error
271 *****************************************************************************/
272 extern INT32 mtk_wcn_stp_enable(INT32 value);
274 /*****************************************************************************
278 * ready/non-ready STP
280 * value [IN] 0 = non-ready, others = ready
282 * INT32 0 = success, others = error
283 *****************************************************************************/
284 extern INT32 mtk_wcn_stp_ready(INT32 value);
287 /*****************************************************************************
289 * mtk_wcn_stp_coredump_start_ctrl
291 * set f/w assert flag in STP context
293 * value [IN] 0=assert end, others=assert begins
295 * INT32 0=success, others=error
296 *****************************************************************************/
297 extern INT32 mtk_wcn_stp_coredump_start_ctrl(UINT32 value);
299 /*****************************************************************************
301 * mtk_wcn_stp_coredump_start_get
303 * get f/w assert flag in STP context
307 * INT32 0= f/w assert flag is not set, others=f/w assert flag is set
308 *****************************************************************************/
309 extern INT32 mtk_wcn_stp_coredump_start_get(VOID);
312 /*****************************************************************************
314 * mtk_wcn_stp_send_data_raw
316 * send raw data to common interface, bypass STP
318 * buffer [IN] data buffer
319 * length [IN] data buffer length
320 * type [IN] subfunction type
322 * INT32 length transmitted
323 *****************************************************************************/
324 extern INT32 mtk_wcn_stp_send_data_raw(const UINT8 *buffer, const UINT32 length, const UINT8 type);
326 /*****************************************************************************
328 * mtk_wcn_stp_set_sdio_mode
330 * Set stp for SDIO mode
332 * sdio_flag [IN] sdio mode flag (TRUE:SDIO mode, FALSE:UART mode)
335 *****************************************************************************/
336 extern void mtk_wcn_stp_set_mode(UINT32 sdio_flag);
338 /*****************************************************************************
340 * mtk_wcn_stp_is_uart_fullset_mode
342 * Is stp use UART Fullset mode?
346 * MTK_WCN_BOOL TRUE:UART Fullset, FALSE:UART Fullset
347 *****************************************************************************/
348 extern MTK_WCN_BOOL mtk_wcn_stp_is_uart_fullset_mode(void);
350 /*****************************************************************************
352 * mtk_wcn_stp_is_uart_mand_mode
354 * Is stp use UART Mandatory mode?
358 * MTK_WCN_BOOL TRUE:UART Mandatory, FALSE:UART Mandatory
359 *****************************************************************************/
360 extern MTK_WCN_BOOL mtk_wcn_stp_is_uart_mand_mode(void);
363 /*****************************************************************************
365 * mtk_wcn_stp_is_sdio_mode
367 * Is stp use SDIO mode?
371 * MTK_WCN_BOOL TRUE:SDIO mode, FALSE:UART mode
372 *****************************************************************************/
373 extern MTK_WCN_BOOL mtk_wcn_stp_is_sdio_mode(void);
376 /*****************************************************************************
378 * stp_send_inband_reset
380 * To sync to oringnal stp state with f/w stp
385 *****************************************************************************/
386 extern void mtk_wcn_stp_inband_reset(void);
388 /*****************************************************************************
390 * stp_send_inband_reset
392 * To send testing command to chip
397 *****************************************************************************/
398 extern void mtk_wcn_stp_test_cmd(INT32 no);
400 /*****************************************************************************
402 * stp_send_inband_reset
404 * To control STP debugging mechanism
406 * func_no: function control, func_op: dumpping filer, func_param: dumpping parameter
409 *****************************************************************************/
410 extern void mtk_wcn_stp_debug_ctrl(INT32 func_no, INT32 func_op, INT32 func_param);
411 /*****************************************************************************
415 * flush all stp context
420 *****************************************************************************/
421 extern void mtk_wcn_stp_flush_context(void);
423 /*****************************************************************************
425 * mtk_wcn_stp_rx_queue
427 * flush all stp rx queue
432 *****************************************************************************/
433 extern void mtk_wcn_stp_flush_rx_queue(UINT32 type);
435 /*****************************************************************************
437 * set stp debugging mdoe
439 * set stp debugging mdoe
441 * dbg_mode: switch to dbg mode ?
444 *****************************************************************************/
445 extern void mtk_wcn_stp_set_dbg_mode(MTK_WCN_BOOL dbg_mode);
447 /*****************************************************************************
449 * set stp auto reset mdoe
451 * set stp auto reset mdoe
453 * auto_rst: switch to auto reset mode ?
456 *****************************************************************************/
457 extern void mtk_wcn_stp_set_auto_rst(MTK_WCN_BOOL auto_rst);
461 /*****************************************************************************
463 * mtk_wcn_stp_psm_notify_stp
465 * WMT notification to STP that power saving job is done or not
469 * 0: Sccuess Negative value: Fail
470 *****************************************************************************/
471 extern int mtk_wcn_stp_psm_notify_stp(const UINT32 action);
473 extern int mtk_wcn_stp_set_psm_state(MTKSTP_PSM_STATE_T state);
475 /*****************************************************************************
477 * mtk_wcn_stp_psm_enabla
481 * int idle_time_to_sleep: IDLE time to sleep
483 * 0: Sccuess Negative value: Fail
484 *****************************************************************************/
485 extern int mtk_wcn_stp_psm_enable(int idle_time_to_sleep);
487 /*****************************************************************************
489 * mtk_wcn_stp_psm_disable
495 * 0: Sccuess Negative value: Fail
496 *****************************************************************************/
497 extern int mtk_wcn_stp_psm_disable(void);
499 /*****************************************************************************
501 * mtk_wcn_stp_psm_reset
503 * reset STP PSM (used on whole chip reset)
507 * 0: Sccuess Negative value: Fail
508 *****************************************************************************/
509 extern int mtk_wcn_stp_psm_reset(void);
510 extern void stp_do_tx_timeout(void);
512 /*****************************************************************************
514 * mtk_wcn_stp_btm_get_dmp
516 * get stp dump related information
518 * buffer: dump placement, len: dump size
520 * 0: Success Negative Value: Fail
521 *****************************************************************************/
522 extern int mtk_wcn_stp_btm_get_dmp(char *buf, int *len);
524 extern int mtk_wcn_stp_dbg_enable(void);
526 extern int mtk_wcn_stp_dbg_disable(void);
528 extern void mtk_wcn_stp_set_if_tx_type (ENUM_STP_TX_IF_TYPE stp_if_type);
530 extern int mtk_wcn_sys_if_rx(UINT8 *data, INT32 size);
532 extern MTK_WCN_BOOL mtk_wcn_stp_dbg_level(UINT32 dbglevel);
534 extern INT32 mtk_wcn_stp_dbg_dump_package(VOID);
536 extern int stp_drv_init(void);
538 extern void stp_drv_exit(void);
540 extern INT32 mtk_wcn_stp_dbg_log_ctrl(UINT32 on);
542 extern INT32 mtk_wcn_stp_coredump_flag_ctrl(UINT32 on);
544 extern INT32 mtk_wcn_stp_coredump_flag_get(VOID);
545 extern INT32 mtk_wcn_stp_notify_sleep_for_thermal(void);
548 extern INT32 mtk_wcn_stp_set_wmt_last_close(UINT32 value);
550 /*******************************************************************************
552 ********************************************************************************
555 #endif /* _STP_CORE_H_ */