htc.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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/timer.h>
  24. struct ath10k;
  25. /****************/
  26. /* HTC protocol */
  27. /****************/
  28. /*
  29. * HTC - host-target control protocol
  30. *
  31. * tx packets are generally <htc_hdr><payload>
  32. * rx packets are more complex: <htc_hdr><payload><trailer>
  33. *
  34. * The payload + trailer length is stored in len.
  35. * To get payload-only length one needs to payload - trailer_len.
  36. *
  37. * Trailer contains (possibly) multiple <htc_record>.
  38. * Each record is a id-len-value.
  39. *
  40. * HTC header flags, control_byte0, control_byte1
  41. * have different meaning depending whether its tx
  42. * or rx.
  43. *
  44. * Alignment: htc_hdr, payload and trailer are
  45. * 4-byte aligned.
  46. */
  47. #define HTC_HOST_MAX_MSG_PER_BUNDLE 8
  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. enum ath10k_htc_setup_complete_flags {
  102. ATH10K_HTC_SETUP_COMPLETE_FLAGS_RX_BNDL_EN = 1
  103. };
  104. struct ath10k_ath10k_htc_msg_hdr {
  105. __le16 message_id; /* @enum htc_message_id */
  106. } __packed;
  107. struct ath10k_htc_unknown {
  108. u8 pad0;
  109. u8 pad1;
  110. } __packed;
  111. struct ath10k_htc_ready {
  112. __le16 credit_count;
  113. __le16 credit_size;
  114. u8 max_endpoints;
  115. u8 pad0;
  116. } __packed;
  117. struct ath10k_htc_ready_extended {
  118. struct ath10k_htc_ready base;
  119. u8 htc_version; /* @enum ath10k_htc_version */
  120. u8 max_msgs_per_htc_bundle;
  121. u8 pad0;
  122. u8 pad1;
  123. } __packed;
  124. struct ath10k_htc_conn_svc {
  125. __le16 service_id;
  126. __le16 flags; /* @enum ath10k_htc_conn_flags */
  127. u8 pad0;
  128. u8 pad1;
  129. } __packed;
  130. struct ath10k_htc_conn_svc_response {
  131. __le16 service_id;
  132. u8 status; /* @enum ath10k_htc_conn_svc_status */
  133. u8 eid;
  134. __le16 max_msg_size;
  135. } __packed;
  136. struct ath10k_htc_setup_complete_extended {
  137. u8 pad0;
  138. u8 pad1;
  139. __le32 flags; /* @enum htc_setup_complete_flags */
  140. u8 max_msgs_per_bundled_recv;
  141. u8 pad2;
  142. u8 pad3;
  143. u8 pad4;
  144. } __packed;
  145. struct ath10k_htc_msg {
  146. struct ath10k_ath10k_htc_msg_hdr hdr;
  147. union {
  148. /* host-to-target */
  149. struct ath10k_htc_conn_svc connect_service;
  150. struct ath10k_htc_ready ready;
  151. struct ath10k_htc_ready_extended ready_ext;
  152. struct ath10k_htc_unknown unknown;
  153. struct ath10k_htc_setup_complete_extended setup_complete_ext;
  154. /* target-to-host */
  155. struct ath10k_htc_conn_svc_response connect_service_response;
  156. };
  157. } __packed __aligned(4);
  158. enum ath10k_ath10k_htc_record_id {
  159. ATH10K_HTC_RECORD_NULL = 0,
  160. ATH10K_HTC_RECORD_CREDITS = 1,
  161. ATH10K_HTC_RECORD_LOOKAHEAD = 2,
  162. ATH10K_HTC_RECORD_LOOKAHEAD_BUNDLE = 3,
  163. };
  164. struct ath10k_ath10k_htc_record_hdr {
  165. u8 id; /* @enum ath10k_ath10k_htc_record_id */
  166. u8 len;
  167. u8 pad0;
  168. u8 pad1;
  169. } __packed;
  170. struct ath10k_htc_credit_report {
  171. u8 eid; /* @enum ath10k_htc_ep_id */
  172. u8 credits;
  173. u8 pad0;
  174. u8 pad1;
  175. } __packed;
  176. struct ath10k_htc_lookahead_report {
  177. u8 pre_valid;
  178. u8 pad0;
  179. u8 pad1;
  180. u8 pad2;
  181. u8 lookahead[4];
  182. u8 post_valid;
  183. u8 pad3;
  184. u8 pad4;
  185. u8 pad5;
  186. } __packed;
  187. struct ath10k_htc_lookahead_bundle {
  188. u8 lookahead[4];
  189. } __packed;
  190. struct ath10k_htc_record {
  191. struct ath10k_ath10k_htc_record_hdr hdr;
  192. union {
  193. struct ath10k_htc_credit_report credit_report[0];
  194. struct ath10k_htc_lookahead_report lookahead_report[0];
  195. struct ath10k_htc_lookahead_bundle lookahead_bundle[0];
  196. u8 pauload[0];
  197. };
  198. } __packed __aligned(4);
  199. /*
  200. * note: the trailer offset is dynamic depending
  201. * on payload length. this is only a struct layout draft
  202. */
  203. struct ath10k_htc_frame {
  204. struct ath10k_htc_hdr hdr;
  205. union {
  206. struct ath10k_htc_msg msg;
  207. u8 payload[0];
  208. };
  209. struct ath10k_htc_record trailer[0];
  210. } __packed __aligned(4);
  211. /*******************/
  212. /* Host-side stuff */
  213. /*******************/
  214. enum ath10k_htc_svc_gid {
  215. ATH10K_HTC_SVC_GRP_RSVD = 0,
  216. ATH10K_HTC_SVC_GRP_WMI = 1,
  217. ATH10K_HTC_SVC_GRP_NMI = 2,
  218. ATH10K_HTC_SVC_GRP_HTT = 3,
  219. ATH10K_HTC_SVC_GRP_TEST = 254,
  220. ATH10K_HTC_SVC_GRP_LAST = 255,
  221. };
  222. #define SVC(group, idx) \
  223. (int)(((int)(group) << 8) | (int)(idx))
  224. enum ath10k_htc_svc_id {
  225. /* NOTE: service ID of 0x0000 is reserved and should never be used */
  226. ATH10K_HTC_SVC_ID_RESERVED = 0x0000,
  227. ATH10K_HTC_SVC_ID_UNUSED = ATH10K_HTC_SVC_ID_RESERVED,
  228. ATH10K_HTC_SVC_ID_RSVD_CTRL = SVC(ATH10K_HTC_SVC_GRP_RSVD, 1),
  229. ATH10K_HTC_SVC_ID_WMI_CONTROL = SVC(ATH10K_HTC_SVC_GRP_WMI, 0),
  230. ATH10K_HTC_SVC_ID_WMI_DATA_BE = SVC(ATH10K_HTC_SVC_GRP_WMI, 1),
  231. ATH10K_HTC_SVC_ID_WMI_DATA_BK = SVC(ATH10K_HTC_SVC_GRP_WMI, 2),
  232. ATH10K_HTC_SVC_ID_WMI_DATA_VI = SVC(ATH10K_HTC_SVC_GRP_WMI, 3),
  233. ATH10K_HTC_SVC_ID_WMI_DATA_VO = SVC(ATH10K_HTC_SVC_GRP_WMI, 4),
  234. ATH10K_HTC_SVC_ID_NMI_CONTROL = SVC(ATH10K_HTC_SVC_GRP_NMI, 0),
  235. ATH10K_HTC_SVC_ID_NMI_DATA = SVC(ATH10K_HTC_SVC_GRP_NMI, 1),
  236. ATH10K_HTC_SVC_ID_HTT_DATA_MSG = SVC(ATH10K_HTC_SVC_GRP_HTT, 0),
  237. /* raw stream service (i.e. flash, tcmd, calibration apps) */
  238. ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS = SVC(ATH10K_HTC_SVC_GRP_TEST, 0),
  239. };
  240. #undef SVC
  241. enum ath10k_htc_ep_id {
  242. ATH10K_HTC_EP_UNUSED = -1,
  243. ATH10K_HTC_EP_0 = 0,
  244. ATH10K_HTC_EP_1 = 1,
  245. ATH10K_HTC_EP_2,
  246. ATH10K_HTC_EP_3,
  247. ATH10K_HTC_EP_4,
  248. ATH10K_HTC_EP_5,
  249. ATH10K_HTC_EP_6,
  250. ATH10K_HTC_EP_7,
  251. ATH10K_HTC_EP_8,
  252. ATH10K_HTC_EP_COUNT,
  253. };
  254. struct ath10k_htc_ops {
  255. void (*target_send_suspend_complete)(struct ath10k *ar);
  256. };
  257. struct ath10k_htc_ep_ops {
  258. void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
  259. void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
  260. void (*ep_tx_credits)(struct ath10k *);
  261. };
  262. /* service connection information */
  263. struct ath10k_htc_svc_conn_req {
  264. u16 service_id;
  265. struct ath10k_htc_ep_ops ep_ops;
  266. int max_send_queue_depth;
  267. };
  268. /* service connection response information */
  269. struct ath10k_htc_svc_conn_resp {
  270. u8 buffer_len;
  271. u8 actual_len;
  272. enum ath10k_htc_ep_id eid;
  273. unsigned int max_msg_len;
  274. u8 connect_resp_code;
  275. };
  276. #define ATH10K_NUM_CONTROL_TX_BUFFERS 2
  277. #define ATH10K_HTC_MAX_LEN 4096
  278. #define ATH10K_HTC_MAX_CTRL_MSG_LEN 256
  279. #define ATH10K_HTC_WAIT_TIMEOUT_HZ (1 * HZ)
  280. #define ATH10K_HTC_CONTROL_BUFFER_SIZE (ATH10K_HTC_MAX_CTRL_MSG_LEN + \
  281. sizeof(struct ath10k_htc_hdr))
  282. #define ATH10K_HTC_CONN_SVC_TIMEOUT_HZ (1 * HZ)
  283. struct ath10k_htc_ep {
  284. struct ath10k_htc *htc;
  285. enum ath10k_htc_ep_id eid;
  286. enum ath10k_htc_svc_id service_id;
  287. struct ath10k_htc_ep_ops ep_ops;
  288. int max_tx_queue_depth;
  289. int max_ep_message_len;
  290. u8 ul_pipe_id;
  291. u8 dl_pipe_id;
  292. u8 seq_no; /* for debugging */
  293. int tx_credits;
  294. bool tx_credit_flow_enabled;
  295. };
  296. struct ath10k_htc_svc_tx_credits {
  297. u16 service_id;
  298. u8 credit_allocation;
  299. };
  300. struct ath10k_htc {
  301. struct ath10k *ar;
  302. struct ath10k_htc_ep endpoint[ATH10K_HTC_EP_COUNT];
  303. /* protects endpoints */
  304. spinlock_t tx_lock;
  305. struct ath10k_htc_ops htc_ops;
  306. u8 control_resp_buffer[ATH10K_HTC_MAX_CTRL_MSG_LEN];
  307. int control_resp_len;
  308. struct completion ctl_resp;
  309. int total_transmit_credits;
  310. int target_credit_size;
  311. u8 max_msgs_per_htc_bundle;
  312. };
  313. int ath10k_htc_init(struct ath10k *ar);
  314. int ath10k_htc_wait_target(struct ath10k_htc *htc);
  315. int ath10k_htc_start(struct ath10k_htc *htc);
  316. int ath10k_htc_connect_service(struct ath10k_htc *htc,
  317. struct ath10k_htc_svc_conn_req *conn_req,
  318. struct ath10k_htc_svc_conn_resp *conn_resp);
  319. int ath10k_htc_send(struct ath10k_htc *htc, enum ath10k_htc_ep_id eid,
  320. struct sk_buff *packet);
  321. struct sk_buff *ath10k_htc_alloc_skb(struct ath10k *ar, int size);
  322. void ath10k_htc_tx_completion_handler(struct ath10k *ar, struct sk_buff *skb);
  323. void ath10k_htc_rx_completion_handler(struct ath10k *ar, struct sk_buff *skb);
  324. void ath10k_htc_notify_tx_completion(struct ath10k_htc_ep *ep,
  325. struct sk_buff *skb);
  326. int ath10k_htc_process_trailer(struct ath10k_htc *htc,
  327. u8 *buffer,
  328. int length,
  329. enum ath10k_htc_ep_id src_eid,
  330. void *next_lookaheads,
  331. int *next_lookaheads_len);
  332. #endif