htc.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. /*
  2. * Copyright (c) 2004-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011 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 "common.h"
  20. /* frame header flags */
  21. /* send direction */
  22. #define HTC_FLAGS_NEED_CREDIT_UPDATE (1 << 0)
  23. #define HTC_FLAGS_SEND_BUNDLE (1 << 1)
  24. /* receive direction */
  25. #define HTC_FLG_RX_UNUSED (1 << 0)
  26. #define HTC_FLG_RX_TRAILER (1 << 1)
  27. /* Bundle count maske and shift */
  28. #define HTC_FLG_RX_BNDL_CNT (0xF0)
  29. #define HTC_FLG_RX_BNDL_CNT_S 4
  30. #define HTC_HDR_LENGTH (sizeof(struct htc_frame_hdr))
  31. #define HTC_MAX_PAYLOAD_LENGTH (4096 - sizeof(struct htc_frame_hdr))
  32. /* HTC control message IDs */
  33. #define HTC_MSG_READY_ID 1
  34. #define HTC_MSG_CONN_SVC_ID 2
  35. #define HTC_MSG_CONN_SVC_RESP_ID 3
  36. #define HTC_MSG_SETUP_COMPLETE_ID 4
  37. #define HTC_MSG_SETUP_COMPLETE_EX_ID 5
  38. #define HTC_MAX_CTRL_MSG_LEN 256
  39. #define HTC_VERSION_2P0 0x00
  40. #define HTC_VERSION_2P1 0x01
  41. #define HTC_SERVICE_META_DATA_MAX_LENGTH 128
  42. #define HTC_CONN_FLGS_THRESH_LVL_QUAT 0x0
  43. #define HTC_CONN_FLGS_THRESH_LVL_HALF 0x1
  44. #define HTC_CONN_FLGS_THRESH_LVL_THREE_QUAT 0x2
  45. #define HTC_CONN_FLGS_REDUCE_CRED_DRIB 0x4
  46. #define HTC_CONN_FLGS_THRESH_MASK 0x3
  47. /* connect response status codes */
  48. #define HTC_SERVICE_SUCCESS 0
  49. #define HTC_SERVICE_NOT_FOUND 1
  50. #define HTC_SERVICE_FAILED 2
  51. /* no resources (i.e. no more endpoints) */
  52. #define HTC_SERVICE_NO_RESOURCES 3
  53. /* specific service is not allowing any more endpoints */
  54. #define HTC_SERVICE_NO_MORE_EP 4
  55. /* report record IDs */
  56. #define HTC_RECORD_NULL 0
  57. #define HTC_RECORD_CREDITS 1
  58. #define HTC_RECORD_LOOKAHEAD 2
  59. #define HTC_RECORD_LOOKAHEAD_BUNDLE 3
  60. #define HTC_SETUP_COMP_FLG_RX_BNDL_EN (1 << 0)
  61. #define MAKE_SERVICE_ID(group, index) \
  62. (int)(((int)group << 8) | (int)(index))
  63. /* NOTE: service ID of 0x0000 is reserved and should never be used */
  64. #define HTC_CTRL_RSVD_SVC MAKE_SERVICE_ID(RSVD_SERVICE_GROUP, 1)
  65. #define WMI_CONTROL_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 0)
  66. #define WMI_DATA_BE_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 1)
  67. #define WMI_DATA_BK_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 2)
  68. #define WMI_DATA_VI_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 3)
  69. #define WMI_DATA_VO_SVC MAKE_SERVICE_ID(WMI_SERVICE_GROUP, 4)
  70. #define WMI_MAX_SERVICES 5
  71. /* reserved and used to flush ALL packets */
  72. #define HTC_TX_PACKET_TAG_ALL 0
  73. #define HTC_SERVICE_TX_PACKET_TAG 1
  74. #define HTC_TX_PACKET_TAG_USER_DEFINED (HTC_SERVICE_TX_PACKET_TAG + 9)
  75. /* more packets on this endpoint are being fetched */
  76. #define HTC_RX_FLAGS_INDICATE_MORE_PKTS (1 << 0)
  77. /* TODO.. for BMI */
  78. #define ENDPOINT1 0
  79. /* TODO -remove me, but we have to fix BMI first */
  80. #define HTC_MAILBOX_NUM_MAX 4
  81. /* enable send bundle padding for this endpoint */
  82. #define HTC_FLGS_TX_BNDL_PAD_EN (1 << 0)
  83. #define HTC_EP_ACTIVE ((u32) (1u << 31))
  84. /* HTC operational parameters */
  85. #define HTC_TARGET_RESPONSE_TIMEOUT 2000 /* in ms */
  86. #define HTC_TARGET_DEBUG_INTR_MASK 0x01
  87. #define HTC_TARGET_CREDIT_INTR_MASK 0xF0
  88. #define HTC_HOST_MAX_MSG_PER_BUNDLE 8
  89. #define HTC_MIN_HTC_MSGS_TO_BUNDLE 2
  90. /* packet flags */
  91. #define HTC_RX_PKT_IGNORE_LOOKAHEAD (1 << 0)
  92. #define HTC_RX_PKT_REFRESH_HDR (1 << 1)
  93. #define HTC_RX_PKT_PART_OF_BUNDLE (1 << 2)
  94. #define HTC_RX_PKT_NO_RECYCLE (1 << 3)
  95. #define NUM_CONTROL_BUFFERS 8
  96. #define NUM_CONTROL_TX_BUFFERS 2
  97. #define NUM_CONTROL_RX_BUFFERS (NUM_CONTROL_BUFFERS - NUM_CONTROL_TX_BUFFERS)
  98. #define HTC_RECV_WAIT_BUFFERS (1 << 0)
  99. #define HTC_OP_STATE_STOPPING (1 << 0)
  100. /*
  101. * The frame header length and message formats defined herein were selected
  102. * to accommodate optimal alignment for target processing. This reduces
  103. * code size and improves performance. Any changes to the header length may
  104. * alter the alignment and cause exceptions on the target. When adding to
  105. * the messagestructures insure that fields are properly aligned.
  106. */
  107. /* HTC frame header
  108. *
  109. * NOTE: do not remove or re-arrange the fields, these are minimally
  110. * required to take advantage of 4-byte lookaheads in some hardware
  111. * implementations.
  112. */
  113. struct htc_frame_hdr {
  114. u8 eid;
  115. u8 flags;
  116. /* length of data (including trailer) that follows the header */
  117. __le16 payld_len;
  118. /* end of 4-byte lookahead */
  119. u8 ctrl[2];
  120. } __packed;
  121. /* HTC ready message */
  122. struct htc_ready_msg {
  123. __le16 msg_id;
  124. __le16 cred_cnt;
  125. __le16 cred_sz;
  126. u8 max_ep;
  127. u8 pad;
  128. } __packed;
  129. /* extended HTC ready message */
  130. struct htc_ready_ext_msg {
  131. struct htc_ready_msg ver2_0_info;
  132. u8 htc_ver;
  133. u8 msg_per_htc_bndl;
  134. } __packed;
  135. /* connect service */
  136. struct htc_conn_service_msg {
  137. __le16 msg_id;
  138. __le16 svc_id;
  139. __le16 conn_flags;
  140. u8 svc_meta_len;
  141. u8 pad;
  142. } __packed;
  143. /* connect response */
  144. struct htc_conn_service_resp {
  145. __le16 msg_id;
  146. __le16 svc_id;
  147. u8 status;
  148. u8 eid;
  149. __le16 max_msg_sz;
  150. u8 svc_meta_len;
  151. u8 pad;
  152. } __packed;
  153. struct htc_setup_comp_msg {
  154. __le16 msg_id;
  155. } __packed;
  156. /* extended setup completion message */
  157. struct htc_setup_comp_ext_msg {
  158. __le16 msg_id;
  159. __le32 flags;
  160. u8 msg_per_rxbndl;
  161. u8 Rsvd[3];
  162. } __packed;
  163. struct htc_record_hdr {
  164. u8 rec_id;
  165. u8 len;
  166. } __packed;
  167. struct htc_credit_report {
  168. u8 eid;
  169. u8 credits;
  170. } __packed;
  171. /*
  172. * NOTE: The lk_ahd array is guarded by a pre_valid
  173. * and Post Valid guard bytes. The pre_valid bytes must
  174. * equal the inverse of the post_valid byte.
  175. */
  176. struct htc_lookahead_report {
  177. u8 pre_valid;
  178. u8 lk_ahd[4];
  179. u8 post_valid;
  180. } __packed;
  181. struct htc_bundle_lkahd_rpt {
  182. u8 lk_ahd[4];
  183. } __packed;
  184. /* Current service IDs */
  185. enum htc_service_grp_ids {
  186. RSVD_SERVICE_GROUP = 0,
  187. WMI_SERVICE_GROUP = 1,
  188. HTC_TEST_GROUP = 254,
  189. HTC_SERVICE_GROUP_LAST = 255
  190. };
  191. /* ------ endpoint IDS ------ */
  192. enum htc_endpoint_id {
  193. ENDPOINT_UNUSED = -1,
  194. ENDPOINT_0 = 0,
  195. ENDPOINT_1 = 1,
  196. ENDPOINT_2 = 2,
  197. ENDPOINT_3,
  198. ENDPOINT_4,
  199. ENDPOINT_5,
  200. ENDPOINT_6,
  201. ENDPOINT_7,
  202. ENDPOINT_8,
  203. ENDPOINT_MAX,
  204. };
  205. struct htc_tx_packet_info {
  206. u16 tag;
  207. int cred_used;
  208. u8 flags;
  209. int seqno;
  210. };
  211. struct htc_rx_packet_info {
  212. u32 exp_hdr;
  213. u32 rx_flags;
  214. u32 indicat_flags;
  215. };
  216. struct htc_target;
  217. /* wrapper around endpoint-specific packets */
  218. struct htc_packet {
  219. struct list_head list;
  220. /* caller's per packet specific context */
  221. void *pkt_cntxt;
  222. /*
  223. * the true buffer start , the caller can store the real
  224. * buffer start here. In receive callbacks, the HTC layer
  225. * sets buf to the start of the payload past the header.
  226. * This field allows the caller to reset buf when it recycles
  227. * receive packets back to HTC.
  228. */
  229. u8 *buf_start;
  230. /*
  231. * Pointer to the start of the buffer. In the transmit
  232. * direction this points to the start of the payload. In the
  233. * receive direction, however, the buffer when queued up
  234. * points to the start of the HTC header but when returned
  235. * to the caller points to the start of the payload
  236. */
  237. u8 *buf;
  238. u32 buf_len;
  239. /* actual length of payload */
  240. u32 act_len;
  241. /* endpoint that this packet was sent/recv'd from */
  242. enum htc_endpoint_id endpoint;
  243. /* completion status */
  244. int status;
  245. union {
  246. struct htc_tx_packet_info tx;
  247. struct htc_rx_packet_info rx;
  248. } info;
  249. void (*completion) (struct htc_target *, struct htc_packet *);
  250. struct htc_target *context;
  251. };
  252. enum htc_send_full_action {
  253. HTC_SEND_FULL_KEEP = 0,
  254. HTC_SEND_FULL_DROP = 1,
  255. };
  256. struct htc_ep_callbacks {
  257. void (*rx) (struct htc_target *, struct htc_packet *);
  258. void (*rx_refill) (struct htc_target *, enum htc_endpoint_id endpoint);
  259. enum htc_send_full_action (*tx_full) (struct htc_target *,
  260. struct htc_packet *);
  261. struct htc_packet *(*rx_allocthresh) (struct htc_target *,
  262. enum htc_endpoint_id, int);
  263. int rx_alloc_thresh;
  264. int rx_refill_thresh;
  265. };
  266. /* service connection information */
  267. struct htc_service_connect_req {
  268. u16 svc_id;
  269. u16 conn_flags;
  270. struct htc_ep_callbacks ep_cb;
  271. int max_txq_depth;
  272. u32 flags;
  273. unsigned int max_rxmsg_sz;
  274. };
  275. /* service connection response information */
  276. struct htc_service_connect_resp {
  277. u8 buf_len;
  278. u8 act_len;
  279. enum htc_endpoint_id endpoint;
  280. unsigned int len_max;
  281. u8 resp_code;
  282. };
  283. /* endpoint distributionstructure */
  284. struct htc_endpoint_credit_dist {
  285. struct list_head list;
  286. /* Service ID (set by HTC) */
  287. u16 svc_id;
  288. /* endpoint for this distributionstruct (set by HTC) */
  289. enum htc_endpoint_id endpoint;
  290. u32 dist_flags;
  291. /*
  292. * credits for normal operation, anything above this
  293. * indicates the endpoint is over-subscribed.
  294. */
  295. int cred_norm;
  296. /* floor for credit distribution */
  297. int cred_min;
  298. int cred_assngd;
  299. /* current credits available */
  300. int credits;
  301. /*
  302. * pending credits to distribute on this endpoint, this
  303. * is set by HTC when credit reports arrive. The credit
  304. * distribution functions sets this to zero when it distributes
  305. * the credits.
  306. */
  307. int cred_to_dist;
  308. /*
  309. * the number of credits that the current pending TX packet needs
  310. * to transmit. This is set by HTC when endpoint needs credits in
  311. * order to transmit.
  312. */
  313. int seek_cred;
  314. /* size in bytes of each credit */
  315. int cred_sz;
  316. /* credits required for a maximum sized messages */
  317. int cred_per_msg;
  318. /* reserved for HTC use */
  319. struct htc_endpoint *htc_ep;
  320. /*
  321. * current depth of TX queue , i.e. messages waiting for credits
  322. * This field is valid only when HTC_CREDIT_DIST_ACTIVITY_CHANGE
  323. * or HTC_CREDIT_DIST_SEND_COMPLETE is indicated on an endpoint
  324. * that has non-zero credits to recover.
  325. */
  326. int txq_depth;
  327. };
  328. /*
  329. * credit distibution code that is passed into the distrbution function,
  330. * there are mandatory and optional codes that must be handled
  331. */
  332. enum htc_credit_dist_reason {
  333. HTC_CREDIT_DIST_SEND_COMPLETE = 0,
  334. HTC_CREDIT_DIST_ACTIVITY_CHANGE = 1,
  335. HTC_CREDIT_DIST_SEEK_CREDITS,
  336. };
  337. struct ath6kl_htc_credit_info {
  338. int total_avail_credits;
  339. int cur_free_credits;
  340. /* list of lowest priority endpoints */
  341. struct list_head lowestpri_ep_dist;
  342. };
  343. /* endpoint statistics */
  344. struct htc_endpoint_stats {
  345. /*
  346. * number of times the host set the credit-low flag in a send
  347. * message on this endpoint
  348. */
  349. u32 cred_low_indicate;
  350. u32 tx_issued;
  351. u32 tx_pkt_bundled;
  352. u32 tx_bundles;
  353. u32 tx_dropped;
  354. /* running count of total credit reports received for this endpoint */
  355. u32 tx_cred_rpt;
  356. /* credit reports received from this endpoint's RX packets */
  357. u32 cred_rpt_from_rx;
  358. /* credit reports received from RX packets of other endpoints */
  359. u32 cred_rpt_from_other;
  360. /* credit reports received from endpoint 0 RX packets */
  361. u32 cred_rpt_ep0;
  362. /* count of credits received via Rx packets on this endpoint */
  363. u32 cred_from_rx;
  364. /* count of credits received via another endpoint */
  365. u32 cred_from_other;
  366. /* count of credits received via another endpoint */
  367. u32 cred_from_ep0;
  368. /* count of consummed credits */
  369. u32 cred_cosumd;
  370. /* count of credits returned */
  371. u32 cred_retnd;
  372. u32 rx_pkts;
  373. /* count of lookahead records found in Rx msg */
  374. u32 rx_lkahds;
  375. /* count of recv packets received in a bundle */
  376. u32 rx_bundl;
  377. /* count of number of bundled lookaheads */
  378. u32 rx_bundle_lkahd;
  379. /* count of the number of bundle indications from the HTC header */
  380. u32 rx_bundle_from_hdr;
  381. /* the number of times the recv allocation threshold was hit */
  382. u32 rx_alloc_thresh_hit;
  383. /* total number of bytes */
  384. u32 rxalloc_thresh_byte;
  385. };
  386. struct htc_endpoint {
  387. enum htc_endpoint_id eid;
  388. u16 svc_id;
  389. struct list_head txq;
  390. struct list_head rx_bufq;
  391. struct htc_endpoint_credit_dist cred_dist;
  392. struct htc_ep_callbacks ep_cb;
  393. int max_txq_depth;
  394. int len_max;
  395. int tx_proc_cnt;
  396. int rx_proc_cnt;
  397. struct htc_target *target;
  398. u8 seqno;
  399. u32 conn_flags;
  400. struct htc_endpoint_stats ep_st;
  401. };
  402. struct htc_control_buffer {
  403. struct htc_packet packet;
  404. u8 *buf;
  405. };
  406. struct ath6kl_device;
  407. /* our HTC target state */
  408. struct htc_target {
  409. struct htc_endpoint endpoint[ENDPOINT_MAX];
  410. /* contains struct htc_endpoint_credit_dist */
  411. struct list_head cred_dist_list;
  412. struct list_head free_ctrl_txbuf;
  413. struct list_head free_ctrl_rxbuf;
  414. struct ath6kl_htc_credit_info *credit_info;
  415. int tgt_creds;
  416. unsigned int tgt_cred_sz;
  417. spinlock_t htc_lock;
  418. spinlock_t rx_lock;
  419. spinlock_t tx_lock;
  420. struct ath6kl_device *dev;
  421. u32 htc_flags;
  422. u32 rx_st_flags;
  423. enum htc_endpoint_id ep_waiting;
  424. u8 htc_tgt_ver;
  425. /* max messages per bundle for HTC */
  426. int msg_per_bndl_max;
  427. bool tx_bndl_enable;
  428. int rx_bndl_enable;
  429. int max_rx_bndl_sz;
  430. int max_tx_bndl_sz;
  431. u32 block_sz;
  432. u32 block_mask;
  433. int max_scat_entries;
  434. int max_xfer_szper_scatreq;
  435. int chk_irq_status_cnt;
  436. };
  437. void *ath6kl_htc_create(struct ath6kl *ar);
  438. void ath6kl_htc_set_credit_dist(struct htc_target *target,
  439. struct ath6kl_htc_credit_info *cred_info,
  440. u16 svc_pri_order[], int len);
  441. int ath6kl_htc_wait_target(struct htc_target *target);
  442. int ath6kl_htc_start(struct htc_target *target);
  443. int ath6kl_htc_conn_service(struct htc_target *target,
  444. struct htc_service_connect_req *req,
  445. struct htc_service_connect_resp *resp);
  446. int ath6kl_htc_tx(struct htc_target *target, struct htc_packet *packet);
  447. void ath6kl_htc_stop(struct htc_target *target);
  448. void ath6kl_htc_cleanup(struct htc_target *target);
  449. void ath6kl_htc_flush_txep(struct htc_target *target,
  450. enum htc_endpoint_id endpoint, u16 tag);
  451. void ath6kl_htc_flush_rx_buf(struct htc_target *target);
  452. void ath6kl_htc_indicate_activity_change(struct htc_target *target,
  453. enum htc_endpoint_id endpoint,
  454. bool active);
  455. int ath6kl_htc_get_rxbuf_num(struct htc_target *target,
  456. enum htc_endpoint_id endpoint);
  457. int ath6kl_htc_add_rxbuf_multiple(struct htc_target *target,
  458. struct list_head *pktq);
  459. int ath6kl_htc_rxmsg_pending_handler(struct htc_target *target,
  460. u32 msg_look_ahead, int *n_pkts);
  461. int ath6kl_credit_setup(void *htc_handle,
  462. struct ath6kl_htc_credit_info *cred_info);
  463. static inline void set_htc_pkt_info(struct htc_packet *packet, void *context,
  464. u8 *buf, unsigned int len,
  465. enum htc_endpoint_id eid, u16 tag)
  466. {
  467. packet->pkt_cntxt = context;
  468. packet->buf = buf;
  469. packet->act_len = len;
  470. packet->endpoint = eid;
  471. packet->info.tx.tag = tag;
  472. }
  473. static inline void htc_rxpkt_reset(struct htc_packet *packet)
  474. {
  475. packet->buf = packet->buf_start;
  476. packet->act_len = 0;
  477. }
  478. static inline void set_htc_rxpkt_info(struct htc_packet *packet, void *context,
  479. u8 *buf, unsigned long len,
  480. enum htc_endpoint_id eid)
  481. {
  482. packet->pkt_cntxt = context;
  483. packet->buf = buf;
  484. packet->buf_start = buf;
  485. packet->buf_len = len;
  486. packet->endpoint = eid;
  487. }
  488. static inline int get_queue_depth(struct list_head *queue)
  489. {
  490. struct list_head *tmp_list;
  491. int depth = 0;
  492. list_for_each(tmp_list, queue)
  493. depth++;
  494. return depth;
  495. }
  496. #endif