import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / connectivity / conn_soc / common / core / include / stp_core.h
CommitLineData
6fa3eb70
S
1/*
2* Copyright (C) 2011-2014 MediaTek Inc.
3*
4* This program is free software: you can redistribute it and/or modify it under the terms of the
5* GNU General Public License version 2 as published by the Free Software Foundation.
6*
7* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9* See the GNU General Public License for more details.
10*
11* You should have received a copy of the GNU General Public License along with this program.
12* If not, see <http://www.gnu.org/licenses/>.
13*/
14
15/*! \file
16 \brief Declaration of library functions
17
18 Any definitions in this file will be shared among GLUE Layer and internal Driver Stack.
19*/
20
21
22
23#ifndef _STP_CORE_H
24#define _STP_CORE_H
25
26#include "osal_typedef.h"
27#include "osal.h"
28#include "stp_exp.h"
29#include "psm_core.h"
30#include "btm_core.h"
31#include "stp_btif.h"
32/*******************************************************************************
33* C O M P I L E R F L A G S
34********************************************************************************
35*/
36#define CFG_STP_CORE_CTX_SPIN_LOCK (0)
37
38#define WMT_LTE_COEX_FLAG (0x16)
39
40/*configure using SPINLOCK or just mutex for STP-CORE tx*/
41/*******************************************************************************
42* M A C R O S
43********************************************************************************
44*/
45
46#define CONFIG_POWER_SAVING_SUPPORT
47
48
49#define PFX "[STP] "
50#define STP_LOG_DBG 4
51#define STP_LOG_PKHEAD 3
52#define STP_LOG_INFO 2
53#define STP_LOG_WARN 1
54#define STP_LOG_ERR 0
55
56extern unsigned int gStpDbgLvl;
57
58#define STP_DBG_FUNC(fmt, arg...) if(gStpDbgLvl >= STP_LOG_DBG){ osal_dbg_print(PFX "%s: " fmt, __FUNCTION__ ,##arg);}
59#define STP_INFO_FUNC(fmt, arg...) if(gStpDbgLvl >= STP_LOG_INFO){ osal_dbg_print(PFX "%s:[I] " fmt, __FUNCTION__ ,##arg);}
60#define STP_WARN_FUNC(fmt, arg...) if(gStpDbgLvl >= STP_LOG_WARN){ osal_dbg_print(PFX "%s:[W] " fmt, __FUNCTION__ ,##arg);}
61#define STP_ERR_FUNC(fmt, arg...) if(gStpDbgLvl >= STP_LOG_ERR){ osal_dbg_print(PFX "%s:[E] " fmt, __FUNCTION__ ,##arg);}
62#define STP_TRC_FUNC(f) if(gStpDbgLvl >= STP_LOG_DBG){ osal_dbg_print(PFX "<%s> <%d>\n", __FUNCTION__, __LINE__);}
63
64#define STP_DUMP_PACKET_HEAD(a, b, c) if(gStpDbgLvl >= STP_LOG_PKHEAD){stp_dump_data(a, b, c);}
65#define STP_TRACE_FUNC(fmt, arg...) if(gStpDbgLvl >= STP_LOG_DBG){ osal_dbg_print(PFX "%s: " fmt, __FUNCTION__ ,##arg);}
66
67#define STP_MODE_BIT(x) (0x1UL << x)
68#define MTKSTP_UART_FULL_MODE STP_MODE_BIT(0)
69#define MTKSTP_UART_MAND_MODE STP_MODE_BIT(1)
70#define MTKSTP_BTIF_FULL_MODE STP_MODE_BIT(2)
71#define MTKSTP_BTIF_MAND_MODE STP_MODE_BIT(3)
72#define MTKSTP_SDIO_MODE STP_MODE_BIT(4)
73
74#define MTKSTP_BUFFER_SIZE (16384)
75
76/*To check function driver's status by the the interface*/
77/*Operation definition*/
78#define OP_FUNCTION_ACTIVE 0
79
80/*Driver's status*/
81#define STATUS_OP_INVALID 0
82#define STATUS_FUNCTION_INVALID 1
83
84#define STATUS_FUNCTION_ACTIVE 31
85#define STATUS_FUNCTION_INACTIVE 32
86
87#define MTKSTP_CRC_SIZE (2)
88#define MTKSTP_HEADER_SIZE (4)
89#define MTKSTP_SEQ_SIZE (8)
90
91/*#define MTKSTP_WINSIZE (4)*/
92#define MTKSTP_WINSIZE (7)
93#define MTKSTP_TX_TIMEOUT (180) /*TODO: Baudrate to decide this*/
94#define MTKSTP_RETRY_LIMIT (10)
95
96#define INDEX_INC(idx) \
97{ \
98 idx++; \
99 idx &= 0x7; \
100}
101
102#define INDEX_DEC(idx) \
103{ \
104 idx--; \
105 idx &= 0x7; \
106}
107
108/*******************************************************************************
109* E X T E R N A L R E F E R E N C E S
110********************************************************************************
111*/
112
113
114
115/*******************************************************************************
116* C O N S T A N T S
117********************************************************************************
118*/
119
120/*******************************************************************************
121* D A T A T Y P E S
122********************************************************************************
123*/
124typedef INT32 (*IF_TX)(const UINT8 *data, const UINT32 size, UINT32 *written_size);
125/* event/signal */
126typedef INT32 (*EVENT_SET)(UINT8 function_type);
127typedef INT32 (*EVENT_TX_RESUME)(UINT8 winspace);
128typedef INT32 (*FUNCTION_STATUS)(UINT8 type, UINT8 op);
129typedef INT32 (*WMT_NOTIFY_FUNC_T)(UINT32 action);
130typedef INT32 (*BTM_NOTIFY_WMT_FUNC_T)(INT32);
131
132#if CFG_STP_CORE_CTX_SPIN_LOCK
133typedef OSAL_UNSLEEPABLE_LOCK STP_CTX_LOCK, *PSTP_CTX_LOCK;
134#else
135typedef OSAL_SLEEPABLE_LOCK STP_CTX_LOCK, *PSTP_CTX_LOCK;
136#endif
137
138
139typedef struct
140{
141 /* common interface */
142 IF_TX cb_if_tx;
143 /* event/signal */
144 EVENT_SET cb_event_set;
145 EVENT_TX_RESUME cb_event_tx_resume;
146 FUNCTION_STATUS cb_check_funciton_status;
147}mtkstp_callback;
148
149typedef enum
150{
151 MTKSTP_SYNC = 0,
152 MTKSTP_SEQ,
153 MTKSTP_ACK,
154 MTKSTP_NAK,
155 MTKSTP_TYPE,
156 MTKSTP_LENGTH,
157 MTKSTP_CHECKSUM,
158 MTKSTP_DATA,
159 MTKSTP_CRC1,
160 MTKSTP_CRC2,
161 MTKSTP_RESYNC1,
162 MTKSTP_RESYNC2,
163 MTKSTP_RESYNC3,
164 MTKSTP_RESYNC4,
165 MTKSTP_FW_MSG,
166} mtkstp_parser_state;
167
168typedef struct
169{
170 mtkstp_parser_state state;
171 UINT8 seq;
172 UINT8 ack;
173 UINT8 nak;
174 UINT8 type;
175 UINT16 length;
176 UINT8 checksum;
177 UINT16 crc;
178#if 1
179 UINT8 wmtsubtype;
180#endif
181} mtkstp_parser_context_struct;
182
183typedef struct
184{
185 UINT8 txseq; // last tx pkt's seq + 1
186 UINT8 txack; // last tx pkt's ack
187 UINT8 rxack; // last rx pkt's ack
188 UINT8 winspace; // current sliding window size
189 UINT8 expected_rxseq; // last rx pkt's seq + 1
190 UINT8 retry_times;
191} mtkstp_sequence_context_struct;
192
193typedef struct
194{
195 //MTK_WCN_MUTEX mtx;
196 OSAL_UNSLEEPABLE_LOCK mtx;
197 UINT8 buffer[MTKSTP_BUFFER_SIZE];
198 UINT32 read_p;
199 UINT32 write_p;
200} mtkstp_ring_buffer_struct;
201
202typedef struct
203{
204 UINT8 inband_rst_set;
205 UINT32 rx_counter; // size of current processing pkt in rx_buf[]
206 UINT8 rx_buf[MTKSTP_BUFFER_SIZE]; // input buffer of STP, room for current processing pkt
207 UINT32 tx_read; // read ptr of tx_buf[]
208 UINT32 tx_write; // write ptr of tx_buf[]
209 UINT8 tx_buf[MTKSTP_BUFFER_SIZE]; // output buffer of STP
210 UINT32 tx_start_addr[MTKSTP_SEQ_SIZE]; // ptr of each pkt in tx_buf[]
211 UINT32 tx_length[MTKSTP_SEQ_SIZE]; // length of each pkt in tx_buf[]
212 mtkstp_ring_buffer_struct ring[MTKSTP_MAX_TASK_NUM]; // ring buffers for each function driver
213 mtkstp_parser_context_struct parser; // current rx pkt's content
214 mtkstp_sequence_context_struct sequence; // state machine's current status
215 //MTK_WCN_MUTEX stp_mutex;
216 //OSAL_UNSLEEPABLE_LOCK stp_mutex;
217 STP_CTX_LOCK stp_mutex;
218 //MTK_WCN_TIMER tx_timer; // timer for tx timeout handling
219 OSAL_TIMER tx_timer;
220
221 MTKSTP_PSM_T *psm;
222 MTKSTP_BTM_T *btm;
223 UINT8 f_enable; /* default disabled */
224 UINT8 f_ready; /* default non-ready */
225 UINT8 f_pending_type;
226 UINT8 f_coredump; /*block tx flag, for now, only when f/w assert happens, we will set this bit on*/
227 UINT8 en_coredump;
228 /* Flag to identify Blueztooth is Bluez/or MTK Stack*/
229 MTK_WCN_BOOL f_bluez;
230 MTK_WCN_BOOL f_dbg_en;
231 MTK_WCN_BOOL f_autorst_en;
232
233
234
235 /* Flag to identify STP by SDIO or UART */
236 UINT32 f_mode;
237
238 /* Flag to indicate the last WMT CLOSE*/
239 UINT32 f_wmt_last_close;
240
241 /* Flag to indicate evt err has triggered assert or not*/
242 UINT32 f_evt_err_assert;
243}mtkstp_context_struct;
244
245/*******************************************************************************
246* P U B L I C D A T A
247********************************************************************************
248*/
249
250/*******************************************************************************
251* P R I V A T E D A T A
252********************************************************************************
253*/
254
255
256/*******************************************************************************
257* F U N C T I O N D E C L A R A T I O N S
258********************************************************************************
259*/
260
261INT32 stp_send_data_no_ps(UINT8 *buffer, UINT32 length, UINT8 type);
262
263/*****************************************************************************
264* FUNCTION
265* mtk_wcn_stp_init
266* DESCRIPTION
267* init STP kernel
268* PARAMETERS
269* cb_func [IN] function pointers of system APIs
270* RETURNS
271* INT32 0 = success, others = failure
272*****************************************************************************/
273extern INT32 mtk_wcn_stp_init(const mtkstp_callback * const cb_func);
274
275/*****************************************************************************
276* FUNCTION
277* mtk_wcn_stp_deinit
278* DESCRIPTION
279* deinit STP kernel
280* PARAMETERS
281* void
282* RETURNS
283* INT32 0 = success, others = failure
284*****************************************************************************/
285extern INT32 mtk_wcn_stp_deinit(void);
286
287/*****************************************************************************
288* FUNCTION
289* mtk_wcn_stp_enable
290* DESCRIPTION
291* enable/disable STP
292* PARAMETERS
293* value [IN] 0 = disable, others = enable
294* RETURNS
295* INT32 0 = success, others = error
296*****************************************************************************/
297extern INT32 mtk_wcn_stp_enable(INT32 value);
298
299/*****************************************************************************
300* FUNCTION
301* mtk_wcn_stp_ready
302* DESCRIPTION
303* ready/non-ready STP
304* PARAMETERS
305* value [IN] 0 = non-ready, others = ready
306* RETURNS
307* INT32 0 = success, others = error
308*****************************************************************************/
309extern INT32 mtk_wcn_stp_ready(INT32 value);
310
311
312/*****************************************************************************
313* FUNCTION
314* mtk_wcn_stp_coredump_start_ctrl
315* DESCRIPTION
316* set f/w assert flag in STP context
317* PARAMETERS
318* value [IN] 0=assert end, others=assert begins
319* RETURNS
320* INT32 0=success, others=error
321*****************************************************************************/
322extern INT32 mtk_wcn_stp_coredump_start_ctrl(UINT32 value);
323
324/*****************************************************************************
325* FUNCTION
326* mtk_wcn_stp_coredump_start_get
327* DESCRIPTION
328* get f/w assert flag in STP context
329* PARAMETERS
330* VOID
331* RETURNS
332* INT32 0= f/w assert flag is not set, others=f/w assert flag is set
333*****************************************************************************/
334extern INT32 mtk_wcn_stp_coredump_start_get(VOID);
335
336
337/*****************************************************************************
338* FUNCTION
339* mtk_wcn_stp_send_data_raw
340* DESCRIPTION
341* send raw data to common interface, bypass STP
342* PARAMETERS
343* buffer [IN] data buffer
344* length [IN] data buffer length
345* type [IN] subfunction type
346* RETURNS
347* INT32 length transmitted
348*****************************************************************************/
349extern INT32 mtk_wcn_stp_send_data_raw(const PUINT8 buffer, const UINT32 length, const UINT8 type);
350
351/*****************************************************************************
352* FUNCTION
353* mtk_wcn_stp_set_sdio_mode
354* DESCRIPTION
355* Set stp for SDIO mode
356* PARAMETERS
357* sdio_flag [IN] sdio mode flag (TRUE:SDIO mode, FALSE:UART mode)
358* RETURNS
359* void
360*****************************************************************************/
361extern void mtk_wcn_stp_set_mode(UINT32 sdio_flag);
362
363/*****************************************************************************
364* FUNCTION
365* mtk_wcn_stp_is_uart_fullset_mode
366* DESCRIPTION
367* Is stp use UART Fullset mode?
368* PARAMETERS
369* none.
370* RETURNS
371* MTK_WCN_BOOL TRUE:UART Fullset, FALSE:UART Fullset
372*****************************************************************************/
373extern MTK_WCN_BOOL mtk_wcn_stp_is_uart_fullset_mode(void);
374
375/*****************************************************************************
376* FUNCTION
377* mtk_wcn_stp_is_uart_mand_mode
378* DESCRIPTION
379* Is stp use UART Mandatory mode?
380* PARAMETERS
381* none.
382* RETURNS
383* MTK_WCN_BOOL TRUE:UART Mandatory, FALSE:UART Mandatory
384*****************************************************************************/
385extern MTK_WCN_BOOL mtk_wcn_stp_is_uart_mand_mode(void);
386/*****************************************************************************
387* FUNCTION
388* mtk_wcn_stp_is_btif_fullset_mode
389* DESCRIPTION
390* Is stp use BTIF Fullset mode?
391* PARAMETERS
392* none.
393* RETURNS
394* MTK_WCN_BOOL TRUE:BTIF Fullset, FALSE:BTIF Fullset
395*****************************************************************************/
396extern MTK_WCN_BOOL mtk_wcn_stp_is_btif_fullset_mode(void);
397
398/*****************************************************************************
399* FUNCTION
400* mtk_wcn_stp_is_btif_mand_mode
401* DESCRIPTION
402* Is stp use BTIF Mandatory mode?
403* PARAMETERS
404* none.
405* RETURNS
406* MTK_WCN_BOOL TRUE:BTIF Mandatory, FALSE:BTIF Mandatory
407*****************************************************************************/
408extern MTK_WCN_BOOL mtk_wcn_stp_is_btif_mand_mode(void);
409
410/*****************************************************************************
411* FUNCTION
412* mtk_wcn_stp_is_sdio_mode
413* DESCRIPTION
414* Is stp use SDIO mode?
415* PARAMETERS
416* none.
417* RETURNS
418* MTK_WCN_BOOL TRUE:SDIO mode, FALSE:UART mode
419*****************************************************************************/
420extern MTK_WCN_BOOL mtk_wcn_stp_is_sdio_mode(void);
421
422
423/*****************************************************************************
424* FUNCTION
425* stp_send_inband_reset
426* DESCRIPTION
427* To sync to oringnal stp state with f/w stp
428* PARAMETERS
429* none.
430* RETURNS
431* none
432*****************************************************************************/
433extern void mtk_wcn_stp_inband_reset(void);
434
435/*****************************************************************************
436* FUNCTION
437* stp_send_inband_reset
438* DESCRIPTION
439* To send testing command to chip
440* PARAMETERS
441* none.
442* RETURNS
443* none
444*****************************************************************************/
445extern void mtk_wcn_stp_test_cmd(INT32 no);
446
447/*****************************************************************************
448* FUNCTION
449* stp_send_inband_reset
450* DESCRIPTION
451* To control STP debugging mechanism
452* PARAMETERS
453* func_no: function control, func_op: dumpping filer, func_param: dumpping parameter
454* RETURNS
455* none
456*****************************************************************************/
457extern void mtk_wcn_stp_debug_ctrl(INT32 func_no, INT32 func_op, INT32 func_param);
458/*****************************************************************************
459* FUNCTION
460* mtk_wcn_stp_flush
461* DESCRIPTION
462* flush all stp context
463* PARAMETERS
464* none.
465* RETURNS
466* none
467*****************************************************************************/
468extern void mtk_wcn_stp_flush_context(void);
469
470/*****************************************************************************
471* FUNCTION
472* mtk_wcn_stp_rx_queue
473* DESCRIPTION
474* flush all stp rx queue
475* PARAMETERS
476* none.
477* RETURNS
478* none
479*****************************************************************************/
480extern void mtk_wcn_stp_flush_rx_queue(UINT32 type);
481
482/*****************************************************************************
483* FUNCTION
484* set stp debugging mdoe
485* DESCRIPTION
486* set stp debugging mdoe
487* PARAMETERS
488* dbg_mode: switch to dbg mode ?
489* RETURNS
490* void
491*****************************************************************************/
492extern void mtk_wcn_stp_set_dbg_mode(MTK_WCN_BOOL dbg_mode);
493
494/*****************************************************************************
495* FUNCTION
496* set stp auto reset mdoe
497* DESCRIPTION
498* set stp auto reset mdoe
499* PARAMETERS
500* auto_rst: switch to auto reset mode ?
501* RETURNS
502* void
503*****************************************************************************/
504extern void mtk_wcn_stp_set_auto_rst(MTK_WCN_BOOL auto_rst);
505
506/*stp_psm support*/
507
508/*****************************************************************************
509* FUNCTION
510* mtk_wcn_stp_psm_notify_stp
511* DESCRIPTION
512* WMT notification to STP that power saving job is done or not
513* PARAMETERS
514*
515* RETURNS
516* 0: Sccuess Negative value: Fail
517*****************************************************************************/
518extern int mtk_wcn_stp_psm_notify_stp(const UINT32 action);
519
520extern int mtk_wcn_stp_set_psm_state(MTKSTP_PSM_STATE_T state);
521
522/*****************************************************************************
523* FUNCTION
524* mtk_wcn_stp_psm_enabla
525* DESCRIPTION
526* enable STP PSM
527* PARAMETERS
528* int idle_time_to_sleep: IDLE time to sleep
529* RETURNS
530* 0: Sccuess Negative value: Fail
531*****************************************************************************/
532extern int mtk_wcn_stp_psm_enable(int idle_time_to_sleep);
533
534/*****************************************************************************
535* FUNCTION
536* mtk_wcn_stp_psm_disable
537* DESCRIPTION
538* disable STP PSM
539* PARAMETERS
540* void
541* RETURNS
542* 0: Sccuess Negative value: Fail
543*****************************************************************************/
544extern int mtk_wcn_stp_psm_disable(void);
545
546/*****************************************************************************
547* FUNCTION
548* mtk_wcn_stp_psm_reset
549* DESCRIPTION
550* reset STP PSM (used on whole chip reset)
551* PARAMETERS
552* void
553* RETURNS
554* 0: Sccuess Negative value: Fail
555*****************************************************************************/
556extern int mtk_wcn_stp_psm_reset(void);
557extern void stp_do_tx_timeout(void);
558
559/*****************************************************************************
560* FUNCTION
561* mtk_wcn_stp_btm_get_dmp
562* DESCRIPTION
563* get stp dump related information
564* PARAMETERS
565* buffer: dump placement, len: dump size
566* RETURNS
567* 0: Success Negative Value: Fail
568*****************************************************************************/
569extern int mtk_wcn_stp_btm_get_dmp(char *buf, int *len);
570
571extern int mtk_wcn_stp_dbg_enable(void);
572
573extern int mtk_wcn_stp_dbg_disable(void);
574
575extern void mtk_wcn_stp_set_if_tx_type (ENUM_STP_TX_IF_TYPE stp_if_type);
576
577extern int mtk_wcn_sys_if_rx(UINT8 *data, INT32 size);
578
579extern MTK_WCN_BOOL mtk_wcn_stp_dbg_level(UINT32 dbglevel);
580
581extern INT32 mtk_wcn_stp_dbg_dump_package(VOID);
582
583extern int stp_drv_init(void);
584
585extern void stp_drv_exit(void);
586
587extern INT32 mtk_wcn_stp_dbg_log_ctrl(UINT32 on);
588
589extern INT32 mtk_wcn_stp_coredump_flag_ctrl(UINT32 on);
590
591extern INT32 mtk_wcn_stp_coredump_flag_get(VOID);
592extern INT32 mtk_wcn_stp_notify_sleep_for_thermal(void);
593
594
595extern INT32 mtk_wcn_stp_set_wmt_last_close(UINT32 value);
596
597/*stp btif API declared*/
598extern INT32 mtk_wcn_stp_open_btif(VOID);
599extern INT32 mtk_wcn_stp_close_btif(VOID);
600extern INT32 mtk_wcn_stp_rxcb_register(MTK_WCN_BTIF_RX_CB rx_cb);
601extern INT32 mtk_wcn_stp_tx(UINT8 *pBuf,UINT32 len,UINT32 *written_len);
602extern INT32 mtk_wcn_stp_wakeup_consys(VOID);
603extern INT32 mtk_wcn_stp_dpidle_ctrl(ENUM_BTIF_DPIDLE_CTRL en_flag);
604extern INT32 mtk_wcn_stp_lpbk_ctrl(ENUM_BTIF_LPBK_MODE mode);
605extern INT32 mtk_wcn_stp_logger_ctrl(ENUM_BTIF_DBG_ID flag);
606extern VOID mtk_wcn_stp_ctx_save(VOID);
607extern VOID mtk_wcn_stp_ctx_restore(VOID);
608extern INT32 mtk_wcn_stp_wmt_evt_err_trg_assert(VOID);
609extern VOID mtk_wcn_stp_set_wmt_evt_err_trg_assert(UINT32 value);
610extern UINT32 mtk_wcn_stp_get_wmt_evt_err_trg_assert(VOID);
611/*******************************************************************************
612* F U N C T I O N S
613********************************************************************************
614*/
615
616#endif /* _STP_CORE_H_ */