MT6620: add the new driver JB2 V1.0
[firefly-linux-kernel-4.4.55.git] / drivers / mtk_wcn_combo / common / core / include / stp_core.h
1 /*! \file
2     \brief  Declaration of library functions
3
4     Any definitions in this file will be shared among GLUE Layer and internal Driver Stack.
5 */
6
7
8
9 #ifndef _STP_CORE_H
10 #define _STP_CORE_H
11
12 #include "osal_typedef.h"
13 #include "osal.h"
14 #include "stp_exp.h"
15 #include "psm_core.h"
16 #include "btm_core.h"
17 /*******************************************************************************
18 *                         C O M P I L E R   F L A G S
19 ********************************************************************************
20 */
21
22 /*******************************************************************************
23 *                                 M A C R O S
24 ********************************************************************************
25 */
26
27 #define CONFIG_POWER_SAVING_SUPPORT
28 #if WMT_UART_RX_MODE_WORK
29 #define CFG_STP_CORE_CTX_SPIN_LOCK 0
30 #else
31 #define CFG_STP_CORE_CTX_SPIN_LOCK 1
32 #endif
33
34
35
36 #define PFX                         "[STP] "
37 #define STP_LOG_DBG                  4
38 #define STP_LOG_PKHEAD               3
39 #define STP_LOG_INFO                 2
40 #define STP_LOG_WARN                 1
41 #define STP_LOG_ERR                  0
42
43 extern unsigned int gStpDbgLvl;
44
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__);}
50
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);}
53
54 #define MTKSTP_UART_FULL_MODE 0x01
55 #define MTKSTP_UART_MAND_MODE 0x02
56 #define MTKSTP_SDIO_MODE      0x04
57
58 #define MTKSTP_BUFFER_SIZE  (16384)
59
60 /*To check function driver's status by the the interface*/
61 /*Operation definition*/
62 #define OP_FUNCTION_ACTIVE         0
63
64 /*Driver's status*/
65 #define STATUS_OP_INVALID          0
66 #define STATUS_FUNCTION_INVALID    1
67
68 #define STATUS_FUNCTION_ACTIVE     31
69 #define STATUS_FUNCTION_INACTIVE   32
70
71 #define MTKSTP_CRC_SIZE     (2)
72 #define MTKSTP_HEADER_SIZE  (4)
73 #define MTKSTP_SEQ_SIZE     (8)
74
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)
79
80 #define INDEX_INC(idx)  \
81 {                       \
82     idx++;              \
83     idx &= 0x7;         \
84 }
85
86 #define INDEX_DEC(idx)  \
87 {                       \
88     idx--;              \
89     idx &= 0x7;         \
90 }
91
92 /*******************************************************************************
93 *                    E X T E R N A L   R E F E R E N C E S
94 ********************************************************************************
95 */
96
97
98
99 /*******************************************************************************
100 *                              C O N S T A N T S
101 ********************************************************************************
102 */
103
104 /*******************************************************************************
105 *                             D A T A   T Y P E S
106 ********************************************************************************
107 */
108 typedef INT32 (*IF_TX)(const UINT8 *data, const UINT32 size, UINT32 *written_size);
109 /* event/signal */
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);
115
116
117 typedef struct
118 {
119     /* common interface */
120     IF_TX           cb_if_tx;
121     /* event/signal */
122     EVENT_SET       cb_event_set;
123     EVENT_TX_RESUME cb_event_tx_resume;
124     FUNCTION_STATUS cb_check_funciton_status;
125 }mtkstp_callback;
126
127 typedef enum
128 {
129     MTKSTP_SYNC = 0,
130     MTKSTP_SEQ,
131     MTKSTP_ACK,
132     MTKSTP_NAK,
133     MTKSTP_TYPE,
134     MTKSTP_LENGTH,
135     MTKSTP_CHECKSUM,
136     MTKSTP_DATA,
137     MTKSTP_CRC1,
138     MTKSTP_CRC2,
139     MTKSTP_RESYNC1,
140     MTKSTP_RESYNC2,
141     MTKSTP_RESYNC3,
142     MTKSTP_RESYNC4,
143     MTKSTP_FW_MSG,
144 } mtkstp_parser_state;
145
146 typedef struct
147 {
148     mtkstp_parser_state  state;
149     UINT8            seq;
150     UINT8            ack;
151     UINT8            nak;
152     UINT8            type;
153     UINT16           length;
154     UINT8            checksum;
155     UINT16           crc;
156 } mtkstp_parser_context_struct;
157
158 typedef struct
159 {
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
165     UINT8           retry_times;
166 } mtkstp_sequence_context_struct;
167
168 typedef struct
169 {
170     //MTK_WCN_MUTEX           mtx;
171     OSAL_UNSLEEPABLE_LOCK  mtx;
172     UINT8           buffer[MTKSTP_BUFFER_SIZE];
173     UINT32          read_p;
174     UINT32          write_p;
175 } mtkstp_ring_buffer_struct;
176
177 typedef struct
178 {
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;
193         #else
194         OSAL_SLEEPABLE_LOCK stp_mutex;
195         #endif
196     //MTK_WCN_TIMER tx_timer; // timer for tx timeout handling
197     OSAL_TIMER tx_timer;
198
199     MTKSTP_PSM_T *psm;
200     MTKSTP_BTM_T *btm;
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*/
205     UINT8 en_coredump;
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;
210
211     
212
213     /* Flag to identify STP by SDIO or UART */
214     UINT32 f_mode;
215     
216     /* Flag to indicate the last WMT CLOSE*/
217     UINT32 f_wmt_last_close;
218 }mtkstp_context_struct;
219
220 /*******************************************************************************
221 *                            P U B L I C   D A T A
222 ********************************************************************************
223 */
224
225 /*******************************************************************************
226 *                           P R I V A T E   D A T A
227 ********************************************************************************
228 */
229
230
231 /*******************************************************************************
232 *                  F U N C T I O N   D E C L A R A T I O N S
233 ********************************************************************************
234 */
235
236 INT32 stp_send_data_no_ps(UINT8 *buffer, UINT32 length, UINT8 type);
237
238 /*****************************************************************************
239 * FUNCTION
240 *  mtk_wcn_stp_init
241 * DESCRIPTION
242 *  init STP kernel
243 * PARAMETERS
244 *  cb_func      [IN] function pointers of system APIs
245 * RETURNS
246 *  INT32    0 = success, others = failure
247 *****************************************************************************/
248 extern INT32 mtk_wcn_stp_init(const mtkstp_callback * const cb_func);
249
250 /*****************************************************************************
251 * FUNCTION
252 *  mtk_wcn_stp_deinit
253 * DESCRIPTION
254 *  deinit STP kernel
255 * PARAMETERS
256 *  void
257 * RETURNS
258 *  INT32    0 = success, others = failure
259 *****************************************************************************/
260 extern INT32 mtk_wcn_stp_deinit(void);
261
262 /*****************************************************************************
263 * FUNCTION
264 *  mtk_wcn_stp_enable
265 * DESCRIPTION
266 *  enable/disable STP
267 * PARAMETERS
268 *  value        [IN]        0 = disable, others = enable
269 * RETURNS
270 *  INT32    0 = success, others = error
271 *****************************************************************************/
272 extern INT32 mtk_wcn_stp_enable(INT32 value);
273
274 /*****************************************************************************
275 * FUNCTION
276 *  mtk_wcn_stp_ready
277 * DESCRIPTION
278 *  ready/non-ready STP
279 * PARAMETERS
280 *  value        [IN]        0 = non-ready, others = ready
281 * RETURNS
282 *  INT32    0 = success, others = error
283 *****************************************************************************/
284 extern INT32 mtk_wcn_stp_ready(INT32 value);
285
286
287 /*****************************************************************************
288 * FUNCTION
289 *  mtk_wcn_stp_coredump_start_ctrl
290 * DESCRIPTION
291 *  set f/w assert flag in STP context
292 * PARAMETERS
293 *  value        [IN]        0=assert end, others=assert begins
294 * RETURNS
295 *  INT32    0=success, others=error
296 *****************************************************************************/
297 extern INT32 mtk_wcn_stp_coredump_start_ctrl(UINT32 value);
298
299 /*****************************************************************************
300 * FUNCTION
301 *  mtk_wcn_stp_coredump_start_get
302 * DESCRIPTION
303 *  get f/w assert flag in STP context
304 * PARAMETERS
305 *  VOID
306 * RETURNS
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);
310
311
312 /*****************************************************************************
313 * FUNCTION
314 *  mtk_wcn_stp_send_data_raw
315 * DESCRIPTION
316 *  send raw data to common interface, bypass STP
317 * PARAMETERS
318 *  buffer      [IN]        data buffer
319 *  length      [IN]        data buffer length
320 *  type        [IN]        subfunction type
321 * RETURNS
322 *  INT32    length transmitted
323 *****************************************************************************/
324 extern INT32 mtk_wcn_stp_send_data_raw(const UINT8 *buffer, const UINT32 length, const UINT8 type);
325
326 /*****************************************************************************
327 * FUNCTION
328 *  mtk_wcn_stp_set_sdio_mode
329 * DESCRIPTION
330 *  Set stp for SDIO mode
331 * PARAMETERS
332 *  sdio_flag  [IN]        sdio mode flag (TRUE:SDIO mode, FALSE:UART mode)
333 * RETURNS
334 *  void
335 *****************************************************************************/
336 extern void mtk_wcn_stp_set_mode(UINT32 sdio_flag);
337
338 /*****************************************************************************
339 * FUNCTION
340 *  mtk_wcn_stp_is_uart_fullset_mode
341 * DESCRIPTION
342 *  Is stp use UART Fullset  mode?
343 * PARAMETERS
344 *  none.
345 * RETURNS
346 *  MTK_WCN_BOOL    TRUE:UART Fullset, FALSE:UART Fullset
347 *****************************************************************************/
348 extern MTK_WCN_BOOL mtk_wcn_stp_is_uart_fullset_mode(void);
349
350 /*****************************************************************************
351 * FUNCTION
352 *  mtk_wcn_stp_is_uart_mand_mode
353 * DESCRIPTION
354 *  Is stp use UART Mandatory  mode?
355 * PARAMETERS
356 *  none.
357 * RETURNS
358 *  MTK_WCN_BOOL    TRUE:UART Mandatory, FALSE:UART Mandatory
359 *****************************************************************************/
360 extern MTK_WCN_BOOL mtk_wcn_stp_is_uart_mand_mode(void);
361
362
363 /*****************************************************************************
364 * FUNCTION
365 *  mtk_wcn_stp_is_sdio_mode
366 * DESCRIPTION
367 *  Is stp use SDIO mode?
368 * PARAMETERS
369 *  none.
370 * RETURNS
371 *  MTK_WCN_BOOL    TRUE:SDIO mode, FALSE:UART mode
372 *****************************************************************************/
373 extern MTK_WCN_BOOL mtk_wcn_stp_is_sdio_mode(void);
374
375
376 /*****************************************************************************
377 * FUNCTION
378 *  stp_send_inband_reset
379 * DESCRIPTION
380 *  To sync to oringnal stp state with f/w stp
381 * PARAMETERS
382 *  none.
383 * RETURNS
384 *  none
385 *****************************************************************************/
386 extern void mtk_wcn_stp_inband_reset(void);
387
388 /*****************************************************************************
389 * FUNCTION
390 *  stp_send_inband_reset
391 * DESCRIPTION
392 *  To send testing command to chip
393 * PARAMETERS
394 *  none.
395 * RETURNS
396 *  none
397 *****************************************************************************/
398 extern void mtk_wcn_stp_test_cmd(INT32 no);
399
400 /*****************************************************************************
401 * FUNCTION
402 *  stp_send_inband_reset
403 * DESCRIPTION
404 * To control STP debugging mechanism
405 * PARAMETERS
406 *  func_no: function control, func_op: dumpping filer, func_param: dumpping parameter
407 * RETURNS
408 *  none
409 *****************************************************************************/
410 extern void mtk_wcn_stp_debug_ctrl(INT32 func_no, INT32 func_op, INT32 func_param);
411 /*****************************************************************************
412 * FUNCTION
413 *  mtk_wcn_stp_flush
414 * DESCRIPTION
415 *  flush all stp context
416 * PARAMETERS
417 *  none.
418 * RETURNS
419 *  none
420 *****************************************************************************/
421 extern void mtk_wcn_stp_flush_context(void);
422
423 /*****************************************************************************
424 * FUNCTION
425 *  mtk_wcn_stp_rx_queue
426 * DESCRIPTION
427 *  flush all stp rx queue
428 * PARAMETERS
429 *  none.
430 * RETURNS
431 *  none
432 *****************************************************************************/
433 extern void mtk_wcn_stp_flush_rx_queue(UINT32 type);
434
435 /*****************************************************************************
436 * FUNCTION
437 *  set stp debugging mdoe
438 * DESCRIPTION
439 *  set stp debugging mdoe
440 * PARAMETERS
441 * dbg_mode: switch to dbg mode ?
442 * RETURNS
443 *  void
444 *****************************************************************************/
445 extern void mtk_wcn_stp_set_dbg_mode(MTK_WCN_BOOL dbg_mode);
446
447 /*****************************************************************************
448 * FUNCTION
449 *  set stp auto reset mdoe
450 * DESCRIPTION
451 *  set stp auto reset mdoe
452 * PARAMETERS
453 * auto_rst: switch to auto reset mode ?
454 * RETURNS
455 *  void
456 *****************************************************************************/
457 extern void mtk_wcn_stp_set_auto_rst(MTK_WCN_BOOL auto_rst);
458
459 /*stp_psm support*/
460
461 /*****************************************************************************
462 * FUNCTION
463 *  mtk_wcn_stp_psm_notify_stp
464 * DESCRIPTION
465 *  WMT notification to STP that power saving job is done or not
466 * PARAMETERS
467 *
468 * RETURNS
469 *  0: Sccuess  Negative value: Fail
470 *****************************************************************************/
471 extern int mtk_wcn_stp_psm_notify_stp(const UINT32 action);
472
473 extern int mtk_wcn_stp_set_psm_state(MTKSTP_PSM_STATE_T state);
474
475 /*****************************************************************************
476 * FUNCTION
477 *  mtk_wcn_stp_psm_enabla
478 * DESCRIPTION
479 *  enable STP PSM
480 * PARAMETERS
481 *  int idle_time_to_sleep: IDLE time to sleep
482 * RETURNS
483 *  0: Sccuess  Negative value: Fail
484 *****************************************************************************/
485 extern int mtk_wcn_stp_psm_enable(int idle_time_to_sleep);
486
487 /*****************************************************************************
488 * FUNCTION
489 *  mtk_wcn_stp_psm_disable
490 * DESCRIPTION
491 *  disable STP PSM
492 * PARAMETERS
493 *  void
494 * RETURNS
495 *  0: Sccuess  Negative value: Fail
496 *****************************************************************************/
497 extern int mtk_wcn_stp_psm_disable(void);
498
499 /*****************************************************************************
500 * FUNCTION
501 *  mtk_wcn_stp_psm_reset
502 * DESCRIPTION
503 *  reset STP PSM (used on whole chip reset)
504 * PARAMETERS
505 *  void
506 * RETURNS
507 *  0: Sccuess  Negative value: Fail
508 *****************************************************************************/
509 extern int mtk_wcn_stp_psm_reset(void);
510 extern void stp_do_tx_timeout(void);
511
512 /*****************************************************************************
513 * FUNCTION
514 *  mtk_wcn_stp_btm_get_dmp
515 * DESCRIPTION
516 *  get stp dump related information
517 * PARAMETERS
518 *  buffer: dump placement, len: dump size
519 * RETURNS
520 *   0: Success Negative Value: Fail
521 *****************************************************************************/
522 extern int mtk_wcn_stp_btm_get_dmp(char *buf, int *len);
523
524 extern int mtk_wcn_stp_dbg_enable(void);
525
526 extern int mtk_wcn_stp_dbg_disable(void);
527
528 extern void mtk_wcn_stp_set_if_tx_type (ENUM_STP_TX_IF_TYPE stp_if_type);
529
530 extern int mtk_wcn_sys_if_rx(UINT8 *data, INT32 size);
531
532 extern MTK_WCN_BOOL mtk_wcn_stp_dbg_level(UINT32 dbglevel);
533
534 extern INT32 mtk_wcn_stp_dbg_dump_package(VOID);
535
536 extern int  stp_drv_init(void);
537
538 extern void stp_drv_exit(void);
539
540 extern INT32 mtk_wcn_stp_dbg_log_ctrl(UINT32 on);
541
542 extern INT32 mtk_wcn_stp_coredump_flag_ctrl(UINT32 on);
543
544 extern INT32 mtk_wcn_stp_coredump_flag_get(VOID);
545 extern INT32 mtk_wcn_stp_notify_sleep_for_thermal(void);
546
547
548 extern INT32 mtk_wcn_stp_set_wmt_last_close(UINT32 value);
549
550 /*******************************************************************************
551 *                              F U N C T I O N S
552 ********************************************************************************
553 */
554
555 #endif /* _STP_CORE_H_ */