hif.h 8.2 KB

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