pcie.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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 "mrvl/pcie8766_uapsta.bin"
  28. #define PCIE8897_DEFAULT_FW_NAME "mrvl/pcie8897_uapsta.bin"
  29. #define PCIE8997_DEFAULT_FW_NAME "mrvl/pcie8997_uapsta.bin"
  30. #define PCIE_VENDOR_ID_MARVELL (0x11ab)
  31. #define PCIE_DEVICE_ID_MARVELL_88W8766P (0x2b30)
  32. #define PCIE_DEVICE_ID_MARVELL_88W8897 (0x2b38)
  33. #define PCIE_DEVICE_ID_MARVELL_88W8997 (0x2b42)
  34. /* Constants for Buffer Descriptor (BD) rings */
  35. #define MWIFIEX_MAX_TXRX_BD 0x20
  36. #define MWIFIEX_TXBD_MASK 0x3F
  37. #define MWIFIEX_RXBD_MASK 0x3F
  38. #define MWIFIEX_MAX_EVT_BD 0x08
  39. #define MWIFIEX_EVTBD_MASK 0x0f
  40. /* PCIE INTERNAL REGISTERS */
  41. #define PCIE_SCRATCH_0_REG 0xC10
  42. #define PCIE_SCRATCH_1_REG 0xC14
  43. #define PCIE_CPU_INT_EVENT 0xC18
  44. #define PCIE_CPU_INT_STATUS 0xC1C
  45. #define PCIE_HOST_INT_STATUS 0xC30
  46. #define PCIE_HOST_INT_MASK 0xC34
  47. #define PCIE_HOST_INT_STATUS_MASK 0xC3C
  48. #define PCIE_SCRATCH_2_REG 0xC40
  49. #define PCIE_SCRATCH_3_REG 0xC44
  50. #define PCIE_SCRATCH_4_REG 0xCD0
  51. #define PCIE_SCRATCH_5_REG 0xCD4
  52. #define PCIE_SCRATCH_6_REG 0xCD8
  53. #define PCIE_SCRATCH_7_REG 0xCDC
  54. #define PCIE_SCRATCH_8_REG 0xCE0
  55. #define PCIE_SCRATCH_9_REG 0xCE4
  56. #define PCIE_SCRATCH_10_REG 0xCE8
  57. #define PCIE_SCRATCH_11_REG 0xCEC
  58. #define PCIE_SCRATCH_12_REG 0xCF0
  59. #define PCIE_RD_DATA_PTR_Q0_Q1 0xC08C
  60. #define PCIE_WR_DATA_PTR_Q0_Q1 0xC05C
  61. #define CPU_INTR_DNLD_RDY BIT(0)
  62. #define CPU_INTR_DOOR_BELL BIT(1)
  63. #define CPU_INTR_SLEEP_CFM_DONE BIT(2)
  64. #define CPU_INTR_RESET BIT(3)
  65. #define CPU_INTR_EVENT_DONE BIT(5)
  66. #define HOST_INTR_DNLD_DONE BIT(0)
  67. #define HOST_INTR_UPLD_RDY BIT(1)
  68. #define HOST_INTR_CMD_DONE BIT(2)
  69. #define HOST_INTR_EVENT_RDY BIT(3)
  70. #define HOST_INTR_MASK (HOST_INTR_DNLD_DONE | \
  71. HOST_INTR_UPLD_RDY | \
  72. HOST_INTR_CMD_DONE | \
  73. HOST_INTR_EVENT_RDY)
  74. #define MWIFIEX_BD_FLAG_ROLLOVER_IND BIT(7)
  75. #define MWIFIEX_BD_FLAG_FIRST_DESC BIT(0)
  76. #define MWIFIEX_BD_FLAG_LAST_DESC BIT(1)
  77. #define MWIFIEX_BD_FLAG_SOP BIT(0)
  78. #define MWIFIEX_BD_FLAG_EOP BIT(1)
  79. #define MWIFIEX_BD_FLAG_XS_SOP BIT(2)
  80. #define MWIFIEX_BD_FLAG_XS_EOP BIT(3)
  81. #define MWIFIEX_BD_FLAG_EVT_ROLLOVER_IND BIT(7)
  82. #define MWIFIEX_BD_FLAG_RX_ROLLOVER_IND BIT(10)
  83. #define MWIFIEX_BD_FLAG_TX_START_PTR BIT(16)
  84. #define MWIFIEX_BD_FLAG_TX_ROLLOVER_IND BIT(26)
  85. /* Max retry number of command write */
  86. #define MAX_WRITE_IOMEM_RETRY 2
  87. /* Define PCIE block size for firmware download */
  88. #define MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD 256
  89. /* FW awake cookie after FW ready */
  90. #define FW_AWAKE_COOKIE (0xAA55AA55)
  91. #define MWIFIEX_DEF_SLEEP_COOKIE 0xBEEFBEEF
  92. #define MWIFIEX_MAX_DELAY_COUNT 5
  93. struct mwifiex_pcie_card_reg {
  94. u16 cmd_addr_lo;
  95. u16 cmd_addr_hi;
  96. u16 fw_status;
  97. u16 cmd_size;
  98. u16 cmdrsp_addr_lo;
  99. u16 cmdrsp_addr_hi;
  100. u16 tx_rdptr;
  101. u16 tx_wrptr;
  102. u16 rx_rdptr;
  103. u16 rx_wrptr;
  104. u16 evt_rdptr;
  105. u16 evt_wrptr;
  106. u16 drv_rdy;
  107. u16 tx_start_ptr;
  108. u32 tx_mask;
  109. u32 tx_wrap_mask;
  110. u32 rx_mask;
  111. u32 rx_wrap_mask;
  112. u32 tx_rollover_ind;
  113. u32 rx_rollover_ind;
  114. u32 evt_rollover_ind;
  115. u8 ring_flag_sop;
  116. u8 ring_flag_eop;
  117. u8 ring_flag_xs_sop;
  118. u8 ring_flag_xs_eop;
  119. u32 ring_tx_start_ptr;
  120. u8 pfu_enabled;
  121. u8 sleep_cookie;
  122. u16 fw_dump_ctrl;
  123. u16 fw_dump_start;
  124. u16 fw_dump_end;
  125. };
  126. static const struct mwifiex_pcie_card_reg mwifiex_reg_8766 = {
  127. .cmd_addr_lo = PCIE_SCRATCH_0_REG,
  128. .cmd_addr_hi = PCIE_SCRATCH_1_REG,
  129. .cmd_size = PCIE_SCRATCH_2_REG,
  130. .fw_status = PCIE_SCRATCH_3_REG,
  131. .cmdrsp_addr_lo = PCIE_SCRATCH_4_REG,
  132. .cmdrsp_addr_hi = PCIE_SCRATCH_5_REG,
  133. .tx_rdptr = PCIE_SCRATCH_6_REG,
  134. .tx_wrptr = PCIE_SCRATCH_7_REG,
  135. .rx_rdptr = PCIE_SCRATCH_8_REG,
  136. .rx_wrptr = PCIE_SCRATCH_9_REG,
  137. .evt_rdptr = PCIE_SCRATCH_10_REG,
  138. .evt_wrptr = PCIE_SCRATCH_11_REG,
  139. .drv_rdy = PCIE_SCRATCH_12_REG,
  140. .tx_start_ptr = 0,
  141. .tx_mask = MWIFIEX_TXBD_MASK,
  142. .tx_wrap_mask = 0,
  143. .rx_mask = MWIFIEX_RXBD_MASK,
  144. .rx_wrap_mask = 0,
  145. .tx_rollover_ind = MWIFIEX_BD_FLAG_ROLLOVER_IND,
  146. .rx_rollover_ind = MWIFIEX_BD_FLAG_ROLLOVER_IND,
  147. .evt_rollover_ind = MWIFIEX_BD_FLAG_ROLLOVER_IND,
  148. .ring_flag_sop = 0,
  149. .ring_flag_eop = 0,
  150. .ring_flag_xs_sop = 0,
  151. .ring_flag_xs_eop = 0,
  152. .ring_tx_start_ptr = 0,
  153. .pfu_enabled = 0,
  154. .sleep_cookie = 1,
  155. };
  156. static const struct mwifiex_pcie_card_reg mwifiex_reg_8897 = {
  157. .cmd_addr_lo = PCIE_SCRATCH_0_REG,
  158. .cmd_addr_hi = PCIE_SCRATCH_1_REG,
  159. .cmd_size = PCIE_SCRATCH_2_REG,
  160. .fw_status = PCIE_SCRATCH_3_REG,
  161. .cmdrsp_addr_lo = PCIE_SCRATCH_4_REG,
  162. .cmdrsp_addr_hi = PCIE_SCRATCH_5_REG,
  163. .tx_rdptr = PCIE_RD_DATA_PTR_Q0_Q1,
  164. .tx_wrptr = PCIE_WR_DATA_PTR_Q0_Q1,
  165. .rx_rdptr = PCIE_WR_DATA_PTR_Q0_Q1,
  166. .rx_wrptr = PCIE_RD_DATA_PTR_Q0_Q1,
  167. .evt_rdptr = PCIE_SCRATCH_10_REG,
  168. .evt_wrptr = PCIE_SCRATCH_11_REG,
  169. .drv_rdy = PCIE_SCRATCH_12_REG,
  170. .tx_start_ptr = 16,
  171. .tx_mask = 0x03FF0000,
  172. .tx_wrap_mask = 0x07FF0000,
  173. .rx_mask = 0x000003FF,
  174. .rx_wrap_mask = 0x000007FF,
  175. .tx_rollover_ind = MWIFIEX_BD_FLAG_TX_ROLLOVER_IND,
  176. .rx_rollover_ind = MWIFIEX_BD_FLAG_RX_ROLLOVER_IND,
  177. .evt_rollover_ind = MWIFIEX_BD_FLAG_EVT_ROLLOVER_IND,
  178. .ring_flag_sop = MWIFIEX_BD_FLAG_SOP,
  179. .ring_flag_eop = MWIFIEX_BD_FLAG_EOP,
  180. .ring_flag_xs_sop = MWIFIEX_BD_FLAG_XS_SOP,
  181. .ring_flag_xs_eop = MWIFIEX_BD_FLAG_XS_EOP,
  182. .ring_tx_start_ptr = MWIFIEX_BD_FLAG_TX_START_PTR,
  183. .pfu_enabled = 1,
  184. .sleep_cookie = 0,
  185. .fw_dump_ctrl = 0xcf4,
  186. .fw_dump_start = 0xcf8,
  187. .fw_dump_end = 0xcff,
  188. };
  189. static const struct mwifiex_pcie_card_reg mwifiex_reg_8997 = {
  190. .cmd_addr_lo = PCIE_SCRATCH_0_REG,
  191. .cmd_addr_hi = PCIE_SCRATCH_1_REG,
  192. .cmd_size = PCIE_SCRATCH_2_REG,
  193. .fw_status = PCIE_SCRATCH_3_REG,
  194. .cmdrsp_addr_lo = PCIE_SCRATCH_4_REG,
  195. .cmdrsp_addr_hi = PCIE_SCRATCH_5_REG,
  196. .tx_rdptr = 0xC1A4,
  197. .tx_wrptr = 0xC1A8,
  198. .rx_rdptr = 0xC1A8,
  199. .rx_wrptr = 0xC1A4,
  200. .evt_rdptr = PCIE_SCRATCH_10_REG,
  201. .evt_wrptr = PCIE_SCRATCH_11_REG,
  202. .drv_rdy = PCIE_SCRATCH_12_REG,
  203. .tx_start_ptr = 16,
  204. .tx_mask = 0x0FFF0000,
  205. .tx_wrap_mask = 0x01FF0000,
  206. .rx_mask = 0x00000FFF,
  207. .rx_wrap_mask = 0x000001FF,
  208. .tx_rollover_ind = BIT(28),
  209. .rx_rollover_ind = BIT(12),
  210. .evt_rollover_ind = MWIFIEX_BD_FLAG_EVT_ROLLOVER_IND,
  211. .ring_flag_sop = MWIFIEX_BD_FLAG_SOP,
  212. .ring_flag_eop = MWIFIEX_BD_FLAG_EOP,
  213. .ring_flag_xs_sop = MWIFIEX_BD_FLAG_XS_SOP,
  214. .ring_flag_xs_eop = MWIFIEX_BD_FLAG_XS_EOP,
  215. .ring_tx_start_ptr = MWIFIEX_BD_FLAG_TX_START_PTR,
  216. .pfu_enabled = 1,
  217. .sleep_cookie = 0,
  218. };
  219. struct mwifiex_pcie_device {
  220. const char *firmware;
  221. const struct mwifiex_pcie_card_reg *reg;
  222. u16 blksz_fw_dl;
  223. u16 tx_buf_size;
  224. bool can_dump_fw;
  225. bool can_ext_scan;
  226. };
  227. static const struct mwifiex_pcie_device mwifiex_pcie8766 = {
  228. .firmware = PCIE8766_DEFAULT_FW_NAME,
  229. .reg = &mwifiex_reg_8766,
  230. .blksz_fw_dl = MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD,
  231. .tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K,
  232. .can_dump_fw = false,
  233. .can_ext_scan = true,
  234. };
  235. static const struct mwifiex_pcie_device mwifiex_pcie8897 = {
  236. .firmware = PCIE8897_DEFAULT_FW_NAME,
  237. .reg = &mwifiex_reg_8897,
  238. .blksz_fw_dl = MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD,
  239. .tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K,
  240. .can_dump_fw = true,
  241. .can_ext_scan = true,
  242. };
  243. static const struct mwifiex_pcie_device mwifiex_pcie8997 = {
  244. .firmware = PCIE8997_DEFAULT_FW_NAME,
  245. .reg = &mwifiex_reg_8997,
  246. .blksz_fw_dl = MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD,
  247. .tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K,
  248. .can_dump_fw = false,
  249. .can_ext_scan = true,
  250. };
  251. struct mwifiex_evt_buf_desc {
  252. u64 paddr;
  253. u16 len;
  254. u16 flags;
  255. } __packed;
  256. struct mwifiex_pcie_buf_desc {
  257. u64 paddr;
  258. u16 len;
  259. u16 flags;
  260. } __packed;
  261. struct mwifiex_pfu_buf_desc {
  262. u16 flags;
  263. u16 offset;
  264. u16 frag_len;
  265. u16 len;
  266. u64 paddr;
  267. u32 reserved;
  268. } __packed;
  269. struct pcie_service_card {
  270. struct pci_dev *dev;
  271. struct mwifiex_adapter *adapter;
  272. struct mwifiex_pcie_device pcie;
  273. u8 txbd_flush;
  274. u32 txbd_wrptr;
  275. u32 txbd_rdptr;
  276. u32 txbd_ring_size;
  277. u8 *txbd_ring_vbase;
  278. dma_addr_t txbd_ring_pbase;
  279. void *txbd_ring[MWIFIEX_MAX_TXRX_BD];
  280. struct sk_buff *tx_buf_list[MWIFIEX_MAX_TXRX_BD];
  281. u32 rxbd_wrptr;
  282. u32 rxbd_rdptr;
  283. u32 rxbd_ring_size;
  284. u8 *rxbd_ring_vbase;
  285. dma_addr_t rxbd_ring_pbase;
  286. void *rxbd_ring[MWIFIEX_MAX_TXRX_BD];
  287. struct sk_buff *rx_buf_list[MWIFIEX_MAX_TXRX_BD];
  288. u32 evtbd_wrptr;
  289. u32 evtbd_rdptr;
  290. u32 evtbd_ring_size;
  291. u8 *evtbd_ring_vbase;
  292. dma_addr_t evtbd_ring_pbase;
  293. void *evtbd_ring[MWIFIEX_MAX_EVT_BD];
  294. struct sk_buff *evt_buf_list[MWIFIEX_MAX_EVT_BD];
  295. struct sk_buff *cmd_buf;
  296. struct sk_buff *cmdrsp_buf;
  297. u8 *sleep_cookie_vbase;
  298. dma_addr_t sleep_cookie_pbase;
  299. void __iomem *pci_mmap;
  300. void __iomem *pci_mmap1;
  301. };
  302. static inline int
  303. mwifiex_pcie_txbd_empty(struct pcie_service_card *card, u32 rdptr)
  304. {
  305. const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
  306. switch (card->dev->device) {
  307. case PCIE_DEVICE_ID_MARVELL_88W8766P:
  308. if (((card->txbd_wrptr & reg->tx_mask) ==
  309. (rdptr & reg->tx_mask)) &&
  310. ((card->txbd_wrptr & reg->tx_rollover_ind) !=
  311. (rdptr & reg->tx_rollover_ind)))
  312. return 1;
  313. break;
  314. case PCIE_DEVICE_ID_MARVELL_88W8897:
  315. if (((card->txbd_wrptr & reg->tx_mask) ==
  316. (rdptr & reg->tx_mask)) &&
  317. ((card->txbd_wrptr & reg->tx_rollover_ind) ==
  318. (rdptr & reg->tx_rollover_ind)))
  319. return 1;
  320. break;
  321. }
  322. return 0;
  323. }
  324. static inline int
  325. mwifiex_pcie_txbd_not_full(struct pcie_service_card *card)
  326. {
  327. const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
  328. switch (card->dev->device) {
  329. case PCIE_DEVICE_ID_MARVELL_88W8766P:
  330. if (((card->txbd_wrptr & reg->tx_mask) !=
  331. (card->txbd_rdptr & reg->tx_mask)) ||
  332. ((card->txbd_wrptr & reg->tx_rollover_ind) !=
  333. (card->txbd_rdptr & reg->tx_rollover_ind)))
  334. return 1;
  335. break;
  336. case PCIE_DEVICE_ID_MARVELL_88W8897:
  337. case PCIE_DEVICE_ID_MARVELL_88W8997:
  338. if (((card->txbd_wrptr & reg->tx_mask) !=
  339. (card->txbd_rdptr & reg->tx_mask)) ||
  340. ((card->txbd_wrptr & reg->tx_rollover_ind) ==
  341. (card->txbd_rdptr & reg->tx_rollover_ind)))
  342. return 1;
  343. break;
  344. }
  345. return 0;
  346. }
  347. #endif /* _MWIFIEX_PCIE_H */