htc.h 15 KB

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