htc_hst.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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_packet {
  69. void *pktcontext;
  70. u8 *buf;
  71. u8 *buf_payload;
  72. u32 buflen;
  73. u32 payload_len;
  74. int endpoint;
  75. int status;
  76. void *context;
  77. u32 reserved;
  78. };
  79. struct htc_ep_callbacks {
  80. void *priv;
  81. void (*tx) (void *, struct sk_buff *, enum htc_endpoint_id, bool txok);
  82. void (*rx) (void *, struct sk_buff *, enum htc_endpoint_id);
  83. };
  84. #define HTC_TX_QUEUE_SIZE 256
  85. struct htc_txq {
  86. struct sk_buff *buf[HTC_TX_QUEUE_SIZE];
  87. u32 txqdepth;
  88. u16 txbuf_cnt;
  89. u16 txq_head;
  90. u16 txq_tail;
  91. };
  92. struct htc_endpoint {
  93. u16 service_id;
  94. struct htc_ep_callbacks ep_callbacks;
  95. struct htc_txq htc_txq;
  96. u32 max_txqdepth;
  97. int max_msglen;
  98. u8 ul_pipeid;
  99. u8 dl_pipeid;
  100. };
  101. #define HTC_MAX_CONTROL_MESSAGE_LENGTH 255
  102. #define HTC_CONTROL_BUFFER_SIZE \
  103. (HTC_MAX_CONTROL_MESSAGE_LENGTH + sizeof(struct htc_frame_hdr))
  104. struct htc_control_buf {
  105. struct htc_packet htc_pkt;
  106. u8 buf[HTC_CONTROL_BUFFER_SIZE];
  107. };
  108. #define HTC_OP_START_WAIT BIT(0)
  109. #define HTC_OP_CONFIG_PIPE_CREDITS BIT(1)
  110. struct htc_target {
  111. void *hif_dev;
  112. struct ath9k_htc_priv *drv_priv;
  113. struct device *dev;
  114. struct ath9k_htc_hif *hif;
  115. struct htc_endpoint endpoint[ENDPOINT_MAX];
  116. struct completion target_wait;
  117. struct completion cmd_wait;
  118. struct list_head list;
  119. enum htc_endpoint_id conn_rsp_epid;
  120. u16 credits;
  121. u16 credit_size;
  122. u8 htc_flags;
  123. atomic_t tgt_ready;
  124. };
  125. enum htc_msg_id {
  126. HTC_MSG_READY_ID = 1,
  127. HTC_MSG_CONNECT_SERVICE_ID,
  128. HTC_MSG_CONNECT_SERVICE_RESPONSE_ID,
  129. HTC_MSG_SETUP_COMPLETE_ID,
  130. HTC_MSG_CONFIG_PIPE_ID,
  131. HTC_MSG_CONFIG_PIPE_RESPONSE_ID,
  132. };
  133. struct htc_service_connreq {
  134. u16 service_id;
  135. u16 con_flags;
  136. u32 max_send_qdepth;
  137. struct htc_ep_callbacks ep_callbacks;
  138. };
  139. /* Current service IDs */
  140. enum htc_service_group_ids{
  141. RSVD_SERVICE_GROUP = 0,
  142. WMI_SERVICE_GROUP = 1,
  143. HTC_SERVICE_GROUP_LAST = 255
  144. };
  145. #define MAKE_SERVICE_ID(group, index) \
  146. (int)(((int)group << 8) | (int)(index))
  147. /* NOTE: service ID of 0x0000 is reserved and should never be used */
  148. #define HTC_CTRL_RSVD_SVC MAKE_SERVICE_ID(RSVD_SERVICE_GROUP, 1)
  149. #define HTC_LOOPBACK_RSVD_SVC MAKE_SERVICE_ID(RSVD_SERVICE_GROUP, 2)
  150. #define WMI_CONTROL_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 0)
  151. #define WMI_BEACON_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 1)
  152. #define WMI_CAB_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 2)
  153. #define WMI_UAPSD_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 3)
  154. #define WMI_MGMT_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 4)
  155. #define WMI_DATA_VO_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 5)
  156. #define WMI_DATA_VI_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 6)
  157. #define WMI_DATA_BE_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 7)
  158. #define WMI_DATA_BK_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 8)
  159. struct htc_conn_svc_msg {
  160. __be16 msg_id;
  161. __be16 service_id;
  162. __be16 con_flags;
  163. u8 dl_pipeid;
  164. u8 ul_pipeid;
  165. u8 svc_meta_len;
  166. u8 pad;
  167. } __packed;
  168. /* connect response status codes */
  169. #define HTC_SERVICE_SUCCESS 0
  170. #define HTC_SERVICE_NOT_FOUND 1
  171. #define HTC_SERVICE_FAILED 2
  172. #define HTC_SERVICE_NO_RESOURCES 3
  173. #define HTC_SERVICE_NO_MORE_EP 4
  174. struct htc_conn_svc_rspmsg {
  175. __be16 msg_id;
  176. __be16 service_id;
  177. u8 status;
  178. u8 endpoint_id;
  179. __be16 max_msg_len;
  180. u8 svc_meta_len;
  181. u8 pad;
  182. } __packed;
  183. struct htc_comp_msg {
  184. __be16 msg_id;
  185. } __packed;
  186. int htc_init(struct htc_target *target);
  187. int htc_connect_service(struct htc_target *target,
  188. struct htc_service_connreq *service_connreq,
  189. enum htc_endpoint_id *conn_rsp_eid);
  190. int htc_send(struct htc_target *target, struct sk_buff *skb,
  191. enum htc_endpoint_id eid, struct ath9k_htc_tx_ctl *tx_ctl);
  192. void htc_stop(struct htc_target *target);
  193. void htc_start(struct htc_target *target);
  194. void ath9k_htc_rx_msg(struct htc_target *htc_handle,
  195. struct sk_buff *skb, u32 len, u8 pipe_id);
  196. void ath9k_htc_txcompletion_cb(struct htc_target *htc_handle,
  197. struct sk_buff *skb, bool txok);
  198. struct htc_target *ath9k_htc_hw_alloc(void *hif_handle,
  199. struct ath9k_htc_hif *hif,
  200. struct device *dev);
  201. void ath9k_htc_hw_free(struct htc_target *htc);
  202. int ath9k_htc_hw_init(struct htc_target *target,
  203. struct device *dev, u16 devid, char *product);
  204. void ath9k_htc_hw_deinit(struct htc_target *target, bool hot_unplug);
  205. #endif /* HTC_HST_H */