stp_sdio.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * Id:
  3. * */
  4. /*! \file "stp_sdio.h"
  5. \brief
  6. */
  7. /*
  8. * Log:
  9. * */
  10. #ifndef _STP_SDIO_H
  11. #define _STP_SDIO_H
  12. /*******************************************************************************
  13. * C O M P I L E R F L A G S
  14. ********************************************************************************
  15. */
  16. #define KMALLOC_UPDATE 1
  17. #if 0 /* NO support for multiple STP-SDIO instances (multiple MT6620) on a single host */
  18. #define STP_SDIO_HOST_COUNT (1)
  19. #define STP_SDIO_ONLY_ONE_HOST (0)
  20. #endif
  21. #define STP_SDIO_POLL_OWNBACK_INTR (1)
  22. #define STP_SDIO_NEW_TXRING (0)
  23. /* George: Keep old (0) codes for debugging only!
  24. * Use new code (1) for SQC and MP!
  25. */
  26. #define STP_SDIO_OWN_THREAD (1)
  27. /*******************************************************************************
  28. * E X T E R N A L R E F E R E N C E S
  29. ********************************************************************************
  30. */
  31. #include "osal.h"
  32. #include "hif_sdio.h"
  33. /*******************************************************************************
  34. * C O N S T A N T S
  35. ********************************************************************************
  36. */
  37. /* Common HIF register address */
  38. #define CCIR (0x0000)
  39. #define CHLPCR (0x0004)
  40. #define CSDIOCSR (0x0008)
  41. #define CHCR (0x000c)
  42. #define CHISR (0x0010)
  43. #define CHIER (0x0014)
  44. #define CTDR (0x0018)
  45. #define CRDR (0x001c)
  46. #define CTFSR (0x0020)
  47. #define CRPLR (0x0024)
  48. #define CSR (0x00D8) /* MT6630 only for the moment */
  49. #define SWPCDBGR (0x0154)
  50. /* Common HIF register bit field address */
  51. /* CHLPCR */
  52. #define C_FW_OWN_REQ_CLR (0x00000200)
  53. #define C_FW_OWN_REQ_SET (0x00000100)
  54. #define C_FW_INT_EN_CLR (0x00000002)
  55. #define C_FW_INT_EN_SET (0x00000001)
  56. #define C_FW_COM_DRV_OWN (0x00000100)
  57. /* CHIER */
  58. #define CHISR_EN_15_7 (0x0000ff80)
  59. #define CHISR_EN_3_0 (0x0000000f)
  60. /* CHISR */
  61. #define RX_PKT_LEN (0xffff0000)
  62. #define FIRMWARE_INT (0x0000fe00)
  63. #define TX_FIFO_OVERFLOW (0x00000100)
  64. #define FW_INT_IND_INDICATOR (0x00000080)
  65. #define TX_COMPLETE_COUNT (0x00000070)
  66. #define TX_UNDER_THOLD (0x00000008)
  67. #define TX_EMPTY (0x00000004)
  68. #define RX_DONE (0x00000002)
  69. #define FW_OWN_BACK_INT (0x00000001)
  70. /* hardware settings */
  71. #define STP_SDIO_TX_FIFO_SIZE (2080UL)
  72. #define STP_SDIO_RX_FIFO_SIZE (2304UL) /* 256*9 */
  73. #define STP_SDIO_TX_PKT_MAX_CNT (7) /* Max outstanding tx pkt count, as defined in TX_COMPLETE_COUNT */
  74. #define STP_SDIO_HDR_SIZE (4) /* hw,fw,sw follow the same format: 2 bytes length + 2 bytes reserved */
  75. /* sdio bus settings */
  76. #define STP_SDIO_BLK_SIZE (512UL)
  77. /* software driver settings */
  78. #define STP_SDIO_TX_BUF_CNT (16UL) /*(7) */
  79. #define STP_SDIO_TX_BUF_CNT_MASK (STP_SDIO_TX_BUF_CNT - 1)
  80. #define STP_SDIO_TX_PKT_LIST_SIZE (STP_SDIO_TX_BUF_CNT) /* must be 2^x now... */
  81. #define STP_SDIO_TX_PKT_LIST_SIZE_MASK (STP_SDIO_TX_PKT_LIST_SIZE - 1)
  82. #define STP_SDIO_FW_CPUPCR_POLLING_CNT (5)
  83. /* tx buffer size for a single entry */
  84. /* George: SHALL BE a multiple of the used BLK_SIZE!! */
  85. #if 1
  86. /* round up: 512*5 = 2560 > 2080 */
  87. #define STP_SDIO_TX_ENTRY_SIZE ((STP_SDIO_TX_FIFO_SIZE + (STP_SDIO_BLK_SIZE - 1)) & ~(STP_SDIO_BLK_SIZE - 1))
  88. #else
  89. /* round down: 512*4 = 2048 < 2080 */
  90. #define STP_SDIO_TX_MAX_BLK_CNT (STP_SDIO_TX_FIFO_SIZE / STP_SDIO_BLK_SIZE)
  91. #define STP_SDIO_TX_ENTRY_SIZE (STP_SDIO_TX_MAX_BLK_CNT * STP_SDIO_BLK_SIZE)
  92. #endif
  93. /*software rx buffer size */
  94. /*#define STP_SDIO_RX_BUF_SIZE (STP_SDIO_RX_FIFO_SIZE)*/
  95. /* George: SHALL BE a multiple of the used BLK_SIZE!! */
  96. #if 1
  97. /* round up: 512*5 = 2560 > 2304 */
  98. #define STP_SDIO_RX_BUF_SIZE ((STP_SDIO_RX_FIFO_SIZE + (STP_SDIO_BLK_SIZE - 1)) & ~(STP_SDIO_BLK_SIZE - 1))
  99. #else
  100. /* round down: 512*4 = 2048 < 2304 */
  101. #define STP_SDIO_RX_MAX_BLK_CNT (STP_SDIO_RX_FIFO_SIZE / STP_SDIO_BLK_SIZE)
  102. #define STP_SDIO_RX_BUF_SIZE (STP_SDIO_RX_MAX_BLK_CNT * STP_SDIO_BLK_SIZE)
  103. #endif
  104. #define COHEC_00006052 (1)
  105. /* #define COHEC_00006052 (0) */
  106. /*******************************************************************************
  107. * D A T A T Y P E S
  108. ********************************************************************************
  109. */
  110. /* HIF's local packet buffer variables for Tx/Rx */
  111. typedef struct _MTK_WCN_STP_SDIO_PKT_BUF {
  112. /* Tx entry ring buffer. Entry size is aligned to SDIO block size. */
  113. #if KMALLOC_UPDATE
  114. PUINT8 tx_buf;
  115. #else
  116. UINT8 tx_buf[STP_SDIO_TX_BUF_CNT][STP_SDIO_TX_ENTRY_SIZE];
  117. #endif
  118. /* Tx size ring buffer. Record valid data size in tx_buf. */
  119. UINT32 tx_buf_sz[STP_SDIO_TX_BUF_CNT];
  120. /* Tx debug timestamp: 1st time when the entry is filled with data */
  121. UINT32 tx_buf_ts[STP_SDIO_TX_BUF_CNT];
  122. #if KMALLOC_UPDATE
  123. PUINT8 rx_buf;
  124. #else
  125. UINT8 rx_buf[STP_SDIO_RX_BUF_SIZE]; /* Rx buffer (not ring) */
  126. #endif
  127. #if STP_SDIO_NEW_TXRING
  128. UINT32 wr_cnt; /* Tx entry ring buffer write count */
  129. UINT32 rd_cnt; /* Tx entry ring buffer read count */
  130. spinlock_t rd_cnt_lock; /* Tx entry ring buffer read count spin lock */
  131. #else
  132. UINT8 wr_idx; /* Tx ring buffer write index *//*George: obsolete */
  133. UINT8 rd_idx; /* Tx ring buffer read index *//*George: obsolete */
  134. spinlock_t rd_idx_lock; /* spin lock for Tx ring buffer read index */
  135. #endif
  136. MTK_WCN_BOOL full_flag; /* Tx entry ring buffer full flag (TRUE: full, FALSE: not full) */
  137. /* save interrupt status flag for Tx entry ring buf spin lock */
  138. unsigned long rd_irq_flag;
  139. /* wait queue head for Tx entry ring buf full case */
  140. wait_queue_head_t fullwait_q;
  141. } MTK_WCN_STP_SDIO_PKT_BUF;
  142. /* Tx packet list information */
  143. typedef struct _MTK_WCN_STP_SDIO_Tx_Pkt_LIST {
  144. UINT32 pkt_rd_cnt;
  145. UINT32 pkt_wr_cnt;
  146. UINT16 pkt_size_list[STP_SDIO_TX_PKT_LIST_SIZE]; /*max length is FIFO Size */
  147. UINT32 out_ts[STP_SDIO_TX_PKT_LIST_SIZE];
  148. UINT32 in_ts[STP_SDIO_TX_PKT_LIST_SIZE];
  149. } MTK_WCN_STP_SDIO_Tx_Pkt_LIST;
  150. /* STP HIF firmware information */
  151. typedef struct _MTK_WCN_STP_SDIO_FIRMWARE_INFO {
  152. UINT32 tx_fifo_size; /* Current left tx FIFO size */
  153. UINT32 tx_packet_num; /* Current outstanding tx packet (0~7) */
  154. atomic_t tx_comp_num; /* Current total tx ok but fifo size not released packet count */
  155. } MTK_WCN_STP_SDIO_FIRMWARE_INFO;
  156. /* STP SDIO private information */
  157. typedef struct _MTK_WCN_STP_SDIO_PRIVATE_INFO {
  158. UINT8 stp_sdio_host_idx;
  159. } MTK_WCN_STP_SDIO_PRIVATE_INFO;
  160. /* STP SDIO host information */
  161. typedef struct _MTK_WCN_STP_SDIO_HIF_INFO {
  162. MTK_WCN_HIF_SDIO_CLTCTX sdio_cltctx;
  163. MTK_WCN_STP_SDIO_PKT_BUF pkt_buf;
  164. MTK_WCN_STP_SDIO_Tx_Pkt_LIST tx_pkt_list;
  165. UINT32 rx_pkt_len; /* George: use 32-bit for efficiency. Correct name to pkt for packet */
  166. MTK_WCN_STP_SDIO_FIRMWARE_INFO firmware_info;
  167. MTK_WCN_STP_SDIO_PRIVATE_INFO private_info;
  168. #if STP_SDIO_OWN_THREAD
  169. /* struct tasklet_struct tx_rx_job; */
  170. OSAL_THREAD tx_rx_thread;
  171. INT32 irq_pending;
  172. INT32 sleep_flag;
  173. INT32 wakeup_flag;
  174. INT32 awake_flag;
  175. OSAL_EVENT tx_rx_event;
  176. OSAL_SIGNAL isr_check_complete;
  177. INT32 dump_flag;
  178. #endif
  179. INT32 tx_dbg_dump_flag;
  180. struct work_struct tx_work;
  181. struct work_struct rx_work;
  182. } MTK_WCN_STP_SDIO_HIF_INFO;
  183. /*******************************************************************************
  184. * P U B L I C D A T A
  185. ********************************************************************************
  186. */
  187. extern MTK_WCN_STP_SDIO_HIF_INFO g_stp_sdio_host_info;
  188. /*******************************************************************************
  189. * P R I V A T E D A T A
  190. ********************************************************************************
  191. */
  192. /*******************************************************************************
  193. * M A C R O S
  194. ********************************************************************************
  195. */
  196. /* STP_SDIO_TX_PKT_LIST_SIZE must be 2^x */
  197. #define STP_SDIO_GET_PKT_AR_IDX(idx) ((idx) & STP_SDIO_TX_PKT_LIST_SIZE_MASK)
  198. /*******************************************************************************
  199. * F U N C T I O N D E C L A R A T I O N S
  200. ********************************************************************************
  201. */
  202. /*!
  203. * \brief MTK hif sdio client registration function
  204. *
  205. * Client uses this function to do hif sdio registration
  206. *
  207. * \param pinfo a pointer of client's information
  208. *
  209. * \retval 0 register successfully
  210. * \retval < 0 error code
  211. */
  212. extern INT32 mtk_wcn_hif_sdio_client_reg(const MTK_WCN_HIF_SDIO_CLTINFO *pinfo);
  213. extern INT32 mtk_wcn_stp_sdio_do_own_clr(VOID);
  214. /* extern INT32 */
  215. /* mtk_wcn_stp_sdio_do_own_set (void); */
  216. /*******************************************************************************
  217. * F U N C T I O N S
  218. ********************************************************************************
  219. */
  220. #endif /* _STP_SDIO_H */