pcie.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /* @file mwifiex_pcie.h
  2. *
  3. * @brief This file contains definitions for PCI-E interface.
  4. * driver.
  5. *
  6. * Copyright (C) 2011-2014, Marvell International Ltd.
  7. *
  8. * This software file (the "File") is distributed by Marvell International
  9. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  10. * (the "License"). You may use, redistribute and/or modify this File in
  11. * accordance with the terms and conditions of the License, a copy of which
  12. * is available by writing to the Free Software Foundation, Inc.,
  13. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  14. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  15. *
  16. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  19. * this warranty disclaimer.
  20. */
  21. #ifndef _MWIFIEX_PCIE_H
  22. #define _MWIFIEX_PCIE_H
  23. #include <linux/pci.h>
  24. #include <linux/pcieport_if.h>
  25. #include <linux/interrupt.h>
  26. #include "main.h"
  27. #define PCIE8766_DEFAULT_FW_NAME "/*(DEBLOBBED)*/"
  28. #define PCIE8897_DEFAULT_FW_NAME "/*(DEBLOBBED)*/"
  29. #define PCIE_VENDOR_ID_MARVELL (0x11ab)
  30. #define PCIE_DEVICE_ID_MARVELL_88W8766P (0x2b30)
  31. #define PCIE_DEVICE_ID_MARVELL_88W8897 (0x2b38)
  32. /* Constants for Buffer Descriptor (BD) rings */
  33. #define MWIFIEX_MAX_TXRX_BD 0x20
  34. #define MWIFIEX_TXBD_MASK 0x3F
  35. #define MWIFIEX_RXBD_MASK 0x3F
  36. #define MWIFIEX_MAX_EVT_BD 0x08
  37. #define MWIFIEX_EVTBD_MASK 0x0f
  38. /* PCIE INTERNAL REGISTERS */
  39. #define PCIE_SCRATCH_0_REG 0xC10
  40. #define PCIE_SCRATCH_1_REG 0xC14
  41. #define PCIE_CPU_INT_EVENT 0xC18
  42. #define PCIE_CPU_INT_STATUS 0xC1C
  43. #define PCIE_HOST_INT_STATUS 0xC30
  44. #define PCIE_HOST_INT_MASK 0xC34
  45. #define PCIE_HOST_INT_STATUS_MASK 0xC3C
  46. #define PCIE_SCRATCH_2_REG 0xC40
  47. #define PCIE_SCRATCH_3_REG 0xC44
  48. #define PCIE_SCRATCH_4_REG 0xCD0
  49. #define PCIE_SCRATCH_5_REG 0xCD4
  50. #define PCIE_SCRATCH_6_REG 0xCD8
  51. #define PCIE_SCRATCH_7_REG 0xCDC
  52. #define PCIE_SCRATCH_8_REG 0xCE0
  53. #define PCIE_SCRATCH_9_REG 0xCE4
  54. #define PCIE_SCRATCH_10_REG 0xCE8
  55. #define PCIE_SCRATCH_11_REG 0xCEC
  56. #define PCIE_SCRATCH_12_REG 0xCF0
  57. #define PCIE_RD_DATA_PTR_Q0_Q1 0xC08C
  58. #define PCIE_WR_DATA_PTR_Q0_Q1 0xC05C
  59. #define CPU_INTR_DNLD_RDY BIT(0)
  60. #define CPU_INTR_DOOR_BELL BIT(1)
  61. #define CPU_INTR_SLEEP_CFM_DONE BIT(2)
  62. #define CPU_INTR_RESET BIT(3)
  63. #define CPU_INTR_EVENT_DONE BIT(5)
  64. #define HOST_INTR_DNLD_DONE BIT(0)
  65. #define HOST_INTR_UPLD_RDY BIT(1)
  66. #define HOST_INTR_CMD_DONE BIT(2)
  67. #define HOST_INTR_EVENT_RDY BIT(3)
  68. #define HOST_INTR_MASK (HOST_INTR_DNLD_DONE | \
  69. HOST_INTR_UPLD_RDY | \
  70. HOST_INTR_CMD_DONE | \
  71. HOST_INTR_EVENT_RDY)
  72. #define MWIFIEX_BD_FLAG_ROLLOVER_IND BIT(7)
  73. #define MWIFIEX_BD_FLAG_FIRST_DESC BIT(0)
  74. #define MWIFIEX_BD_FLAG_LAST_DESC BIT(1)
  75. #define MWIFIEX_BD_FLAG_SOP BIT(0)
  76. #define MWIFIEX_BD_FLAG_EOP BIT(1)
  77. #define MWIFIEX_BD_FLAG_XS_SOP BIT(2)
  78. #define MWIFIEX_BD_FLAG_XS_EOP BIT(3)
  79. #define MWIFIEX_BD_FLAG_EVT_ROLLOVER_IND BIT(7)
  80. #define MWIFIEX_BD_FLAG_RX_ROLLOVER_IND BIT(10)
  81. #define MWIFIEX_BD_FLAG_TX_START_PTR BIT(16)
  82. #define MWIFIEX_BD_FLAG_TX_ROLLOVER_IND BIT(26)
  83. /* Max retry number of command write */
  84. #define MAX_WRITE_IOMEM_RETRY 2
  85. /* Define PCIE block size for firmware download */
  86. #define MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD 256
  87. /* FW awake cookie after FW ready */
  88. #define FW_AWAKE_COOKIE (0xAA55AA55)
  89. #define MWIFIEX_DEF_SLEEP_COOKIE 0xBEEFBEEF
  90. #define MWIFIEX_MAX_DELAY_COUNT 5
  91. struct mwifiex_pcie_card_reg {
  92. u16 cmd_addr_lo;
  93. u16 cmd_addr_hi;
  94. u16 fw_status;
  95. u16 cmd_size;
  96. u16 cmdrsp_addr_lo;
  97. u16 cmdrsp_addr_hi;
  98. u16 tx_rdptr;
  99. u16 tx_wrptr;
  100. u16 rx_rdptr;
  101. u16 rx_wrptr;
  102. u16 evt_rdptr;
  103. u16 evt_wrptr;
  104. u16 drv_rdy;
  105. u16 tx_start_ptr;
  106. u32 tx_mask;
  107. u32 tx_wrap_mask;
  108. u32 rx_mask;
  109. u32 rx_wrap_mask;
  110. u32 tx_rollover_ind;
  111. u32 rx_rollover_ind;
  112. u32 evt_rollover_ind;
  113. u8 ring_flag_sop;
  114. u8 ring_flag_eop;
  115. u8 ring_flag_xs_sop;
  116. u8 ring_flag_xs_eop;
  117. u32 ring_tx_start_ptr;
  118. u8 pfu_enabled;
  119. u8 sleep_cookie;
  120. u16 fw_dump_ctrl;
  121. u16 fw_dump_start;
  122. u16 fw_dump_end;
  123. };
  124. static const struct mwifiex_pcie_card_reg mwifiex_reg_8766 = {
  125. .cmd_addr_lo = PCIE_SCRATCH_0_REG,
  126. .cmd_addr_hi = PCIE_SCRATCH_1_REG,
  127. .cmd_size = PCIE_SCRATCH_2_REG,
  128. .fw_status = PCIE_SCRATCH_3_REG,
  129. .cmdrsp_addr_lo = PCIE_SCRATCH_4_REG,
  130. .cmdrsp_addr_hi = PCIE_SCRATCH_5_REG,
  131. .tx_rdptr = PCIE_SCRATCH_6_REG,
  132. .tx_wrptr = PCIE_SCRATCH_7_REG,
  133. .rx_rdptr = PCIE_SCRATCH_8_REG,
  134. .rx_wrptr = PCIE_SCRATCH_9_REG,
  135. .evt_rdptr = PCIE_SCRATCH_10_REG,
  136. .evt_wrptr = PCIE_SCRATCH_11_REG,
  137. .drv_rdy = PCIE_SCRATCH_12_REG,
  138. .tx_start_ptr = 0,
  139. .tx_mask = MWIFIEX_TXBD_MASK,
  140. .tx_wrap_mask = 0,
  141. .rx_mask = MWIFIEX_RXBD_MASK,
  142. .rx_wrap_mask = 0,
  143. .tx_rollover_ind = MWIFIEX_BD_FLAG_ROLLOVER_IND,
  144. .rx_rollover_ind = MWIFIEX_BD_FLAG_ROLLOVER_IND,
  145. .evt_rollover_ind = MWIFIEX_BD_FLAG_ROLLOVER_IND,
  146. .ring_flag_sop = 0,
  147. .ring_flag_eop = 0,
  148. .ring_flag_xs_sop = 0,
  149. .ring_flag_xs_eop = 0,
  150. .ring_tx_start_ptr = 0,
  151. .pfu_enabled = 0,
  152. .sleep_cookie = 1,
  153. };
  154. static const struct mwifiex_pcie_card_reg mwifiex_reg_8897 = {
  155. .cmd_addr_lo = PCIE_SCRATCH_0_REG,
  156. .cmd_addr_hi = PCIE_SCRATCH_1_REG,
  157. .cmd_size = PCIE_SCRATCH_2_REG,
  158. .fw_status = PCIE_SCRATCH_3_REG,
  159. .cmdrsp_addr_lo = PCIE_SCRATCH_4_REG,
  160. .cmdrsp_addr_hi = PCIE_SCRATCH_5_REG,
  161. .tx_rdptr = PCIE_RD_DATA_PTR_Q0_Q1,
  162. .tx_wrptr = PCIE_WR_DATA_PTR_Q0_Q1,
  163. .rx_rdptr = PCIE_WR_DATA_PTR_Q0_Q1,
  164. .rx_wrptr = PCIE_RD_DATA_PTR_Q0_Q1,
  165. .evt_rdptr = PCIE_SCRATCH_10_REG,
  166. .evt_wrptr = PCIE_SCRATCH_11_REG,
  167. .drv_rdy = PCIE_SCRATCH_12_REG,
  168. .tx_start_ptr = 16,
  169. .tx_mask = 0x03FF0000,
  170. .tx_wrap_mask = 0x07FF0000,
  171. .rx_mask = 0x000003FF,
  172. .rx_wrap_mask = 0x000007FF,
  173. .tx_rollover_ind = MWIFIEX_BD_FLAG_TX_ROLLOVER_IND,
  174. .rx_rollover_ind = MWIFIEX_BD_FLAG_RX_ROLLOVER_IND,
  175. .evt_rollover_ind = MWIFIEX_BD_FLAG_EVT_ROLLOVER_IND,
  176. .ring_flag_sop = MWIFIEX_BD_FLAG_SOP,
  177. .ring_flag_eop = MWIFIEX_BD_FLAG_EOP,
  178. .ring_flag_xs_sop = MWIFIEX_BD_FLAG_XS_SOP,
  179. .ring_flag_xs_eop = MWIFIEX_BD_FLAG_XS_EOP,
  180. .ring_tx_start_ptr = MWIFIEX_BD_FLAG_TX_START_PTR,
  181. .pfu_enabled = 1,
  182. .sleep_cookie = 0,
  183. .fw_dump_ctrl = 0xcf4,
  184. .fw_dump_start = 0xcf8,
  185. .fw_dump_end = 0xcff
  186. };
  187. struct mwifiex_pcie_device {
  188. const char *firmware;
  189. const struct mwifiex_pcie_card_reg *reg;
  190. u16 blksz_fw_dl;
  191. u16 tx_buf_size;
  192. bool can_dump_fw;
  193. bool can_ext_scan;
  194. };
  195. static const struct mwifiex_pcie_device mwifiex_pcie8766 = {
  196. .firmware = PCIE8766_DEFAULT_FW_NAME,
  197. .reg = &mwifiex_reg_8766,
  198. .blksz_fw_dl = MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD,
  199. .tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K,
  200. .can_dump_fw = false,
  201. .can_ext_scan = true,
  202. };
  203. static const struct mwifiex_pcie_device mwifiex_pcie8897 = {
  204. .firmware = PCIE8897_DEFAULT_FW_NAME,
  205. .reg = &mwifiex_reg_8897,
  206. .blksz_fw_dl = MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD,
  207. .tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K,
  208. .can_dump_fw = true,
  209. .can_ext_scan = true,
  210. };
  211. struct mwifiex_evt_buf_desc {
  212. u64 paddr;
  213. u16 len;
  214. u16 flags;
  215. } __packed;
  216. struct mwifiex_pcie_buf_desc {
  217. u64 paddr;
  218. u16 len;
  219. u16 flags;
  220. } __packed;
  221. struct mwifiex_pfu_buf_desc {
  222. u16 flags;
  223. u16 offset;
  224. u16 frag_len;
  225. u16 len;
  226. u64 paddr;
  227. u32 reserved;
  228. } __packed;
  229. struct pcie_service_card {
  230. struct pci_dev *dev;
  231. struct mwifiex_adapter *adapter;
  232. struct mwifiex_pcie_device pcie;
  233. u8 txbd_flush;
  234. u32 txbd_wrptr;
  235. u32 txbd_rdptr;
  236. u32 txbd_ring_size;
  237. u8 *txbd_ring_vbase;
  238. dma_addr_t txbd_ring_pbase;
  239. void *txbd_ring[MWIFIEX_MAX_TXRX_BD];
  240. struct sk_buff *tx_buf_list[MWIFIEX_MAX_TXRX_BD];
  241. u32 rxbd_wrptr;
  242. u32 rxbd_rdptr;
  243. u32 rxbd_ring_size;
  244. u8 *rxbd_ring_vbase;
  245. dma_addr_t rxbd_ring_pbase;
  246. void *rxbd_ring[MWIFIEX_MAX_TXRX_BD];
  247. struct sk_buff *rx_buf_list[MWIFIEX_MAX_TXRX_BD];
  248. u32 evtbd_wrptr;
  249. u32 evtbd_rdptr;
  250. u32 evtbd_ring_size;
  251. u8 *evtbd_ring_vbase;
  252. dma_addr_t evtbd_ring_pbase;
  253. void *evtbd_ring[MWIFIEX_MAX_EVT_BD];
  254. struct sk_buff *evt_buf_list[MWIFIEX_MAX_EVT_BD];
  255. struct sk_buff *cmd_buf;
  256. struct sk_buff *cmdrsp_buf;
  257. u8 *sleep_cookie_vbase;
  258. dma_addr_t sleep_cookie_pbase;
  259. void __iomem *pci_mmap;
  260. void __iomem *pci_mmap1;
  261. };
  262. static inline int
  263. mwifiex_pcie_txbd_empty(struct pcie_service_card *card, u32 rdptr)
  264. {
  265. const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
  266. switch (card->dev->device) {
  267. case PCIE_DEVICE_ID_MARVELL_88W8766P:
  268. if (((card->txbd_wrptr & reg->tx_mask) ==
  269. (rdptr & reg->tx_mask)) &&
  270. ((card->txbd_wrptr & reg->tx_rollover_ind) !=
  271. (rdptr & reg->tx_rollover_ind)))
  272. return 1;
  273. break;
  274. case PCIE_DEVICE_ID_MARVELL_88W8897:
  275. if (((card->txbd_wrptr & reg->tx_mask) ==
  276. (rdptr & reg->tx_mask)) &&
  277. ((card->txbd_wrptr & reg->tx_rollover_ind) ==
  278. (rdptr & reg->tx_rollover_ind)))
  279. return 1;
  280. break;
  281. }
  282. return 0;
  283. }
  284. static inline int
  285. mwifiex_pcie_txbd_not_full(struct pcie_service_card *card)
  286. {
  287. const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
  288. switch (card->dev->device) {
  289. case PCIE_DEVICE_ID_MARVELL_88W8766P:
  290. if (((card->txbd_wrptr & reg->tx_mask) !=
  291. (card->txbd_rdptr & reg->tx_mask)) ||
  292. ((card->txbd_wrptr & reg->tx_rollover_ind) !=
  293. (card->txbd_rdptr & reg->tx_rollover_ind)))
  294. return 1;
  295. break;
  296. case PCIE_DEVICE_ID_MARVELL_88W8897:
  297. if (((card->txbd_wrptr & reg->tx_mask) !=
  298. (card->txbd_rdptr & reg->tx_mask)) ||
  299. ((card->txbd_wrptr & reg->tx_rollover_ind) ==
  300. (card->txbd_rdptr & reg->tx_rollover_ind)))
  301. return 1;
  302. break;
  303. }
  304. return 0;
  305. }
  306. #endif /* _MWIFIEX_PCIE_H */