htc_hst.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Copyright (c) 2010 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 HTC_HST_H
  17. #define HTC_HST_H
  18. struct ath9k_htc_priv;
  19. struct htc_target;
  20. struct ath9k_htc_tx_ctl;
  21. enum ath9k_hif_transports {
  22. ATH9K_HIF_USB,
  23. };
  24. struct ath9k_htc_hif {
  25. struct list_head list;
  26. const enum ath9k_hif_transports transport;
  27. const char *name;
  28. u8 control_dl_pipe;
  29. u8 control_ul_pipe;
  30. void (*start) (void *hif_handle, u8 pipe);
  31. void (*stop) (void *hif_handle, u8 pipe);
  32. int (*send) (void *hif_handle, u8 pipe, struct sk_buff *buf,
  33. struct ath9k_htc_tx_ctl *tx_ctl);
  34. };
  35. enum htc_endpoint_id {
  36. ENDPOINT_UNUSED = -1,
  37. ENDPOINT0 = 0,
  38. ENDPOINT1 = 1,
  39. ENDPOINT2 = 2,
  40. ENDPOINT3 = 3,
  41. ENDPOINT4 = 4,
  42. ENDPOINT5 = 5,
  43. ENDPOINT6 = 6,
  44. ENDPOINT7 = 7,
  45. ENDPOINT8 = 8,
  46. ENDPOINT_MAX = 22
  47. };
  48. /* Htc frame hdr flags */
  49. #define HTC_FLAGS_RECV_TRAILER (1 << 1)
  50. struct htc_frame_hdr {
  51. u8 endpoint_id;
  52. u8 flags;
  53. __be16 payload_len;
  54. u8 control[4];
  55. } __packed;
  56. struct htc_ready_msg {
  57. __be16 message_id;
  58. __be16 credits;
  59. __be16 credit_size;
  60. u8 max_endpoints;
  61. u8 pad;
  62. } __packed;
  63. struct htc_config_pipe_msg {
  64. __be16 message_id;
  65. u8 pipe_id;
  66. u8 credits;
  67. } __packed;
  68. struct htc_ep_callbacks {
  69. void *priv;
  70. void (*tx) (void *, struct sk_buff *, enum htc_endpoint_id, bool txok);
  71. void (*rx) (void *, struct sk_buff *, enum htc_endpoint_id);
  72. };
  73. #define HTC_TX_QUEUE_SIZE 256
  74. struct htc_txq {
  75. struct sk_buff *buf[HTC_TX_QUEUE_SIZE];
  76. u32 txqdepth;
  77. u16 txbuf_cnt;
  78. u16 txq_head;
  79. u16 txq_tail;
  80. };
  81. struct htc_endpoint {
  82. u16 service_id;
  83. struct htc_ep_callbacks ep_callbacks;
  84. struct htc_txq htc_txq;
  85. u32 max_txqdepth;
  86. int max_msglen;
  87. u8 ul_pipeid;
  88. u8 dl_pipeid;
  89. };
  90. #define HTC_MAX_CONTROL_MESSAGE_LENGTH 255
  91. #define HTC_CONTROL_BUFFER_SIZE \
  92. (HTC_MAX_CONTROL_MESSAGE_LENGTH + sizeof(struct htc_frame_hdr))
  93. #define HTC_OP_START_WAIT BIT(0)
  94. #define HTC_OP_CONFIG_PIPE_CREDITS BIT(1)
  95. struct htc_target {
  96. void *hif_dev;
  97. struct ath9k_htc_priv *drv_priv;
  98. struct device *dev;
  99. struct ath9k_htc_hif *hif;
  100. struct htc_endpoint endpoint[ENDPOINT_MAX];
  101. struct completion target_wait;
  102. struct completion cmd_wait;
  103. struct list_head list;
  104. enum htc_endpoint_id conn_rsp_epid;
  105. u16 credits;
  106. u16 credit_size;
  107. u8 htc_flags;
  108. atomic_t tgt_ready;
  109. };
  110. enum htc_msg_id {
  111. HTC_MSG_READY_ID = 1,
  112. HTC_MSG_CONNECT_SERVICE_ID,
  113. HTC_MSG_CONNECT_SERVICE_RESPONSE_ID,
  114. HTC_MSG_SETUP_COMPLETE_ID,
  115. HTC_MSG_CONFIG_PIPE_ID,
  116. HTC_MSG_CONFIG_PIPE_RESPONSE_ID,
  117. };
  118. struct htc_service_connreq {
  119. u16 service_id;
  120. u16 con_flags;
  121. u32 max_send_qdepth;
  122. struct htc_ep_callbacks ep_callbacks;
  123. };
  124. /* Current service IDs */
  125. enum htc_service_group_ids{
  126. RSVD_SERVICE_GROUP = 0,
  127. WMI_SERVICE_GROUP = 1,
  128. HTC_SERVICE_GROUP_LAST = 255
  129. };
  130. #define MAKE_SERVICE_ID(group, index) \
  131. (int)(((int)group << 8) | (int)(index))
  132. /* NOTE: service ID of 0x0000 is reserved and should never be used */
  133. #define HTC_CTRL_RSVD_SVC MAKE_SERVICE_ID(RSVD_SERVICE_GROUP, 1)
  134. #define HTC_LOOPBACK_RSVD_SVC MAKE_SERVICE_ID(RSVD_SERVICE_GROUP, 2)
  135. #define WMI_CONTROL_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 0)
  136. #define WMI_BEACON_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 1)
  137. #define WMI_CAB_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 2)
  138. #define WMI_UAPSD_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 3)
  139. #define WMI_MGMT_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 4)
  140. #define WMI_DATA_VO_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 5)
  141. #define WMI_DATA_VI_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 6)
  142. #define WMI_DATA_BE_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 7)
  143. #define WMI_DATA_BK_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 8)
  144. struct htc_conn_svc_msg {
  145. __be16 msg_id;
  146. __be16 service_id;
  147. __be16 con_flags;
  148. u8 dl_pipeid;
  149. u8 ul_pipeid;
  150. u8 svc_meta_len;
  151. u8 pad;
  152. } __packed;
  153. /* connect response status codes */
  154. #define HTC_SERVICE_SUCCESS 0
  155. #define HTC_SERVICE_NOT_FOUND 1
  156. #define HTC_SERVICE_FAILED 2
  157. #define HTC_SERVICE_NO_RESOURCES 3
  158. #define HTC_SERVICE_NO_MORE_EP 4
  159. struct htc_conn_svc_rspmsg {
  160. __be16 msg_id;
  161. __be16 service_id;
  162. u8 status;
  163. u8 endpoint_id;
  164. __be16 max_msg_len;
  165. u8 svc_meta_len;
  166. u8 pad;
  167. } __packed;
  168. struct htc_comp_msg {
  169. __be16 msg_id;
  170. } __packed;
  171. int htc_init(struct htc_target *target);
  172. int htc_connect_service(struct htc_target *target,
  173. struct htc_service_connreq *service_connreq,
  174. enum htc_endpoint_id *conn_rsp_eid);
  175. int htc_send(struct htc_target *target, struct sk_buff *skb,
  176. enum htc_endpoint_id eid, struct ath9k_htc_tx_ctl *tx_ctl);
  177. void htc_stop(struct htc_target *target);
  178. void htc_start(struct htc_target *target);
  179. void ath9k_htc_rx_msg(struct htc_target *htc_handle,
  180. struct sk_buff *skb, u32 len, u8 pipe_id);
  181. void ath9k_htc_txcompletion_cb(struct htc_target *htc_handle,
  182. struct sk_buff *skb, bool txok);
  183. struct htc_target *ath9k_htc_hw_alloc(void *hif_handle,
  184. struct ath9k_htc_hif *hif,
  185. struct device *dev);
  186. void ath9k_htc_hw_free(struct htc_target *htc);
  187. int ath9k_htc_hw_init(struct htc_target *target,
  188. struct device *dev, u16 devid, char *product,
  189. u32 drv_info);
  190. void ath9k_htc_hw_deinit(struct htc_target *target, bool hot_unplug);
  191. #endif /* HTC_HST_H */