sdio.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Copyright (c) 2004-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
  4. * Copyright (c) 2016-2017 Erik Stromdahl <erik.stromdahl@gmail.com>
  5. *
  6. * Permission to use, copy, modify, and/or distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #ifndef _SDIO_H_
  19. #define _SDIO_H_
  20. #define ATH10K_HIF_MBOX_BLOCK_SIZE 256
  21. #define QCA_MANUFACTURER_ID_BASE GENMASK(11, 8)
  22. #define QCA_MANUFACTURER_ID_AR6005_BASE 0x5
  23. #define QCA_MANUFACTURER_ID_QCA9377_BASE 0x7
  24. #define QCA_SDIO_ID_AR6005_BASE 0x500
  25. #define QCA_SDIO_ID_QCA9377_BASE 0x700
  26. #define QCA_MANUFACTURER_ID_REV_MASK 0x00FF
  27. #define QCA_MANUFACTURER_CODE 0x271 /* Qualcomm/Atheros */
  28. #define ATH10K_SDIO_MAX_BUFFER_SIZE 4096 /*Unsure of this constant*/
  29. /* Mailbox address in SDIO address space */
  30. #define ATH10K_HIF_MBOX_BASE_ADDR 0x1000
  31. #define ATH10K_HIF_MBOX_WIDTH 0x800
  32. #define ATH10K_HIF_MBOX_TOT_WIDTH \
  33. (ATH10K_HIF_MBOX_NUM_MAX * ATH10K_HIF_MBOX_WIDTH)
  34. #define ATH10K_HIF_MBOX0_EXT_BASE_ADDR 0x5000
  35. #define ATH10K_HIF_MBOX0_EXT_WIDTH (36 * 1024)
  36. #define ATH10K_HIF_MBOX0_EXT_WIDTH_ROME_2_0 (56 * 1024)
  37. #define ATH10K_HIF_MBOX1_EXT_WIDTH (36 * 1024)
  38. #define ATH10K_HIF_MBOX_DUMMY_SPACE_SIZE (2 * 1024)
  39. #define ATH10K_HTC_MBOX_MAX_PAYLOAD_LENGTH \
  40. (ATH10K_SDIO_MAX_BUFFER_SIZE - sizeof(struct ath10k_htc_hdr))
  41. #define ATH10K_HIF_MBOX_NUM_MAX 4
  42. #define ATH10K_SDIO_BUS_REQUEST_MAX_NUM 64
  43. #define ATH10K_SDIO_HIF_COMMUNICATION_TIMEOUT_HZ (100 * HZ)
  44. /* HTC runs over mailbox 0 */
  45. #define ATH10K_HTC_MAILBOX 0
  46. #define ATH10K_HTC_MAILBOX_MASK BIT(ATH10K_HTC_MAILBOX)
  47. /* GMBOX addresses */
  48. #define ATH10K_HIF_GMBOX_BASE_ADDR 0x7000
  49. #define ATH10K_HIF_GMBOX_WIDTH 0x4000
  50. /* Modified versions of the sdio.h macros.
  51. * The macros in sdio.h can't be used easily with the FIELD_{PREP|GET}
  52. * macros in bitfield.h, so we define our own macros here.
  53. */
  54. #define ATH10K_SDIO_DRIVE_DTSX_MASK \
  55. (SDIO_DRIVE_DTSx_MASK << SDIO_DRIVE_DTSx_SHIFT)
  56. #define ATH10K_SDIO_DRIVE_DTSX_TYPE_B 0
  57. #define ATH10K_SDIO_DRIVE_DTSX_TYPE_A 1
  58. #define ATH10K_SDIO_DRIVE_DTSX_TYPE_C 2
  59. #define ATH10K_SDIO_DRIVE_DTSX_TYPE_D 3
  60. /* SDIO CCCR register definitions */
  61. #define CCCR_SDIO_IRQ_MODE_REG 0xF0
  62. #define CCCR_SDIO_IRQ_MODE_REG_SDIO3 0x16
  63. #define CCCR_SDIO_DRIVER_STRENGTH_ENABLE_ADDR 0xF2
  64. #define CCCR_SDIO_DRIVER_STRENGTH_ENABLE_A 0x02
  65. #define CCCR_SDIO_DRIVER_STRENGTH_ENABLE_C 0x04
  66. #define CCCR_SDIO_DRIVER_STRENGTH_ENABLE_D 0x08
  67. #define CCCR_SDIO_ASYNC_INT_DELAY_ADDRESS 0xF0
  68. #define CCCR_SDIO_ASYNC_INT_DELAY_MASK 0xC0
  69. /* mode to enable special 4-bit interrupt assertion without clock */
  70. #define SDIO_IRQ_MODE_ASYNC_4BIT_IRQ BIT(0)
  71. #define SDIO_IRQ_MODE_ASYNC_4BIT_IRQ_SDIO3 BIT(1)
  72. #define ATH10K_SDIO_TARGET_DEBUG_INTR_MASK 0x01
  73. /* The theoretical maximum number of RX messages that can be fetched
  74. * from the mbox interrupt handler in one loop is derived in the following
  75. * way:
  76. *
  77. * Let's assume that each packet in a bundle of the maximum bundle size
  78. * (HTC_HOST_MAX_MSG_PER_BUNDLE) has the HTC header bundle count set
  79. * to the maximum value (HTC_HOST_MAX_MSG_PER_BUNDLE).
  80. *
  81. * in this case the driver must allocate
  82. * (HTC_HOST_MAX_MSG_PER_BUNDLE * HTC_HOST_MAX_MSG_PER_BUNDLE) skb's.
  83. */
  84. #define ATH10K_SDIO_MAX_RX_MSGS \
  85. (HTC_HOST_MAX_MSG_PER_BUNDLE * HTC_HOST_MAX_MSG_PER_BUNDLE)
  86. #define ATH10K_FIFO_TIMEOUT_AND_CHIP_CONTROL 0x00000868u
  87. #define ATH10K_FIFO_TIMEOUT_AND_CHIP_CONTROL_DISABLE_SLEEP_OFF 0xFFFEFFFF
  88. #define ATH10K_FIFO_TIMEOUT_AND_CHIP_CONTROL_DISABLE_SLEEP_ON 0x10000
  89. struct ath10k_sdio_bus_request {
  90. struct list_head list;
  91. /* sdio address */
  92. u32 address;
  93. struct sk_buff *skb;
  94. enum ath10k_htc_ep_id eid;
  95. int status;
  96. /* Specifies if the current request is an HTC message.
  97. * If not, the eid is not applicable an the TX completion handler
  98. * associated with the endpoint will not be invoked.
  99. */
  100. bool htc_msg;
  101. /* Completion that (if set) will be invoked for non HTC requests
  102. * (htc_msg == false) when the request has been processed.
  103. */
  104. struct completion *comp;
  105. };
  106. struct ath10k_sdio_rx_data {
  107. struct sk_buff *skb;
  108. size_t alloc_len;
  109. size_t act_len;
  110. enum ath10k_htc_ep_id eid;
  111. bool part_of_bundle;
  112. bool last_in_bundle;
  113. bool trailer_only;
  114. int status;
  115. };
  116. struct ath10k_sdio_irq_proc_regs {
  117. u8 host_int_status;
  118. u8 cpu_int_status;
  119. u8 error_int_status;
  120. u8 counter_int_status;
  121. u8 mbox_frame;
  122. u8 rx_lookahead_valid;
  123. u8 host_int_status2;
  124. u8 gmbox_rx_avail;
  125. __le32 rx_lookahead[2];
  126. __le32 rx_gmbox_lookahead_alias[2];
  127. };
  128. struct ath10k_sdio_irq_enable_regs {
  129. u8 int_status_en;
  130. u8 cpu_int_status_en;
  131. u8 err_int_status_en;
  132. u8 cntr_int_status_en;
  133. };
  134. struct ath10k_sdio_irq_data {
  135. /* protects irq_proc_reg and irq_en_reg below.
  136. * We use a mutex here and not a spinlock since we will have the
  137. * mutex locked while calling the sdio_memcpy_ functions.
  138. * These function require non atomic context, and hence, spinlocks
  139. * can be held while calling these functions.
  140. */
  141. struct mutex mtx;
  142. struct ath10k_sdio_irq_proc_regs *irq_proc_reg;
  143. struct ath10k_sdio_irq_enable_regs *irq_en_reg;
  144. };
  145. struct ath10k_mbox_ext_info {
  146. u32 htc_ext_addr;
  147. u32 htc_ext_sz;
  148. };
  149. struct ath10k_mbox_info {
  150. u32 htc_addr;
  151. struct ath10k_mbox_ext_info ext_info[2];
  152. u32 block_size;
  153. u32 block_mask;
  154. u32 gmbox_addr;
  155. u32 gmbox_sz;
  156. };
  157. struct ath10k_sdio {
  158. struct sdio_func *func;
  159. struct ath10k_mbox_info mbox_info;
  160. bool swap_mbox;
  161. u32 mbox_addr[ATH10K_HTC_EP_COUNT];
  162. u32 mbox_size[ATH10K_HTC_EP_COUNT];
  163. /* available bus requests */
  164. struct ath10k_sdio_bus_request bus_req[ATH10K_SDIO_BUS_REQUEST_MAX_NUM];
  165. /* free list of bus requests */
  166. struct list_head bus_req_freeq;
  167. /* protects access to bus_req_freeq */
  168. spinlock_t lock;
  169. struct ath10k_sdio_rx_data rx_pkts[ATH10K_SDIO_MAX_RX_MSGS];
  170. size_t n_rx_pkts;
  171. struct ath10k *ar;
  172. struct ath10k_sdio_irq_data irq_data;
  173. /* temporary buffer for BMI requests */
  174. u8 *bmi_buf;
  175. bool is_disabled;
  176. struct workqueue_struct *workqueue;
  177. struct work_struct wr_async_work;
  178. struct list_head wr_asyncq;
  179. /* protects access to wr_asyncq */
  180. spinlock_t wr_async_lock;
  181. };
  182. static inline struct ath10k_sdio *ath10k_sdio_priv(struct ath10k *ar)
  183. {
  184. return (struct ath10k_sdio *)ar->drv_priv;
  185. }
  186. #endif