htc_internal.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /*
  2. * Copyright (c) 2013-2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #ifndef _HTC_INTERNAL_H_
  19. #define _HTC_INTERNAL_H_
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif /* __cplusplus */
  23. #include "htc_api.h"
  24. #include "htc_packet.h"
  25. #include <hif.h>
  26. #include <htc.h>
  27. #include <qdf_atomic.h>
  28. #include <qdf_event.h>
  29. #include <qdf_lock.h>
  30. #include <qdf_nbuf.h>
  31. #include <qdf_timer.h>
  32. #include <qdf_types.h>
  33. /* HTC operational parameters */
  34. #define HTC_TARGET_RESPONSE_TIMEOUT 2000 /* in ms */
  35. #define HTC_TARGET_DEBUG_INTR_MASK 0x01
  36. #define HTC_TARGET_CREDIT_INTR_MASK 0xF0
  37. #define HTC_MIN_MSG_PER_BUNDLE 2
  38. #if defined(HIF_USB)
  39. #define HTC_MAX_MSG_PER_BUNDLE_RX 11
  40. #define HTC_MAX_MSG_PER_BUNDLE_TX 8
  41. #else
  42. #define HTC_MAX_MSG_PER_BUNDLE_RX 64
  43. #define HTC_MAX_MSG_PER_BUNDLE 16
  44. #define HTC_MAX_MSG_PER_BUNDLE_TX 32
  45. #endif
  46. #ifdef HIF_SDIO
  47. #define UPDATE_ALT_CREDIT(tar, val) (tar->AltDataCreditSize = (uint16_t) val)
  48. #else
  49. #define UPDATE_ALT_CREDIT(tar, val) /* no-op */
  50. #endif
  51. /*
  52. * HTC_MAX_TX_BUNDLE_SEND_LIMIT -
  53. * This value is in units of tx frame fragments.
  54. * It needs to be at least as large as the maximum number of tx frames in a
  55. * HTC download bundle times the average number of fragments in each such frame
  56. * (In certain operating systems, such as Linux, we expect to only have
  57. * a single fragment per frame anyway.)
  58. */
  59. #define HTC_MAX_TX_BUNDLE_SEND_LIMIT 255
  60. #define HTC_PACKET_CONTAINER_ALLOCATION 32
  61. #define NUM_CONTROL_TX_BUFFERS 2
  62. #define HTC_CONTROL_BUFFER_SIZE (HTC_MAX_CONTROL_MESSAGE_LENGTH + \
  63. HTC_HDR_LENGTH)
  64. #define HTC_CONTROL_BUFFER_ALIGN 32
  65. #define HTC_TARGET_RESPONSE_POLL_MS 10
  66. #if !defined(A_SIMOS_DEVHOST)
  67. #define HTC_TARGET_MAX_RESPONSE_POLL 200 /* actual HW */
  68. #else
  69. #define HTC_TARGET_MAX_RESPONSE_POLL 600 /* host + target simulation */
  70. #endif
  71. #define HTC_SERVICE_TX_PACKET_TAG HTC_TX_PACKET_TAG_INTERNAL
  72. #define HTC_CREDIT_HISTORY_MAX 1024
  73. #define HTC_IS_EPPING_ENABLED(_x) ((_x) == QDF_GLOBAL_EPPING_MODE)
  74. enum htc_credit_exchange_type {
  75. HTC_REQUEST_CREDIT,
  76. HTC_PROCESS_CREDIT_REPORT,
  77. HTC_SUSPEND_ACK,
  78. HTC_SUSPEND_NACK,
  79. HTC_INITIAL_WAKE_UP,
  80. };
  81. static inline const char*
  82. htc_credit_exchange_type_str(enum htc_credit_exchange_type type)
  83. {
  84. switch (type) {
  85. case HTC_REQUEST_CREDIT:
  86. return "HTC_REQUEST_CREDIT";
  87. case HTC_PROCESS_CREDIT_REPORT:
  88. return "HTC_PROCESS_CREDIT_REPORT";
  89. case HTC_SUSPEND_ACK:
  90. return "HTC_SUSPEND_ACK";
  91. case HTC_SUSPEND_NACK:
  92. return "HTC_SUSPEND_NACK";
  93. case HTC_INITIAL_WAKE_UP:
  94. return "HTC_INITIAL_WAKE_UP";
  95. default:
  96. return "Unknown htc_credit_exchange_type";
  97. }
  98. }
  99. typedef struct _HTC_ENDPOINT {
  100. HTC_ENDPOINT_ID Id;
  101. /* service ID this endpoint is bound to
  102. * non-zero value means this endpoint is in use
  103. */
  104. HTC_SERVICE_ID service_id;
  105. /* callbacks associated with this endpoint */
  106. struct htc_ep_callbacks EpCallBacks;
  107. /* HTC frame buffer TX queue */
  108. HTC_PACKET_QUEUE TxQueue;
  109. /* max depth of the TX queue before calling driver's full handler */
  110. int MaxTxQueueDepth;
  111. /* max length of endpoint message */
  112. int MaxMsgLength;
  113. uint8_t UL_PipeID;
  114. uint8_t DL_PipeID;
  115. /* Need to call HIF to get tx completion callbacks? */
  116. int ul_is_polled;
  117. qdf_timer_t ul_poll_timer;
  118. int ul_poll_timer_active;
  119. int ul_outstanding_cnt;
  120. /* Need to call HIF to fetch rx? (Not currently supported.) */
  121. int dl_is_polled;
  122. /* not currently supported */
  123. /* qdf_timer_t dl_poll_timer; */
  124. /* lookup queue to match netbufs to htc packets */
  125. HTC_PACKET_QUEUE TxLookupQueue;
  126. /* temporary hold queue for back compatibility */
  127. HTC_PACKET_QUEUE RxBufferHoldQueue;
  128. /* TX seq no (helpful) for debugging */
  129. uint8_t SeqNo;
  130. /* serialization */
  131. qdf_atomic_t TxProcessCount;
  132. struct _HTC_TARGET *target;
  133. /* TX credits available on this endpoint */
  134. int TxCredits;
  135. /* size in bytes of each credit (set by HTC) */
  136. int TxCreditSize;
  137. /* credits required per max message (precalculated) */
  138. int TxCreditsPerMaxMsg;
  139. #ifdef HTC_EP_STAT_PROFILING
  140. /* endpoint statistics */
  141. struct htc_endpoint_stats endpoint_stats;
  142. #endif
  143. bool TxCreditFlowEnabled;
  144. bool async_update; /* packets can be queued asynchronously */
  145. qdf_spinlock_t lookup_queue_lock;
  146. } HTC_ENDPOINT;
  147. #ifdef HTC_EP_STAT_PROFILING
  148. #define INC_HTC_EP_STAT(p, stat, count) ((p)->endpoint_stats.stat += (count))
  149. #else
  150. #define INC_HTC_EP_STAT(p, stat, count)
  151. #endif
  152. struct htc_service_tx_credit_allocation {
  153. uint16_t service_id;
  154. uint8_t CreditAllocation;
  155. };
  156. #define HTC_MAX_SERVICE_ALLOC_ENTRIES 8
  157. /* Error codes for HTC layer packet stats*/
  158. enum ol_ath_htc_pkt_ecodes {
  159. /* error- get packet at head of HTC_PACKET_Q */
  160. GET_HTC_PKT_Q_FAIL = 0,
  161. HTC_PKT_Q_EMPTY,
  162. HTC_SEND_Q_EMPTY
  163. };
  164. /* our HTC target state */
  165. typedef struct _HTC_TARGET {
  166. struct hif_opaque_softc *hif_dev;
  167. HTC_ENDPOINT endpoint[ENDPOINT_MAX];
  168. qdf_spinlock_t HTCLock;
  169. qdf_spinlock_t HTCRxLock;
  170. qdf_spinlock_t HTCTxLock;
  171. qdf_spinlock_t HTCCreditLock;
  172. uint32_t HTCStateFlags;
  173. void *host_handle;
  174. struct htc_init_info HTCInitInfo;
  175. HTC_PACKET *pHTCPacketStructPool; /* pool of HTC packets */
  176. HTC_PACKET_QUEUE ControlBufferTXFreeList;
  177. uint8_t CtrlResponseBuffer[HTC_MAX_CONTROL_MESSAGE_LENGTH];
  178. int CtrlResponseLength;
  179. qdf_event_t ctrl_response_valid;
  180. bool CtrlResponseProcessing;
  181. int TotalTransmitCredits;
  182. struct htc_service_tx_credit_allocation
  183. ServiceTxAllocTable[HTC_MAX_SERVICE_ALLOC_ENTRIES];
  184. int TargetCreditSize;
  185. #ifdef RX_SG_SUPPORT
  186. qdf_nbuf_queue_t RxSgQueue;
  187. bool IsRxSgInprogress;
  188. uint32_t CurRxSgTotalLen; /* current total length */
  189. uint32_t ExpRxSgTotalLen; /* expected total length */
  190. #endif
  191. qdf_device_t osdev;
  192. struct ol_ath_htc_stats htc_pkt_stats;
  193. HTC_PACKET *pBundleFreeList;
  194. uint32_t ce_send_cnt;
  195. uint32_t TX_comp_cnt;
  196. uint8_t MaxMsgsPerHTCBundle;
  197. qdf_work_t queue_kicker;
  198. #ifdef HIF_SDIO
  199. uint16_t AltDataCreditSize;
  200. #endif
  201. uint32_t avail_tx_credits;
  202. #if defined(DEBUG_HL_LOGGING) && defined(CONFIG_HL_SUPPORT)
  203. uint32_t rx_bundle_stats[HTC_MAX_MSG_PER_BUNDLE_RX];
  204. uint32_t tx_bundle_stats[HTC_MAX_MSG_PER_BUNDLE_TX];
  205. #endif
  206. uint32_t con_mode;
  207. /*
  208. * This flag is from the mboxping tool. It indicates that we cannot
  209. * drop it. Besides, nodrop pkts have higher priority than normal pkts.
  210. */
  211. A_BOOL is_nodrop_pkt;
  212. /*
  213. * Number of WMI endpoints used.
  214. * Default value is 1. But it should be overidden after htc_create to
  215. * reflect the actual count.
  216. */
  217. uint8_t wmi_ep_count;
  218. } HTC_TARGET;
  219. #ifdef RX_SG_SUPPORT
  220. #define RESET_RX_SG_CONFIG(_target) \
  221. do { \
  222. _target->ExpRxSgTotalLen = 0; \
  223. _target->CurRxSgTotalLen = 0; \
  224. _target->IsRxSgInprogress = false; \
  225. } while (0)
  226. #endif
  227. #define HTC_STATE_STOPPING (1 << 0)
  228. #define HTC_STOPPING(t) ((t)->HTCStateFlags & HTC_STATE_STOPPING)
  229. #define LOCK_HTC(t) qdf_spin_lock_bh(&(t)->HTCLock)
  230. #define UNLOCK_HTC(t) qdf_spin_unlock_bh(&(t)->HTCLock)
  231. #define LOCK_HTC_RX(t) qdf_spin_lock_bh(&(t)->HTCRxLock)
  232. #define UNLOCK_HTC_RX(t) qdf_spin_unlock_bh(&(t)->HTCRxLock)
  233. #define LOCK_HTC_TX(t) qdf_spin_lock_bh(&(t)->HTCTxLock)
  234. #define UNLOCK_HTC_TX(t) qdf_spin_unlock_bh(&(t)->HTCTxLock)
  235. #define LOCK_HTC_EP_TX_LOOKUP(t) qdf_spin_lock_bh(&(t)->lookup_queue_lock)
  236. #define UNLOCK_HTC_EP_TX_LOOKUP(t) qdf_spin_unlock_bh(&(t)->lookup_queue_lock)
  237. #define GET_HTC_TARGET_FROM_HANDLE(hnd) ((HTC_TARGET *)(hnd))
  238. #define IS_TX_CREDIT_FLOW_ENABLED(ep) ((ep)->TxCreditFlowEnabled)
  239. #define HTC_POLL_CLEANUP_PERIOD_MS 10 /* milliseconds */
  240. /* Macro to Increment the HTC_PACKET_ERRORS for Tx.*/
  241. #define OL_ATH_HTC_PKT_ERROR_COUNT_INCR(_target, _ecode) \
  242. do { \
  243. if (_ecode == GET_HTC_PKT_Q_FAIL) \
  244. (_target->htc_pkt_stats.htc_get_pkt_q_fail_count) += 1; \
  245. if (_ecode == HTC_PKT_Q_EMPTY) \
  246. (_target->htc_pkt_stats.htc_pkt_q_empty_count) += 1; \
  247. if (_ecode == HTC_SEND_Q_EMPTY) \
  248. (_target->htc_pkt_stats.htc_send_q_empty_count) += 1; \
  249. } while (0)
  250. /* internal HTC functions */
  251. QDF_STATUS htc_rx_completion_handler(void *Context, qdf_nbuf_t netbuf,
  252. uint8_t pipeID);
  253. QDF_STATUS htc_tx_completion_handler(void *Context, qdf_nbuf_t netbuf,
  254. unsigned int transferID,
  255. uint32_t toeplitz_hash_result);
  256. HTC_PACKET *allocate_htc_bundle_packet(HTC_TARGET *target);
  257. void free_htc_bundle_packet(HTC_TARGET *target, HTC_PACKET *pPacket);
  258. HTC_PACKET *allocate_htc_packet_container(HTC_TARGET *target);
  259. void free_htc_packet_container(HTC_TARGET *target, HTC_PACKET *pPacket);
  260. void htc_flush_rx_hold_queue(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint);
  261. void htc_flush_endpoint_tx(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint,
  262. HTC_TX_TAG Tag);
  263. void htc_recv_init(HTC_TARGET *target);
  264. QDF_STATUS htc_wait_recv_ctrl_message(HTC_TARGET *target);
  265. void htc_free_control_tx_packet(HTC_TARGET *target, HTC_PACKET *pPacket);
  266. HTC_PACKET *htc_alloc_control_tx_packet(HTC_TARGET *target);
  267. uint8_t htc_get_credit_allocation(HTC_TARGET *target, uint16_t service_id);
  268. void htc_tx_resource_avail_handler(void *context, uint8_t pipeID);
  269. void htc_control_rx_complete(void *Context, HTC_PACKET *pPacket);
  270. void htc_process_credit_rpt(HTC_TARGET *target,
  271. HTC_CREDIT_REPORT *pRpt,
  272. int NumEntries, HTC_ENDPOINT_ID FromEndpoint);
  273. void htc_fw_event_handler(void *context, QDF_STATUS status);
  274. void htc_send_complete_check_cleanup(void *context);
  275. #ifdef FEATURE_RUNTIME_PM
  276. void htc_kick_queues(void *context);
  277. #endif
  278. static inline void htc_send_complete_poll_timer_stop(HTC_ENDPOINT *
  279. pEndpoint) {
  280. LOCK_HTC_TX(pEndpoint->target);
  281. if (pEndpoint->ul_poll_timer_active) {
  282. /* qdf_timer_stop(&pEndpoint->ul_poll_timer); */
  283. pEndpoint->ul_poll_timer_active = 0;
  284. }
  285. UNLOCK_HTC_TX(pEndpoint->target);
  286. }
  287. static inline void htc_send_complete_poll_timer_start(HTC_ENDPOINT *
  288. pEndpoint) {
  289. LOCK_HTC_TX(pEndpoint->target);
  290. if (pEndpoint->ul_outstanding_cnt
  291. && !pEndpoint->ul_poll_timer_active) {
  292. /* qdf_timer_start(
  293. * &pEndpoint->ul_poll_timer, HTC_POLL_CLEANUP_PERIOD_MS);
  294. */
  295. pEndpoint->ul_poll_timer_active = 1;
  296. }
  297. UNLOCK_HTC_TX(pEndpoint->target);
  298. }
  299. static inline void
  300. htc_send_complete_check(HTC_ENDPOINT *pEndpoint, int force) {
  301. /*
  302. * Stop the polling-cleanup timer that will result in a later call to
  303. * this function. It may get started again below, if there are still
  304. * outsending sends.
  305. */
  306. htc_send_complete_poll_timer_stop(pEndpoint);
  307. /*
  308. * Check whether HIF has any prior sends that have finished,
  309. * have not had the post-processing done.
  310. */
  311. hif_send_complete_check(pEndpoint->target->hif_dev,
  312. pEndpoint->UL_PipeID, force);
  313. /*
  314. * If there are still outstanding sends after polling, start a timer
  315. * to check again a little later.
  316. */
  317. htc_send_complete_poll_timer_start(pEndpoint);
  318. }
  319. #ifdef __cplusplus
  320. }
  321. #endif
  322. #ifndef DEBUG_BUNDLE
  323. #define DEBUG_BUNDLE 0
  324. #endif
  325. #if defined(HIF_SDIO) || defined(HIF_USB)
  326. #ifndef ENABLE_BUNDLE_TX
  327. #define ENABLE_BUNDLE_TX 1
  328. #endif
  329. #ifndef ENABLE_BUNDLE_RX
  330. #define ENABLE_BUNDLE_RX 1
  331. #endif
  332. #endif /*defined(HIF_SDIO) || defined(HIF_USB)*/
  333. #if defined ENABLE_BUNDLE_TX
  334. #define HTC_TX_BUNDLE_ENABLED(target) (target->MaxMsgsPerHTCBundle > 1)
  335. #else
  336. #define HTC_TX_BUNDLE_ENABLED(target) 0
  337. #endif
  338. #if defined ENABLE_BUNDLE_RX
  339. #define HTC_RX_BUNDLE_ENABLED(target) (target->MaxMsgsPerHTCBundle > 1)
  340. #else
  341. #define HTC_RX_BUNDLE_ENABLED(target) 0
  342. #endif
  343. #define HTC_ENABLE_BUNDLE(target) (target->MaxMsgsPerHTCBundle > 1)
  344. #endif /* !_HTC_HOST_INTERNAL_H_ */