bcmsdpcm.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * Broadcom SDIO/PCMCIA
  3. * Software-specific definitions shared between device and host side
  4. *
  5. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  6. *
  7. * Copyright (C) 1999-2020, Broadcom Corporation
  8. *
  9. * Unless you and Broadcom execute a separate written software license
  10. * agreement governing use of this software, this software is licensed to you
  11. * under the terms of the GNU General Public License version 2 (the "GPL"),
  12. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  13. * following added to such license:
  14. *
  15. * As a special exception, the copyright holders of this software give you
  16. * permission to link this software with independent modules, and to copy and
  17. * distribute the resulting executable under terms of your choice, provided that
  18. * you also meet, for each linked independent module, the terms and conditions of
  19. * the license of that module. An independent module is a module which is not
  20. * derived from this software. The special exception does not apply to any
  21. * modifications of the software.
  22. *
  23. * Notwithstanding the above, under no circumstances may you combine this
  24. * software in any way with any other Broadcom software provided under a license
  25. * other than the GPL, without Broadcom's express prior written consent.
  26. *
  27. *
  28. * <<Broadcom-WL-IPTag/Open:>>
  29. *
  30. * $Id: bcmsdpcm.h 681862 2018-01-03 12:34:14Z $
  31. */
  32. #ifndef _bcmsdpcm_h_
  33. #define _bcmsdpcm_h_
  34. /*
  35. * Software allocation of To SB Mailbox resources
  36. */
  37. /* intstatus bits */
  38. #define I_SMB_NAK I_SMB_SW0 /* To SB Mailbox Frame NAK */
  39. #define I_SMB_INT_ACK I_SMB_SW1 /* To SB Mailbox Host Interrupt ACK */
  40. #define I_SMB_USE_OOB I_SMB_SW2 /* To SB Mailbox Use OOB Wakeup */
  41. #define I_SMB_DEV_INT I_SMB_SW3 /* To SB Mailbox Miscellaneous Interrupt */
  42. #define I_TOSBMAIL (I_SMB_NAK | I_SMB_INT_ACK | I_SMB_USE_OOB | I_SMB_DEV_INT)
  43. /* tosbmailbox bits corresponding to intstatus bits */
  44. #define SMB_NAK (1 << 0) /* To SB Mailbox Frame NAK */
  45. #define SMB_INT_ACK (1 << 1) /* To SB Mailbox Host Interrupt ACK */
  46. #define SMB_USE_OOB (1 << 2) /* To SB Mailbox Use OOB Wakeup */
  47. #define SMB_DEV_INT (1 << 3) /* To SB Mailbox Miscellaneous Interrupt */
  48. #define SMB_MASK 0x0000000f /* To SB Mailbox Mask */
  49. /* tosbmailboxdata */
  50. #ifdef DS_PROT
  51. /* Bit msgs for custom deep sleep protocol */
  52. #define SMB_DATA_D3INFORM 0x100 /* host announcing D3 entry */
  53. #define SMB_DATA_DSACK 0x200 /* host acking a deepsleep request */
  54. #define SMB_DATA_DSNACK 0x400 /* host nacking a deepsleep request */
  55. #endif /* DS_PROT */
  56. /* force a trap */
  57. #define SMB_DATA_TRAP 0x800 /* host forcing trap */
  58. #define SMB_DATA_VERSION_MASK 0x00ff0000 /* host protocol version (sent with F2 enable) */
  59. #define SMB_DATA_VERSION_SHIFT 16 /* host protocol version (sent with F2 enable) */
  60. /*
  61. * Software allocation of To Host Mailbox resources
  62. */
  63. /* intstatus bits */
  64. #define I_HMB_INT_ACK I_HMB_SW0 /* To Host Mailbox Dev Interrupt ACK */
  65. #define I_HMB_FC_STATE I_HMB_SW0 /* To Host Mailbox Flow Control State */
  66. #define I_HMB_FC_CHANGE I_HMB_SW1 /* To Host Mailbox Flow Control State Changed */
  67. #define I_HMB_FRAME_IND I_HMB_SW2 /* To Host Mailbox Frame Indication */
  68. #define I_HMB_HOST_INT I_HMB_SW3 /* To Host Mailbox Miscellaneous Interrupt */
  69. #define I_TOHOSTMAIL (I_HMB_INT_ACK | I_HMB_FRAME_IND | I_HMB_HOST_INT)
  70. /* tohostmailbox bits corresponding to intstatus bits */
  71. #define HMB_INT_ACK (1 << 0) /* To Host Mailbox Dev Interrupt ACK */
  72. #define HMB_FRAME_IND (1 << 2) /* To Host Mailbox Frame Indication */
  73. #define HMB_HOST_INT (1 << 3) /* To Host Mailbox Miscellaneous Interrupt */
  74. #define HMB_MASK 0x0000000f /* To Host Mailbox Mask */
  75. /* tohostmailboxdata */
  76. #define HMB_DATA_NAKHANDLED 0x01 /* we're ready to retransmit NAK'd frame to host */
  77. #define HMB_DATA_DEVREADY 0x02 /* we're ready to to talk to host after enable */
  78. #define HMB_DATA_FC 0x04 /* per prio flowcontrol update flag to host */
  79. #define HMB_DATA_FWREADY 0x08 /* firmware is ready for protocol activity */
  80. #define HMB_DATA_FWHALT 0x10 /* firmware has halted operation */
  81. #ifdef DS_PROT
  82. /* Bit msgs for custom deep sleep protocol */
  83. #define HMB_DATA_DSREQ 0x100 /* firmware requesting deepsleep entry */
  84. #define HMB_DATA_DSEXIT 0x200 /* firmware announcing deepsleep exit */
  85. #define HMB_DATA_D3ACK 0x400 /* firmware acking a D3 notice from host */
  86. #define HMB_DATA_D3EXIT 0x800 /* firmware announcing D3 exit */
  87. #define HMB_DATA_DSPROT_MASK 0xf00
  88. #endif /* DS_PROT */
  89. #define HMB_DATA_FCDATA_MASK 0xff000000 /* per prio flowcontrol data */
  90. #define HMB_DATA_FCDATA_SHIFT 24 /* per prio flowcontrol data */
  91. #define HMB_DATA_VERSION_MASK 0x00ff0000 /* device protocol version (with devready) */
  92. #define HMB_DATA_VERSION_SHIFT 16 /* device protocol version (with devready) */
  93. /*
  94. * Software-defined protocol header
  95. */
  96. /* Current protocol version */
  97. #define SDPCM_PROT_VERSION 4
  98. /* SW frame header */
  99. #define SDPCM_SEQUENCE_MASK 0x000000ff /* Sequence Number Mask */
  100. #define SDPCM_PACKET_SEQUENCE(p) (((uint8 *)p)[0] & 0xff) /* p starts w/SW Header */
  101. #define SDPCM_CHANNEL_MASK 0x00000f00 /* Channel Number Mask */
  102. #define SDPCM_CHANNEL_SHIFT 8 /* Channel Number Shift */
  103. #define SDPCM_PACKET_CHANNEL(p) (((uint8 *)p)[1] & 0x0f) /* p starts w/SW Header */
  104. #define SDPCM_FLAGS_MASK 0x0000f000 /* Mask of flag bits */
  105. #define SDPCM_FLAGS_SHIFT 12 /* Flag bits shift */
  106. #define SDPCM_PACKET_FLAGS(p) ((((uint8 *)p)[1] & 0xf0) >> 4) /* p starts w/SW Header */
  107. /* Next Read Len: lookahead length of next frame, in 16-byte units (rounded up) */
  108. #define SDPCM_NEXTLEN_MASK 0x00ff0000 /* Next Read Len Mask */
  109. #define SDPCM_NEXTLEN_SHIFT 16 /* Next Read Len Shift */
  110. #define SDPCM_NEXTLEN_VALUE(p) ((((uint8 *)p)[2] & 0xff) << 4) /* p starts w/SW Header */
  111. #define SDPCM_NEXTLEN_OFFSET 2
  112. /* Data Offset from SOF (HW Tag, SW Tag, Pad) */
  113. #define SDPCM_DOFFSET_OFFSET 3 /* Data Offset */
  114. #define SDPCM_DOFFSET_VALUE(p) (((uint8 *)p)[SDPCM_DOFFSET_OFFSET] & 0xff)
  115. #define SDPCM_DOFFSET_MASK 0xff000000
  116. #define SDPCM_DOFFSET_SHIFT 24
  117. #define SDPCM_FCMASK_OFFSET 4 /* Flow control */
  118. #define SDPCM_FCMASK_VALUE(p) (((uint8 *)p)[SDPCM_FCMASK_OFFSET ] & 0xff)
  119. #define SDPCM_WINDOW_OFFSET 5 /* Credit based fc */
  120. #define SDPCM_WINDOW_VALUE(p) (((uint8 *)p)[SDPCM_WINDOW_OFFSET] & 0xff)
  121. #define SDPCM_VERSION_OFFSET 6 /* Version # */
  122. #define SDPCM_VERSION_VALUE(p) (((uint8 *)p)[SDPCM_VERSION_OFFSET] & 0xff)
  123. #define SDPCM_UNUSED_OFFSET 7 /* Spare */
  124. #define SDPCM_UNUSED_VALUE(p) (((uint8 *)p)[SDPCM_UNUSED_OFFSET] & 0xff)
  125. #define SDPCM_SWHEADER_LEN 8 /* SW header is 64 bits */
  126. /* logical channel numbers */
  127. #define SDPCM_CONTROL_CHANNEL 0 /* Control Request/Response Channel Id */
  128. #define SDPCM_EVENT_CHANNEL 1 /* Asyc Event Indication Channel Id */
  129. #define SDPCM_DATA_CHANNEL 2 /* Data Xmit/Recv Channel Id */
  130. #define SDPCM_GLOM_CHANNEL 3 /* For coalesced packets (superframes) */
  131. #define SDPCM_TEST_CHANNEL 15 /* Reserved for test/debug packets */
  132. #define SDPCM_MAX_CHANNEL 15
  133. #define SDPCM_SEQUENCE_WRAP 256 /* wrap-around val for eight-bit frame seq number */
  134. #define SDPCM_FLAG_RESVD0 0x01
  135. #define SDPCM_FLAG_RESVD1 0x02
  136. #define SDPCM_FLAG_GSPI_TXENAB 0x04
  137. #define SDPCM_FLAG_GLOMDESC 0x08 /* Superframe descriptor mask */
  138. /* For GLOM_CHANNEL frames, use a flag to indicate descriptor frame */
  139. #define SDPCM_GLOMDESC_FLAG (SDPCM_FLAG_GLOMDESC << SDPCM_FLAGS_SHIFT)
  140. #define SDPCM_GLOMDESC(p) (((uint8 *)p)[1] & 0x80)
  141. /* For TEST_CHANNEL packets, define another 4-byte header */
  142. #define SDPCM_TEST_HDRLEN 4 /* Generally: Cmd(1), Ext(1), Len(2);
  143. * Semantics of Ext byte depend on command.
  144. * Len is current or requested frame length, not
  145. * including test header; sent little-endian.
  146. */
  147. #define SDPCM_TEST_PKT_CNT_FLD_LEN 4 /* Packet count filed legth */
  148. #define SDPCM_TEST_DISCARD 0x01 /* Receiver discards. Ext is a pattern id. */
  149. #define SDPCM_TEST_ECHOREQ 0x02 /* Echo request. Ext is a pattern id. */
  150. #define SDPCM_TEST_ECHORSP 0x03 /* Echo response. Ext is a pattern id. */
  151. #define SDPCM_TEST_BURST 0x04 /* Receiver to send a burst. Ext is a frame count
  152. * (Backward compatabilty) Set frame count in a
  153. * 4 byte filed adjacent to the HDR
  154. */
  155. #define SDPCM_TEST_SEND 0x05 /* Receiver sets send mode. Ext is boolean on/off
  156. * Set frame count in a 4 byte filed adjacent to
  157. * the HDR
  158. */
  159. /* Handy macro for filling in datagen packets with a pattern */
  160. #define SDPCM_TEST_FILL(byteno, id) ((uint8)(id + byteno))
  161. /*
  162. * Software counters (first part matches hardware counters)
  163. */
  164. typedef volatile struct {
  165. uint32 cmd52rd; /* Cmd52RdCount, SDIO: cmd52 reads */
  166. uint32 cmd52wr; /* Cmd52WrCount, SDIO: cmd52 writes */
  167. uint32 cmd53rd; /* Cmd53RdCount, SDIO: cmd53 reads */
  168. uint32 cmd53wr; /* Cmd53WrCount, SDIO: cmd53 writes */
  169. uint32 abort; /* AbortCount, SDIO: aborts */
  170. uint32 datacrcerror; /* DataCrcErrorCount, SDIO: frames w/CRC error */
  171. uint32 rdoutofsync; /* RdOutOfSyncCount, SDIO/PCMCIA: Rd Frm out of sync */
  172. uint32 wroutofsync; /* RdOutOfSyncCount, SDIO/PCMCIA: Wr Frm out of sync */
  173. uint32 writebusy; /* WriteBusyCount, SDIO: device asserted "busy" */
  174. uint32 readwait; /* ReadWaitCount, SDIO: no data ready for a read cmd */
  175. uint32 readterm; /* ReadTermCount, SDIO: read frame termination cmds */
  176. uint32 writeterm; /* WriteTermCount, SDIO: write frames termination cmds */
  177. uint32 rxdescuflo; /* receive descriptor underflows */
  178. uint32 rxfifooflo; /* receive fifo overflows */
  179. uint32 txfifouflo; /* transmit fifo underflows */
  180. uint32 runt; /* runt (too short) frames recv'd from bus */
  181. uint32 badlen; /* frame's rxh len does not match its hw tag len */
  182. uint32 badcksum; /* frame's hw tag chksum doesn't agree with len value */
  183. uint32 seqbreak; /* break in sequence # space from one rx frame to the next */
  184. uint32 rxfcrc; /* frame rx header indicates crc error */
  185. uint32 rxfwoos; /* frame rx header indicates write out of sync */
  186. uint32 rxfwft; /* frame rx header indicates write frame termination */
  187. uint32 rxfabort; /* frame rx header indicates frame aborted */
  188. uint32 woosint; /* write out of sync interrupt */
  189. uint32 roosint; /* read out of sync interrupt */
  190. uint32 rftermint; /* read frame terminate interrupt */
  191. uint32 wftermint; /* write frame terminate interrupt */
  192. } sdpcmd_cnt_t;
  193. /*
  194. * Register Access Macros
  195. */
  196. #define SDIODREV_IS(var, val) ((var) == (val))
  197. #define SDIODREV_GE(var, val) ((var) >= (val))
  198. #define SDIODREV_GT(var, val) ((var) > (val))
  199. #define SDIODREV_LT(var, val) ((var) < (val))
  200. #define SDIODREV_LE(var, val) ((var) <= (val))
  201. #define SDIODDMAREG32(h, dir, chnl) \
  202. ((dir) == DMA_TX ? \
  203. (void *)(uintptr)&((h)->regs->dma.sdiod32.dma32regs[chnl].xmt) : \
  204. (void *)(uintptr)&((h)->regs->dma.sdiod32.dma32regs[chnl].rcv))
  205. #define SDIODDMAREG64(h, dir, chnl) \
  206. ((dir) == DMA_TX ? \
  207. (void *)(uintptr)&((h)->regs->dma.sdiod64.dma64regs[chnl].xmt) : \
  208. (void *)(uintptr)&((h)->regs->dma.sdiod64.dma64regs[chnl].rcv))
  209. #define SDIODDMAREG(h, dir, chnl) \
  210. (SDIODREV_LT((h)->corerev, 1) ? \
  211. SDIODDMAREG32((h), (dir), (chnl)) : \
  212. SDIODDMAREG64((h), (dir), (chnl)))
  213. #define PCMDDMAREG(h, dir, chnl) \
  214. ((dir) == DMA_TX ? \
  215. (void *)(uintptr)&((h)->regs->dma.pcm32.dmaregs.xmt) : \
  216. (void *)(uintptr)&((h)->regs->dma.pcm32.dmaregs.rcv))
  217. #define SDPCMDMAREG(h, dir, chnl, coreid) \
  218. ((coreid) == SDIOD_CORE_ID ? \
  219. SDIODDMAREG(h, dir, chnl) : \
  220. PCMDDMAREG(h, dir, chnl))
  221. #define SDIODFIFOREG(h, corerev) \
  222. (SDIODREV_LT((corerev), 1) ? \
  223. ((dma32diag_t *)(uintptr)&((h)->regs->dma.sdiod32.dmafifo)) : \
  224. ((dma32diag_t *)(uintptr)&((h)->regs->dma.sdiod64.dmafifo)))
  225. #define PCMDFIFOREG(h) \
  226. ((dma32diag_t *)(uintptr)&((h)->regs->dma.pcm32.dmafifo))
  227. #define SDPCMFIFOREG(h, coreid, corerev) \
  228. ((coreid) == SDIOD_CORE_ID ? \
  229. SDIODFIFOREG(h, corerev) : \
  230. PCMDFIFOREG(h))
  231. /*
  232. * Shared structure between dongle and the host.
  233. * The structure contains pointers to trap or assert information.
  234. */
  235. #define SDPCM_SHARED_VERSION 0x0001
  236. #define SDPCM_SHARED_VERSION_MASK 0x00FF
  237. #define SDPCM_SHARED_ASSERT_BUILT 0x0100
  238. #define SDPCM_SHARED_ASSERT 0x0200
  239. #define SDPCM_SHARED_TRAP 0x0400
  240. #define SDPCM_SHARED_IN_BRPT 0x0800
  241. #define SDPCM_SHARED_SET_BRPT 0x1000
  242. #define SDPCM_SHARED_PENDING_BRPT 0x2000
  243. #define SDPCM_SHARED_FATAL_LOGBUF_VALID 0x100000
  244. typedef struct {
  245. uint32 flags;
  246. uint32 trap_addr;
  247. uint32 assert_exp_addr;
  248. uint32 assert_file_addr;
  249. uint32 assert_line;
  250. uint32 console_addr; /* Address of hnd_cons_t */
  251. uint32 msgtrace_addr;
  252. uint32 fwid;
  253. uint32 device_fatal_logbuf_start;
  254. } sdpcm_shared_t;
  255. /* Device F/W provides the following access function:
  256. * sdpcm_shared_t *hnd_get_sdpcm_shared(void);
  257. */
  258. #endif /* _bcmsdpcm_h_ */