htc.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*
  2. * Copyright (c) 2005-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2013 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 _HTC_H_
  18. #define _HTC_H_
  19. #include <linux/kernel.h>
  20. #include <linux/list.h>
  21. #include <linux/bug.h>
  22. #include <linux/skbuff.h>
  23. #include <linux/semaphore.h>
  24. #include <linux/timer.h>
  25. struct ath10k;
  26. /****************/
  27. /* HTC protocol */
  28. /****************/
  29. /*
  30. * HTC - host-target control protocol
  31. *
  32. * tx packets are generally <htc_hdr><payload>
  33. * rx packets are more complex: <htc_hdr><payload><trailer>
  34. *
  35. * The payload + trailer length is stored in len.
  36. * To get payload-only length one needs to payload - trailer_len.
  37. *
  38. * Trailer contains (possibly) multiple <htc_record>.
  39. * Each record is a id-len-value.
  40. *
  41. * HTC header flags, control_byte0, control_byte1
  42. * have different meaning depending whether its tx
  43. * or rx.
  44. *
  45. * Alignment: htc_hdr, payload and trailer are
  46. * 4-byte aligned.
  47. */
  48. enum ath10k_htc_tx_flags {
  49. ATH10K_HTC_FLAG_NEED_CREDIT_UPDATE = 0x01,
  50. ATH10K_HTC_FLAG_SEND_BUNDLE = 0x02
  51. };
  52. enum ath10k_htc_rx_flags {
  53. ATH10K_HTC_FLAG_TRAILER_PRESENT = 0x02,
  54. ATH10K_HTC_FLAG_BUNDLE_MASK = 0xF0
  55. };
  56. struct ath10k_htc_hdr {
  57. u8 eid; /* @enum ath10k_htc_ep_id */
  58. u8 flags; /* @enum ath10k_htc_tx_flags, ath10k_htc_rx_flags */
  59. __le16 len;
  60. union {
  61. u8 trailer_len; /* for rx */
  62. u8 control_byte0;
  63. } __packed;
  64. union {
  65. u8 seq_no; /* for tx */
  66. u8 control_byte1;
  67. } __packed;
  68. u8 pad0;
  69. u8 pad1;
  70. } __packed __aligned(4);
  71. enum ath10k_ath10k_htc_msg_id {
  72. ATH10K_HTC_MSG_READY_ID = 1,
  73. ATH10K_HTC_MSG_CONNECT_SERVICE_ID = 2,
  74. ATH10K_HTC_MSG_CONNECT_SERVICE_RESP_ID = 3,
  75. ATH10K_HTC_MSG_SETUP_COMPLETE_ID = 4,
  76. ATH10K_HTC_MSG_SETUP_COMPLETE_EX_ID = 5,
  77. ATH10K_HTC_MSG_SEND_SUSPEND_COMPLETE = 6
  78. };
  79. enum ath10k_htc_version {
  80. ATH10K_HTC_VERSION_2P0 = 0x00, /* 2.0 */
  81. ATH10K_HTC_VERSION_2P1 = 0x01, /* 2.1 */
  82. };
  83. enum ath10k_htc_conn_flags {
  84. ATH10K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_ONE_FOURTH = 0x0,
  85. ATH10K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_ONE_HALF = 0x1,
  86. ATH10K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_THREE_FOURTHS = 0x2,
  87. ATH10K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_UNITY = 0x3,
  88. #define ATH10K_HTC_CONN_FLAGS_THRESHOLD_LEVEL_MASK 0x3
  89. ATH10K_HTC_CONN_FLAGS_REDUCE_CREDIT_DRIBBLE = 1 << 2,
  90. ATH10K_HTC_CONN_FLAGS_DISABLE_CREDIT_FLOW_CTRL = 1 << 3
  91. #define ATH10K_HTC_CONN_FLAGS_RECV_ALLOC_MASK 0xFF00
  92. #define ATH10K_HTC_CONN_FLAGS_RECV_ALLOC_LSB 8
  93. };
  94. enum ath10k_htc_conn_svc_status {
  95. ATH10K_HTC_CONN_SVC_STATUS_SUCCESS = 0,
  96. ATH10K_HTC_CONN_SVC_STATUS_NOT_FOUND = 1,
  97. ATH10K_HTC_CONN_SVC_STATUS_FAILED = 2,
  98. ATH10K_HTC_CONN_SVC_STATUS_NO_RESOURCES = 3,
  99. ATH10K_HTC_CONN_SVC_STATUS_NO_MORE_EP = 4
  100. };
  101. struct ath10k_ath10k_htc_msg_hdr {
  102. __le16 message_id; /* @enum htc_message_id */
  103. } __packed;
  104. struct ath10k_htc_unknown {
  105. u8 pad0;
  106. u8 pad1;
  107. } __packed;
  108. struct ath10k_htc_ready {
  109. __le16 credit_count;
  110. __le16 credit_size;
  111. u8 max_endpoints;
  112. u8 pad0;
  113. } __packed;
  114. struct ath10k_htc_ready_extended {
  115. struct ath10k_htc_ready base;
  116. u8 htc_version; /* @enum ath10k_htc_version */
  117. u8 max_msgs_per_htc_bundle;
  118. u8 pad0;
  119. u8 pad1;
  120. } __packed;
  121. struct ath10k_htc_conn_svc {
  122. __le16 service_id;
  123. __le16 flags; /* @enum ath10k_htc_conn_flags */
  124. u8 pad0;
  125. u8 pad1;
  126. } __packed;
  127. struct ath10k_htc_conn_svc_response {
  128. __le16 service_id;
  129. u8 status; /* @enum ath10k_htc_conn_svc_status */
  130. u8 eid;
  131. __le16 max_msg_size;
  132. } __packed;
  133. struct ath10k_htc_setup_complete_extended {
  134. u8 pad0;
  135. u8 pad1;
  136. __le32 flags; /* @enum htc_setup_complete_flags */
  137. u8 max_msgs_per_bundled_recv;
  138. u8 pad2;
  139. u8 pad3;
  140. u8 pad4;
  141. } __packed;
  142. struct ath10k_htc_msg {
  143. struct ath10k_ath10k_htc_msg_hdr hdr;
  144. union {
  145. /* host-to-target */
  146. struct ath10k_htc_conn_svc connect_service;
  147. struct ath10k_htc_ready ready;
  148. struct ath10k_htc_ready_extended ready_ext;
  149. struct ath10k_htc_unknown unknown;
  150. struct ath10k_htc_setup_complete_extended setup_complete_ext;
  151. /* target-to-host */
  152. struct ath10k_htc_conn_svc_response connect_service_response;
  153. };
  154. } __packed __aligned(4);
  155. enum ath10k_ath10k_htc_record_id {
  156. ATH10K_HTC_RECORD_NULL = 0,
  157. ATH10K_HTC_RECORD_CREDITS = 1
  158. };
  159. struct ath10k_ath10k_htc_record_hdr {
  160. u8 id; /* @enum ath10k_ath10k_htc_record_id */
  161. u8 len;
  162. u8 pad0;
  163. u8 pad1;
  164. } __packed;
  165. struct ath10k_htc_credit_report {
  166. u8 eid; /* @enum ath10k_htc_ep_id */
  167. u8 credits;
  168. u8 pad0;
  169. u8 pad1;
  170. } __packed;
  171. struct ath10k_htc_record {
  172. struct ath10k_ath10k_htc_record_hdr hdr;
  173. union {
  174. struct ath10k_htc_credit_report credit_report[0];
  175. u8 pauload[0];
  176. };
  177. } __packed __aligned(4);
  178. /*
  179. * note: the trailer offset is dynamic depending
  180. * on payload length. this is only a struct layout draft
  181. */
  182. struct ath10k_htc_frame {
  183. struct ath10k_htc_hdr hdr;
  184. union {
  185. struct ath10k_htc_msg msg;
  186. u8 payload[0];
  187. };
  188. struct ath10k_htc_record trailer[0];
  189. } __packed __aligned(4);
  190. /*******************/
  191. /* Host-side stuff */
  192. /*******************/
  193. enum ath10k_htc_svc_gid {
  194. ATH10K_HTC_SVC_GRP_RSVD = 0,
  195. ATH10K_HTC_SVC_GRP_WMI = 1,
  196. ATH10K_HTC_SVC_GRP_NMI = 2,
  197. ATH10K_HTC_SVC_GRP_HTT = 3,
  198. ATH10K_HTC_SVC_GRP_TEST = 254,
  199. ATH10K_HTC_SVC_GRP_LAST = 255,
  200. };
  201. #define SVC(group, idx) \
  202. (int)(((int)(group) << 8) | (int)(idx))
  203. enum ath10k_htc_svc_id {
  204. /* NOTE: service ID of 0x0000 is reserved and should never be used */
  205. ATH10K_HTC_SVC_ID_RESERVED = 0x0000,
  206. ATH10K_HTC_SVC_ID_UNUSED = ATH10K_HTC_SVC_ID_RESERVED,
  207. ATH10K_HTC_SVC_ID_RSVD_CTRL = SVC(ATH10K_HTC_SVC_GRP_RSVD, 1),
  208. ATH10K_HTC_SVC_ID_WMI_CONTROL = SVC(ATH10K_HTC_SVC_GRP_WMI, 0),
  209. ATH10K_HTC_SVC_ID_WMI_DATA_BE = SVC(ATH10K_HTC_SVC_GRP_WMI, 1),
  210. ATH10K_HTC_SVC_ID_WMI_DATA_BK = SVC(ATH10K_HTC_SVC_GRP_WMI, 2),
  211. ATH10K_HTC_SVC_ID_WMI_DATA_VI = SVC(ATH10K_HTC_SVC_GRP_WMI, 3),
  212. ATH10K_HTC_SVC_ID_WMI_DATA_VO = SVC(ATH10K_HTC_SVC_GRP_WMI, 4),
  213. ATH10K_HTC_SVC_ID_NMI_CONTROL = SVC(ATH10K_HTC_SVC_GRP_NMI, 0),
  214. ATH10K_HTC_SVC_ID_NMI_DATA = SVC(ATH10K_HTC_SVC_GRP_NMI, 1),
  215. ATH10K_HTC_SVC_ID_HTT_DATA_MSG = SVC(ATH10K_HTC_SVC_GRP_HTT, 0),
  216. /* raw stream service (i.e. flash, tcmd, calibration apps) */
  217. ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS = SVC(ATH10K_HTC_SVC_GRP_TEST, 0),
  218. };
  219. #undef SVC
  220. enum ath10k_htc_ep_id {
  221. ATH10K_HTC_EP_UNUSED = -1,
  222. ATH10K_HTC_EP_0 = 0,
  223. ATH10K_HTC_EP_1 = 1,
  224. ATH10K_HTC_EP_2,
  225. ATH10K_HTC_EP_3,
  226. ATH10K_HTC_EP_4,
  227. ATH10K_HTC_EP_5,
  228. ATH10K_HTC_EP_6,
  229. ATH10K_HTC_EP_7,
  230. ATH10K_HTC_EP_8,
  231. ATH10K_HTC_EP_COUNT,
  232. };
  233. struct ath10k_htc_ops {
  234. void (*target_send_suspend_complete)(struct ath10k *ar);
  235. };
  236. struct ath10k_htc_ep_ops {
  237. void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
  238. void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
  239. void (*ep_tx_credits)(struct ath10k *);
  240. };
  241. /* service connection information */
  242. struct ath10k_htc_svc_conn_req {
  243. u16 service_id;
  244. struct ath10k_htc_ep_ops ep_ops;
  245. int max_send_queue_depth;
  246. };
  247. /* service connection response information */
  248. struct ath10k_htc_svc_conn_resp {
  249. u8 buffer_len;
  250. u8 actual_len;
  251. enum ath10k_htc_ep_id eid;
  252. unsigned int max_msg_len;
  253. u8 connect_resp_code;
  254. };
  255. #define ATH10K_NUM_CONTROL_TX_BUFFERS 2
  256. #define ATH10K_HTC_MAX_LEN 4096
  257. #define ATH10K_HTC_MAX_CTRL_MSG_LEN 256
  258. #define ATH10K_HTC_WAIT_TIMEOUT_HZ (1*HZ)
  259. #define ATH10K_HTC_CONTROL_BUFFER_SIZE (ATH10K_HTC_MAX_CTRL_MSG_LEN + \
  260. sizeof(struct ath10k_htc_hdr))
  261. #define ATH10K_HTC_CONN_SVC_TIMEOUT_HZ (1*HZ)
  262. struct ath10k_htc_ep {
  263. struct ath10k_htc *htc;
  264. enum ath10k_htc_ep_id eid;
  265. enum ath10k_htc_svc_id service_id;
  266. struct ath10k_htc_ep_ops ep_ops;
  267. int max_tx_queue_depth;
  268. int max_ep_message_len;
  269. u8 ul_pipe_id;
  270. u8 dl_pipe_id;
  271. u8 seq_no; /* for debugging */
  272. int tx_credits;
  273. int tx_credit_size;
  274. int tx_credits_per_max_message;
  275. bool tx_credit_flow_enabled;
  276. };
  277. struct ath10k_htc_svc_tx_credits {
  278. u16 service_id;
  279. u8 credit_allocation;
  280. };
  281. struct ath10k_htc {
  282. struct ath10k *ar;
  283. struct ath10k_htc_ep endpoint[ATH10K_HTC_EP_COUNT];
  284. /* protects endpoints */
  285. spinlock_t tx_lock;
  286. struct ath10k_htc_ops htc_ops;
  287. u8 control_resp_buffer[ATH10K_HTC_MAX_CTRL_MSG_LEN];
  288. int control_resp_len;
  289. struct completion ctl_resp;
  290. int total_transmit_credits;
  291. struct ath10k_htc_svc_tx_credits service_tx_alloc[ATH10K_HTC_EP_COUNT];
  292. int target_credit_size;
  293. };
  294. int ath10k_htc_init(struct ath10k *ar);
  295. int ath10k_htc_wait_target(struct ath10k_htc *htc);
  296. int ath10k_htc_start(struct ath10k_htc *htc);
  297. int ath10k_htc_connect_service(struct ath10k_htc *htc,
  298. struct ath10k_htc_svc_conn_req *conn_req,
  299. struct ath10k_htc_svc_conn_resp *conn_resp);
  300. int ath10k_htc_send(struct ath10k_htc *htc, enum ath10k_htc_ep_id eid,
  301. struct sk_buff *packet);
  302. struct sk_buff *ath10k_htc_alloc_skb(struct ath10k *ar, int size);
  303. void ath10k_htc_tx_completion_handler(struct ath10k *ar, struct sk_buff *skb);
  304. void ath10k_htc_rx_completion_handler(struct ath10k *ar, struct sk_buff *skb);
  305. #endif