hif.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * Copyright (c) 2004-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef HIF_H
  18. #define HIF_H
  19. #include "common.h"
  20. #include "core.h"
  21. #include <linux/scatterlist.h>
  22. #define BUS_REQUEST_MAX_NUM 64
  23. #define HIF_MBOX_BLOCK_SIZE 128
  24. #define HIF_MBOX0_BLOCK_SIZE 1
  25. #define HIF_DMA_BUFFER_SIZE (32 * 1024)
  26. #define CMD53_FIXED_ADDRESS 1
  27. #define CMD53_INCR_ADDRESS 2
  28. #define MAX_SCATTER_REQUESTS 4
  29. #define MAX_SCATTER_ENTRIES_PER_REQ 16
  30. #define MAX_SCATTER_REQ_TRANSFER_SIZE (32 * 1024)
  31. /* Mailbox address in SDIO address space */
  32. #define HIF_MBOX_BASE_ADDR 0x800
  33. #define HIF_MBOX_WIDTH 0x800
  34. #define HIF_MBOX_END_ADDR (HTC_MAILBOX_NUM_MAX * HIF_MBOX_WIDTH - 1)
  35. /* version 1 of the chip has only a 12K extended mbox range */
  36. #define HIF_MBOX0_EXT_BASE_ADDR 0x4000
  37. #define HIF_MBOX0_EXT_WIDTH (12*1024)
  38. /* GMBOX addresses */
  39. #define HIF_GMBOX_BASE_ADDR 0x7000
  40. #define HIF_GMBOX_WIDTH 0x4000
  41. /* interrupt mode register */
  42. #define CCCR_SDIO_IRQ_MODE_REG 0xF0
  43. /* mode to enable special 4-bit interrupt assertion without clock */
  44. #define SDIO_IRQ_MODE_ASYNC_4BIT_IRQ (1 << 0)
  45. /* HTC runs over mailbox 0 */
  46. #define HTC_MAILBOX 0
  47. #define ATH6KL_TARGET_DEBUG_INTR_MASK 0x01
  48. /* FIXME: are these duplicates with MAX_SCATTER_ values in hif.h? */
  49. #define ATH6KL_SCATTER_ENTRIES_PER_REQ 16
  50. #define ATH6KL_MAX_TRANSFER_SIZE_PER_SCATTER (16 * 1024)
  51. #define ATH6KL_SCATTER_REQS 4
  52. #define ATH6KL_HIF_COMMUNICATION_TIMEOUT 1000
  53. struct bus_request {
  54. struct list_head list;
  55. /* request data */
  56. u32 address;
  57. u8 *buffer;
  58. u32 length;
  59. u32 request;
  60. struct htc_packet *packet;
  61. int status;
  62. /* this is a scatter request */
  63. struct hif_scatter_req *scat_req;
  64. };
  65. /* direction of transfer (read/write) */
  66. #define HIF_READ 0x00000001
  67. #define HIF_WRITE 0x00000002
  68. #define HIF_DIR_MASK (HIF_READ | HIF_WRITE)
  69. /*
  70. * emode - This indicates the whether the command is to be executed in a
  71. * blocking or non-blocking fashion (HIF_SYNCHRONOUS/
  72. * HIF_ASYNCHRONOUS). The read/write data paths in HTC have been
  73. * implemented using the asynchronous mode allowing the bus
  74. * driver to indicate the completion of operation through the
  75. * registered callback routine. The requirement primarily comes
  76. * from the contexts these operations get called from (a driver's
  77. * transmit context or the ISR context in case of receive).
  78. * Support for both of these modes is essential.
  79. */
  80. #define HIF_SYNCHRONOUS 0x00000010
  81. #define HIF_ASYNCHRONOUS 0x00000020
  82. #define HIF_EMODE_MASK (HIF_SYNCHRONOUS | HIF_ASYNCHRONOUS)
  83. /*
  84. * dmode - An interface may support different kinds of commands based on
  85. * the tradeoff between the amount of data it can carry and the
  86. * setup time. Byte and Block modes are supported (HIF_BYTE_BASIS/
  87. * HIF_BLOCK_BASIS). In case of latter, the data is rounded off
  88. * to the nearest block size by padding. The size of the block is
  89. * configurable at compile time using the HIF_BLOCK_SIZE and is
  90. * negotiated with the target during initialization after the
  91. * ATH6KL interrupts are enabled.
  92. */
  93. #define HIF_BYTE_BASIS 0x00000040
  94. #define HIF_BLOCK_BASIS 0x00000080
  95. #define HIF_DMODE_MASK (HIF_BYTE_BASIS | HIF_BLOCK_BASIS)
  96. /*
  97. * amode - This indicates if the address has to be incremented on ATH6KL
  98. * after every read/write operation (HIF?FIXED_ADDRESS/
  99. * HIF_INCREMENTAL_ADDRESS).
  100. */
  101. #define HIF_FIXED_ADDRESS 0x00000100
  102. #define HIF_INCREMENTAL_ADDRESS 0x00000200
  103. #define HIF_AMODE_MASK (HIF_FIXED_ADDRESS | HIF_INCREMENTAL_ADDRESS)
  104. #define HIF_WR_ASYNC_BYTE_INC \
  105. (HIF_WRITE | HIF_ASYNCHRONOUS | \
  106. HIF_BYTE_BASIS | HIF_INCREMENTAL_ADDRESS)
  107. #define HIF_WR_ASYNC_BLOCK_INC \
  108. (HIF_WRITE | HIF_ASYNCHRONOUS | \
  109. HIF_BLOCK_BASIS | HIF_INCREMENTAL_ADDRESS)
  110. #define HIF_WR_SYNC_BYTE_FIX \
  111. (HIF_WRITE | HIF_SYNCHRONOUS | \
  112. HIF_BYTE_BASIS | HIF_FIXED_ADDRESS)
  113. #define HIF_WR_SYNC_BYTE_INC \
  114. (HIF_WRITE | HIF_SYNCHRONOUS | \
  115. HIF_BYTE_BASIS | HIF_INCREMENTAL_ADDRESS)
  116. #define HIF_WR_SYNC_BLOCK_INC \
  117. (HIF_WRITE | HIF_SYNCHRONOUS | \
  118. HIF_BLOCK_BASIS | HIF_INCREMENTAL_ADDRESS)
  119. #define HIF_RD_SYNC_BYTE_INC \
  120. (HIF_READ | HIF_SYNCHRONOUS | \
  121. HIF_BYTE_BASIS | HIF_INCREMENTAL_ADDRESS)
  122. #define HIF_RD_SYNC_BYTE_FIX \
  123. (HIF_READ | HIF_SYNCHRONOUS | \
  124. HIF_BYTE_BASIS | HIF_FIXED_ADDRESS)
  125. #define HIF_RD_ASYNC_BLOCK_FIX \
  126. (HIF_READ | HIF_ASYNCHRONOUS | \
  127. HIF_BLOCK_BASIS | HIF_FIXED_ADDRESS)
  128. #define HIF_RD_SYNC_BLOCK_FIX \
  129. (HIF_READ | HIF_SYNCHRONOUS | \
  130. HIF_BLOCK_BASIS | HIF_FIXED_ADDRESS)
  131. struct hif_scatter_item {
  132. u8 *buf;
  133. int len;
  134. struct htc_packet *packet;
  135. };
  136. struct hif_scatter_req {
  137. struct list_head list;
  138. /* address for the read/write operation */
  139. u32 addr;
  140. /* request flags */
  141. u32 req;
  142. /* total length of entire transfer */
  143. u32 len;
  144. bool virt_scat;
  145. void (*complete) (struct htc_target *, struct hif_scatter_req *);
  146. int status;
  147. int scat_entries;
  148. struct bus_request *busrequest;
  149. struct scatterlist *sgentries;
  150. /* bounce buffer for upper layers to copy to/from */
  151. u8 *virt_dma_buf;
  152. u32 scat_q_depth;
  153. struct hif_scatter_item scat_list[];
  154. };
  155. struct ath6kl_irq_proc_registers {
  156. u8 host_int_status;
  157. u8 cpu_int_status;
  158. u8 error_int_status;
  159. u8 counter_int_status;
  160. u8 mbox_frame;
  161. u8 rx_lkahd_valid;
  162. u8 host_int_status2;
  163. u8 gmbox_rx_avail;
  164. __le32 rx_lkahd[2];
  165. __le32 rx_gmbox_lkahd_alias[2];
  166. } __packed;
  167. struct ath6kl_irq_enable_reg {
  168. u8 int_status_en;
  169. u8 cpu_int_status_en;
  170. u8 err_int_status_en;
  171. u8 cntr_int_status_en;
  172. } __packed;
  173. struct ath6kl_device {
  174. /* protects irq_proc_reg and irq_en_reg below */
  175. spinlock_t lock;
  176. struct ath6kl_irq_proc_registers irq_proc_reg;
  177. struct ath6kl_irq_enable_reg irq_en_reg;
  178. struct htc_target *htc_cnxt;
  179. struct ath6kl *ar;
  180. };
  181. struct ath6kl_hif_ops {
  182. int (*read_write_sync)(struct ath6kl *ar, u32 addr, u8 *buf,
  183. u32 len, u32 request);
  184. int (*write_async)(struct ath6kl *ar, u32 address, u8 *buffer,
  185. u32 length, u32 request, struct htc_packet *packet);
  186. void (*irq_enable)(struct ath6kl *ar);
  187. void (*irq_disable)(struct ath6kl *ar);
  188. struct hif_scatter_req *(*scatter_req_get)(struct ath6kl *ar);
  189. void (*scatter_req_add)(struct ath6kl *ar,
  190. struct hif_scatter_req *s_req);
  191. int (*enable_scatter)(struct ath6kl *ar);
  192. int (*scat_req_rw) (struct ath6kl *ar,
  193. struct hif_scatter_req *scat_req);
  194. void (*cleanup_scatter)(struct ath6kl *ar);
  195. int (*suspend)(struct ath6kl *ar, struct cfg80211_wowlan *wow);
  196. int (*resume)(struct ath6kl *ar);
  197. int (*diag_read32)(struct ath6kl *ar, u32 address, u32 *value);
  198. int (*diag_write32)(struct ath6kl *ar, u32 address, __le32 value);
  199. int (*bmi_read)(struct ath6kl *ar, u8 *buf, u32 len);
  200. int (*bmi_write)(struct ath6kl *ar, u8 *buf, u32 len);
  201. int (*power_on)(struct ath6kl *ar);
  202. int (*power_off)(struct ath6kl *ar);
  203. void (*stop)(struct ath6kl *ar);
  204. int (*pipe_send)(struct ath6kl *ar, u8 pipe, struct sk_buff *hdr_buf,
  205. struct sk_buff *buf);
  206. void (*pipe_get_default)(struct ath6kl *ar, u8 *pipe_ul, u8 *pipe_dl);
  207. int (*pipe_map_service)(struct ath6kl *ar, u16 service_id, u8 *pipe_ul,
  208. u8 *pipe_dl);
  209. u16 (*pipe_get_free_queue_number)(struct ath6kl *ar, u8 pipe);
  210. };
  211. int ath6kl_hif_setup(struct ath6kl_device *dev);
  212. int ath6kl_hif_unmask_intrs(struct ath6kl_device *dev);
  213. int ath6kl_hif_mask_intrs(struct ath6kl_device *dev);
  214. int ath6kl_hif_poll_mboxmsg_rx(struct ath6kl_device *dev,
  215. u32 *lk_ahd, int timeout);
  216. int ath6kl_hif_rx_control(struct ath6kl_device *dev, bool enable_rx);
  217. int ath6kl_hif_disable_intrs(struct ath6kl_device *dev);
  218. int ath6kl_hif_rw_comp_handler(void *context, int status);
  219. int ath6kl_hif_intr_bh_handler(struct ath6kl *ar);
  220. /* Scatter Function and Definitions */
  221. int ath6kl_hif_submit_scat_req(struct ath6kl_device *dev,
  222. struct hif_scatter_req *scat_req, bool read);
  223. #endif