htc_api.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. /*
  2. * Copyright (c) 2013-2014, 2016-2021 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_API_H_
  19. #define _HTC_API_H_
  20. #include <htc.h>
  21. #include <htc_services.h>
  22. #include <qdf_types.h> /* qdf_device_t */
  23. #include "htc_packet.h"
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif /* __cplusplus */
  27. /* TODO.. for BMI */
  28. #define ENDPOINT1 0
  29. /* TODO -remove me, but we have to fix BMI first */
  30. #define HTC_MAILBOX_NUM_MAX 4
  31. /* this is the amount of header room required by users of HTC */
  32. #define HTC_HEADER_LEN HTC_HDR_LENGTH
  33. #define HTC_HTT_TRANSFER_HDRSIZE 24
  34. /*
  35. * NOTE WELL: struct opaque_htc_handle is not defined anywhere. This
  36. * reference is used to help ensure that a HTC_HANDLE is never used
  37. * where a different handle type is expected
  38. */
  39. struct opaque_htc_handle;
  40. typedef struct opaque_htc_handle *HTC_HANDLE;
  41. typedef uint16_t HTC_SERVICE_ID;
  42. typedef void (*HTC_TARGET_FAILURE)(void *Instance, QDF_STATUS Status);
  43. struct htc_init_info {
  44. void *pContext; /* context for target notifications */
  45. void (*TargetFailure)(void *Instance, QDF_STATUS Status);
  46. void (*TargetSendSuspendComplete)(void *ctx, bool is_nack);
  47. void (*target_initial_wakeup_cb)(void *cb_ctx);
  48. void *target_psoc;
  49. uint32_t cfg_wmi_credit_cnt;
  50. /* HTC Pipe Ready Timeout in msecs */
  51. uint32_t htc_ready_timeout_ms;
  52. };
  53. /* Struct for HTC layer packet stats*/
  54. struct ol_ath_htc_stats {
  55. int htc_get_pkt_q_fail_count;
  56. int htc_pkt_q_empty_count;
  57. int htc_send_q_empty_count;
  58. };
  59. /* To resume HTT Tx queue during runtime resume */
  60. typedef void (*HTC_EP_RESUME_TX_QUEUE)(void *);
  61. typedef int (*HTC_EP_PADDING_CREDIT_UPDATE) (void *, int);
  62. /* per service connection send completion */
  63. typedef void (*HTC_EP_SEND_PKT_COMPLETE)(void *, HTC_PACKET *);
  64. /* per service connection callback when a plurality of packets have been sent
  65. * The HTC_PACKET_QUEUE is a temporary queue object (e.g. freed on return from
  66. * the callback) to hold a list of completed send packets.
  67. * If the handler cannot fully traverse the packet queue before returning, it
  68. * should transfer the items of the queue into the caller's private queue using:
  69. * HTC_PACKET_ENQUEUE()
  70. */
  71. typedef void (*HTC_EP_SEND_PKT_COMP_MULTIPLE)(void *,
  72. HTC_PACKET_QUEUE *);
  73. /* per service connection pkt received */
  74. typedef void (*HTC_EP_RECV_PKT)(void *, HTC_PACKET *);
  75. /* per service connection callback when a plurality of packets are received
  76. * The HTC_PACKET_QUEUE is a temporary queue object (e.g. freed on return from
  77. * the callback) to hold a list of recv packets.
  78. * If the handler cannot fully traverse the packet queue before returning, it
  79. * should transfer the items of the queue into the caller's private queue using:
  80. * HTC_PACKET_ENQUEUE()
  81. */
  82. typedef void (*HTC_EP_RECV_PKT_MULTIPLE)(void *, HTC_PACKET_QUEUE *);
  83. /* Optional per service connection receive buffer re-fill callback,
  84. * On some OSes (like Linux) packets are allocated from a global pool and
  85. * indicated up to the network stack. The driver never gets the packets back
  86. * from the OS. For these OSes a refill callback can be used to allocate and
  87. * re-queue buffers into HTC.
  88. *
  89. * On other OSes, the network stack can call into the driver's OS-specific
  90. * "return_packet" handler and the driver can re-queue these buffers into HTC.
  91. * In this regard a refill callback is unnecessary
  92. */
  93. typedef void (*HTC_EP_RECV_REFILL)(void *, HTC_ENDPOINT_ID Endpoint);
  94. /* Optional per service connection receive buffer allocation callback.
  95. * On some systems packet buffers are an extremely limited resource. Rather than
  96. * queue largest-possible-sized buffers to HTC, some systems would rather
  97. * allocate a specific size as the packet is received. The trade off is
  98. * slightly more processing (callback invoked for each RX packet)
  99. * for the benefit of committing fewer buffer resources into HTC.
  100. *
  101. * The callback is provided the length of the pending packet to fetch. This
  102. * includes the HTC header length plus the length of payload. The callback can
  103. * return a pointer to the allocated HTC packet for immediate use.
  104. *
  105. * Alternatively a variant of this handler can be used to allocate large receive
  106. * packets as needed. For example an application can use the refill mechanism
  107. * for normal packets and the recv-alloc mechanism to handle the case where a
  108. * large packet buffer is required. This can significantly reduce the
  109. * amount of "committed" memory used to receive packets.
  110. */
  111. typedef HTC_PACKET *(*HTC_EP_RECV_ALLOC)(void *,
  112. HTC_ENDPOINT_ID Endpoint,
  113. int Length);
  114. /* Optional per service connection callback to log packet information.
  115. */
  116. typedef void (*HTC_EP_LOG_PKT)(void *, HTC_PACKET *);
  117. enum htc_send_full_action {
  118. /* packet that overflowed should be kept in the queue */
  119. HTC_SEND_FULL_KEEP = 0,
  120. /* packet that overflowed should be dropped */
  121. HTC_SEND_FULL_DROP = 1,
  122. };
  123. /* Optional per service connection callback when a send queue is full. This can
  124. * occur if host continues queueing up TX packets faster than credits can arrive
  125. * To prevent the host (on some Oses like Linux) from continuously queueing pkts
  126. * and consuming resources, this callback is provided so that that the host
  127. * can disable TX in the subsystem (i.e. network stack).
  128. * This callback is invoked for each packet that "overflows" the HTC queue. The
  129. * callback can determine whether the new packet that overflowed the queue can
  130. * be kept (HTC_SEND_FULL_KEEP) or dropped (HTC_SEND_FULL_DROP). If a packet is
  131. * dropped, the EpTxComplete handler will be called and the packet's status
  132. * field will be set to A_NO_RESOURCE.
  133. * Other OSes require a "per-packet" indication for each completed TX packet,
  134. * this closed loop mechanism will prevent the network stack from overunning the
  135. * NIC. The packet to keep or drop is passed for inspection to the registered
  136. * handler the handler must ONLY inspect the packet, it may not free or reclaim
  137. * the packet.
  138. */
  139. typedef enum htc_send_full_action (*HTC_EP_SEND_QUEUE_FULL)(void *,
  140. HTC_PACKET *pPacket);
  141. struct htc_ep_callbacks {
  142. /* context for each callback */
  143. void *pContext;
  144. /* tx completion callback for connected endpoint */
  145. HTC_EP_SEND_PKT_COMPLETE EpTxComplete;
  146. /* receive callback for connected endpoint */
  147. HTC_EP_RECV_PKT EpRecv;
  148. /* OPTIONAL receive re-fill callback for connected endpoint */
  149. HTC_EP_RECV_REFILL EpRecvRefill;
  150. /* OPTIONAL send full callback */
  151. HTC_EP_SEND_QUEUE_FULL EpSendFull;
  152. /* OPTIONAL recv allocation callback */
  153. HTC_EP_RECV_ALLOC EpRecvAlloc;
  154. /* OPTIONAL recv allocation callback based on a threshold */
  155. HTC_EP_RECV_ALLOC EpRecvAllocThresh;
  156. /* OPTIONAL completion handler for multiple complete
  157. * indications (EpTxComplete must be NULL)
  158. */
  159. HTC_EP_SEND_PKT_COMP_MULTIPLE EpTxCompleteMultiple;
  160. HTC_EP_RESUME_TX_QUEUE ep_resume_tx_queue;
  161. HTC_EP_PADDING_CREDIT_UPDATE ep_padding_credit_update;
  162. /* if EpRecvAllocThresh is non-NULL, HTC will compare the
  163. * threshold value to the current recv packet length and invoke
  164. * the EpRecvAllocThresh callback to acquire a packet buffer
  165. */
  166. int RecvAllocThreshold;
  167. /* if a EpRecvRefill handler is provided, this value
  168. * can be used to set a trigger refill callback
  169. * when the recv queue drops below this value
  170. * if set to 0, the refill is only called when packets
  171. * are empty
  172. */
  173. int RecvRefillWaterMark;
  174. /* OPTIONAL callback to log packet information */
  175. HTC_EP_LOG_PKT ep_log_pkt;
  176. };
  177. /* service connection information */
  178. struct htc_service_connect_req {
  179. /* service ID to connect to */
  180. HTC_SERVICE_ID service_id;
  181. /* connection flags, see htc protocol definition */
  182. uint16_t ConnectionFlags;
  183. /* ptr to optional service-specific meta-data */
  184. uint8_t *pMetaData;
  185. /* optional meta data length */
  186. uint8_t MetaDataLength;
  187. /* endpoint callbacks */
  188. struct htc_ep_callbacks EpCallbacks;
  189. /* maximum depth of any send queue */
  190. int MaxSendQueueDepth;
  191. /* HTC flags for the host-side (local) connection */
  192. uint32_t LocalConnectionFlags;
  193. /* override max message size in send direction */
  194. unsigned int MaxSendMsgSize;
  195. };
  196. /* enable send bundle padding for this endpoint */
  197. #define HTC_LOCAL_CONN_FLAGS_ENABLE_SEND_BUNDLE_PADDING (1 << 0)
  198. /* service connection response information */
  199. struct htc_service_connect_resp {
  200. /* caller supplied buffer to optional meta-data */
  201. uint8_t *pMetaData;
  202. /* length of caller supplied buffer */
  203. uint8_t BufferLength;
  204. /* actual length of meta data */
  205. uint8_t ActualLength;
  206. /* endpoint to communicate over */
  207. HTC_ENDPOINT_ID Endpoint;
  208. /* max length of all messages over this endpoint */
  209. unsigned int MaxMsgLength;
  210. /* connect response code from target */
  211. uint8_t ConnectRespCode;
  212. };
  213. /* endpoint distribution structure */
  214. struct htc_endpoint_credit_dist {
  215. struct _htc_endpoint_credit_dist *pNext;
  216. struct _htc_endpoint_credit_dist *pPrev;
  217. /* Service ID (set by HTC) */
  218. HTC_SERVICE_ID service_id;
  219. /* endpoint for this distribution struct (set by HTC) */
  220. HTC_ENDPOINT_ID Endpoint;
  221. /* distribution flags, distribution function can
  222. * set default activity using SET_EP_ACTIVE() macro
  223. */
  224. uint32_t DistFlags;
  225. /* credits for normal operation, anything above this
  226. * indicates the endpoint is over-subscribed, this field
  227. * is only relevant to the credit distribution function
  228. */
  229. int TxCreditsNorm;
  230. /* floor for credit distribution, this field is
  231. * only relevant to the credit distribution function
  232. */
  233. int TxCreditsMin;
  234. /* number of credits assigned to this EP, this field
  235. * is only relevant to the credit dist function
  236. */
  237. int TxCreditsAssigned;
  238. /* current credits available, this field is used by
  239. * HTC to determine whether a message can be sent or
  240. * must be queued
  241. */
  242. int TxCredits;
  243. /* pending credits to distribute on this endpoint, this
  244. * is set by HTC when credit reports arrive.
  245. * The credit distribution functions sets this to zero
  246. * when it distributes the credits
  247. */
  248. int TxCreditsToDist;
  249. /* this is the number of credits that the current pending TX
  250. * packet needs to transmit. This is set by HTC when
  251. * and endpoint needs credits in order to transmit
  252. */
  253. int TxCreditsSeek;
  254. /* size in bytes of each credit (set by HTC) */
  255. int TxCreditSize;
  256. /* credits required for a maximum sized messages (set by HTC) */
  257. int TxCreditsPerMaxMsg;
  258. /* reserved for HTC use */
  259. void *pHTCReserved;
  260. /* current depth of TX queue , i.e. messages waiting for credits
  261. * This field is valid only when HTC_CREDIT_DIST_ACTIVITY_CHANGE
  262. * or HTC_CREDIT_DIST_SEND_COMPLETE is indicated on an endpoint
  263. * that has non-zero credits to recover
  264. */
  265. int TxQueueDepth;
  266. };
  267. #define HTC_EP_ACTIVE ((uint32_t) (1u << 31))
  268. /* macro to check if an endpoint has gone active, useful for credit
  269. * distributions */
  270. #define IS_EP_ACTIVE(epDist) ((epDist)->DistFlags & HTC_EP_ACTIVE)
  271. #define SET_EP_ACTIVE(epDist) (epDist)->DistFlags |= HTC_EP_ACTIVE
  272. /* credit distibution code that is passed into the distrbution function,
  273. * there are mandatory and optional codes that must be handled
  274. */
  275. enum htc_credit_dist_reason {
  276. /* credits available as a result of completed
  277. * send operations (MANDATORY) resulting in credit reports
  278. */
  279. HTC_CREDIT_DIST_SEND_COMPLETE = 0,
  280. /* a change in endpoint activity occurred (OPTIONAL) */
  281. HTC_CREDIT_DIST_ACTIVITY_CHANGE = 1,
  282. /* an endpoint needs to "seek" credits (OPTIONAL) */
  283. HTC_CREDIT_DIST_SEEK_CREDITS,
  284. /* for debugging, dump any state information that is kept by
  285. * the distribution function
  286. */
  287. HTC_DUMP_CREDIT_STATE
  288. };
  289. typedef void (*HTC_CREDIT_DIST_CALLBACK)(void *Context,
  290. struct htc_endpoint_credit_dist *
  291. pEPList,
  292. enum htc_credit_dist_reason
  293. Reason);
  294. typedef void (*HTC_CREDIT_INIT_CALLBACK)(void *Context,
  295. struct htc_endpoint_credit_dist *
  296. pEPList, int TotalCredits);
  297. /* endpoint statistics action */
  298. enum htc_endpoint_stat_action {
  299. /* only read statistics */
  300. HTC_EP_STAT_SAMPLE = 0,
  301. /* sample and immediately clear statistics */
  302. HTC_EP_STAT_SAMPLE_AND_CLEAR = 1,
  303. /* clear only */
  304. HTC_EP_STAT_CLEAR
  305. };
  306. /* endpoint statistics */
  307. struct htc_endpoint_stats {
  308. /* number of TX packets posted to the endpoint */
  309. uint32_t TxPosted;
  310. /* number of times the host set the credit-low flag in a send message on
  311. * this endpoint
  312. */
  313. uint32_t TxCreditLowIndications;
  314. /* running count of total TX packets issued */
  315. uint32_t TxIssued;
  316. /* running count of TX packets that were issued in bundles */
  317. uint32_t TxPacketsBundled;
  318. /* running count of TX bundles that were issued */
  319. uint32_t TxBundles;
  320. /* tx packets that were dropped */
  321. uint32_t TxDropped;
  322. /* running count of total credit reports received for this endpoint */
  323. uint32_t TxCreditRpts;
  324. /* credit reports received from this endpoint's RX packets */
  325. uint32_t TxCreditRptsFromRx;
  326. /* credit reports received from RX packets of other endpoints */
  327. uint32_t TxCreditRptsFromOther;
  328. /* credit reports received from endpoint 0 RX packets */
  329. uint32_t TxCreditRptsFromEp0;
  330. /* count of credits received via Rx packets on this endpoint */
  331. uint32_t TxCreditsFromRx;
  332. /* count of credits received via another endpoint */
  333. uint32_t TxCreditsFromOther;
  334. /* count of credits received via another endpoint */
  335. uint32_t TxCreditsFromEp0;
  336. /* count of consummed credits */
  337. uint32_t TxCreditsConsummed;
  338. /* count of credits returned */
  339. uint32_t TxCreditsReturned;
  340. /* count of RX packets received */
  341. uint32_t RxReceived;
  342. /* count of lookahead records
  343. * found in messages received on this endpoint
  344. */
  345. uint32_t RxLookAheads;
  346. /* count of recv packets received in a bundle */
  347. uint32_t RxPacketsBundled;
  348. /* count of number of bundled lookaheads */
  349. uint32_t RxBundleLookAheads;
  350. /* count of the number of bundle indications from the HTC header */
  351. uint32_t RxBundleIndFromHdr;
  352. /* number of times the recv allocation threshold was hit */
  353. uint32_t RxAllocThreshHit;
  354. /* total number of bytes */
  355. uint32_t RxAllocThreshBytes;
  356. };
  357. /* ------ Function Prototypes ------ */
  358. /**
  359. * htc_create - Create an instance of HTC over the underlying HIF device
  360. * @HifDevice: hif device handle,
  361. * @pInfo: initialization information
  362. * @osdev: QDF device structure
  363. * @con_mode: driver connection mode
  364. *
  365. * Return: HTC_HANDLE on success, NULL on failure
  366. */
  367. HTC_HANDLE htc_create(void *HifDevice, struct htc_init_info *pInfo,
  368. qdf_device_t osdev, uint32_t con_mode);
  369. /**
  370. * htc_get_hif_device - Get the underlying HIF device handle
  371. * @HTCHandle: handle passed into the AddInstance callback
  372. *
  373. * Return: opaque HIF device handle usable in HIF API calls.
  374. */
  375. void *htc_get_hif_device(HTC_HANDLE HTCHandle);
  376. /**
  377. * htc_set_credit_distribution - Set credit distribution parameters
  378. * @HTCHandle: HTC handle
  379. * @pCreditDistCont: caller supplied context to pass into distribution functions
  380. * @CreditDistFunc: Distribution function callback
  381. * @CreditDistInit: Credit Distribution initialization callback
  382. * @ServicePriorityOrder: Array containing list of service IDs, lowest index
  383. * @is highestpriority: ListLength - number of elements in ServicePriorityOrder
  384. *
  385. * The user can set a custom credit distribution function to handle
  386. * special requirementsfor each endpoint. A default credit distribution
  387. * routine can be used by setting CreditInitFunc to NULL. The default
  388. * credit distribution is only provided for simple "fair" credit distribution
  389. * without regard to any prioritization.
  390. * Return: None
  391. */
  392. void htc_set_credit_distribution(HTC_HANDLE HTCHandle,
  393. void *pCreditDistContext,
  394. HTC_CREDIT_DIST_CALLBACK CreditDistFunc,
  395. HTC_CREDIT_INIT_CALLBACK CreditInitFunc,
  396. HTC_SERVICE_ID ServicePriorityOrder[],
  397. int ListLength);
  398. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  399. * Wait for the target to indicate the HTC layer is ready
  400. * htc_wait_target
  401. * @HTCHandle - HTC handle
  402. *
  403. * This API blocks until the target responds with an HTC ready message.
  404. * The caller should not connect services until the target has indicated it is
  405. * ready.
  406. * Return: None
  407. */
  408. QDF_STATUS htc_wait_target(HTC_HANDLE HTCHandle);
  409. /**
  410. * htc_start - Start target service communications
  411. * @HTCHandle - HTC handle
  412. *
  413. * This API indicates to the target that the service connection phase
  414. * is completeand the target can freely start all connected services. This
  415. * API should only be called AFTER all service connections have been made.
  416. * TCStart will issue a SETUP_COMPLETE message to the target to indicate that
  417. * all service connections have been made and the target can start
  418. * communicating over the endpoints.
  419. * Return: None
  420. */
  421. QDF_STATUS htc_start(HTC_HANDLE HTCHandle);
  422. /**
  423. * htc_connect_service - Connect to an HTC service
  424. * @HTCHandle - HTC handle
  425. * @pReq - connection details
  426. * @pResp - connection response
  427. *
  428. * Service connections must be performed before htc_start.
  429. * User provides callback handlersfor various endpoint events.
  430. * Return: None
  431. */
  432. QDF_STATUS htc_connect_service(HTC_HANDLE HTCHandle,
  433. struct htc_service_connect_req *pReq,
  434. struct htc_service_connect_resp *pResp);
  435. /**
  436. * htc_dump - HTC register log dump
  437. * @HTCHandle - HTC handle
  438. * @CmdId - Log command
  439. * @start - start/print logs
  440. *
  441. * Register logs will be started/printed/ be flushed.
  442. * Return: None
  443. */
  444. void htc_dump(HTC_HANDLE HTCHandle, uint8_t CmdId, bool start);
  445. /**
  446. * htc_ce_taklet_debug_dump - Dump ce tasklet rings debug data
  447. * @HTCHandle - HTC handle
  448. *
  449. * Debug logs will be printed.
  450. * Return: None
  451. */
  452. void htc_ce_tasklet_debug_dump(HTC_HANDLE htc_handle);
  453. /**
  454. * htc_send_pkt - Send an HTC packet
  455. * @HTCHandle - HTC handle
  456. * @pPacket - packet to send
  457. *
  458. * Caller must initialize packet using SET_HTC_PACKET_INFO_TX() macro.
  459. * This interface is fully asynchronous. On error, HTC SendPkt will
  460. * call the registered Endpoint callback to cleanup the packet.
  461. * Return: QDF_STATUS_SUCCESS
  462. */
  463. QDF_STATUS htc_send_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket);
  464. /**
  465. * htc_send_data_pkt - Send an HTC packet containing a tx descriptor and data
  466. * @HTCHandle - HTC handle
  467. * @pPacket - packet to send
  468. *
  469. * Caller must initialize packet using SET_HTC_PACKET_INFO_TX() macro.
  470. * Caller must provide headroom in an initial fragment added to the
  471. * network buffer to store a HTC_FRAME_HDR.
  472. * This interface is fully asynchronous. On error, htc_send_data_pkt will
  473. * call the registered Endpoint EpDataTxComplete callback to cleanup
  474. * the packet.
  475. * Return: A_OK
  476. */
  477. #ifdef ATH_11AC_TXCOMPACT
  478. QDF_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, qdf_nbuf_t netbuf,
  479. int Epid, int ActualLength);
  480. #else /*ATH_11AC_TXCOMPACT */
  481. QDF_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket,
  482. uint8_t more_data);
  483. #endif /*ATH_11AC_TXCOMPACT */
  484. /**
  485. * htc_flush_surprise_remove - Flush HTC when target is removed surprisely
  486. * service communications
  487. * @HTCHandle - HTC handle
  488. *
  489. * All receive and pending TX packets will be flushed.
  490. * Return: None
  491. */
  492. void htc_flush_surprise_remove(HTC_HANDLE HTCHandle);
  493. /**
  494. * htc_stop - Stop HTC service communications
  495. * @HTCHandle - HTC handle
  496. *
  497. * HTC communications is halted. All receive and pending TX packets
  498. * will be flushed.
  499. * Return: None
  500. */
  501. void htc_stop(HTC_HANDLE HTCHandle);
  502. /**
  503. * htc_destroy - Destroy HTC service
  504. * @HTCHandle - HTC handle
  505. *
  506. * This cleans up all resources allocated by htc_create().
  507. * Return: None
  508. */
  509. void htc_destroy(HTC_HANDLE HTCHandle);
  510. /**
  511. * htc_flush_endpoint - Flush pending TX packets
  512. * @HTCHandle - HTC handle
  513. * @Endpoint - Endpoint to flush
  514. * @Tag - flush tag
  515. *
  516. * The Tag parameter is used to selectively flush packets with matching
  517. * tags. The value of 0 forces all packets to be flush regardless of tag
  518. * Return: None
  519. */
  520. void htc_flush_endpoint(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint,
  521. HTC_TX_TAG Tag);
  522. /**
  523. * htc_dump_credit_states - Dump credit distribution state
  524. * @HTCHandle - HTC handle
  525. *
  526. * This dumps all credit distribution information to the debugger
  527. * Return: None
  528. */
  529. void htc_dump_credit_states(HTC_HANDLE HTCHandle);
  530. /**
  531. * htc_indicate_activity_change - Indicate a traffic activity change on an
  532. * endpoint
  533. * @HTCHandle - HTC handle
  534. * @Endpoint - endpoint in which activity has changed
  535. * @Active - true if active, false if it has become inactive
  536. *
  537. * This triggers the registered credit distribution function to
  538. * re-adjust credits for active/inactive endpoints.
  539. * Return: None
  540. */
  541. void htc_indicate_activity_change(HTC_HANDLE HTCHandle,
  542. HTC_ENDPOINT_ID Endpoint, bool Active);
  543. /**
  544. * htc_get_endpoint_statistics - Get endpoint statistics
  545. * @HTCHandle - HTC handle
  546. * @Endpoint - Endpoint identifier
  547. * @Action - action to take with statistics
  548. * @pStats - statistics that were sampled (can be NULL if Action is
  549. * HTC_EP_STAT_CLEAR)
  550. *
  551. * Statistics is a compile-time option and this function may return
  552. * false if HTC is not compiled with profiling.
  553. * The caller can specify the statistic "action" to take when sampling
  554. * the statistics. This includes :
  555. * HTC_EP_STAT_SAMPLE : The pStats structure is filled with the current
  556. * values.
  557. * HTC_EP_STAT_SAMPLE_AND_CLEAR : The structure is filled and the current
  558. * statisticsare cleared.
  559. * HTC_EP_STAT_CLEA : the statistics are cleared, the called can pass
  560. * a NULL value for pStats
  561. * Return: true if statistics profiling is enabled, otherwise false.
  562. */
  563. bool htc_get_endpoint_statistics(HTC_HANDLE HTCHandle,
  564. HTC_ENDPOINT_ID Endpoint,
  565. enum htc_endpoint_stat_action Action,
  566. struct htc_endpoint_stats *pStats);
  567. /**
  568. * htc_unblock_recv - Unblock HTC message reception
  569. * @HTCHandle - HTC handle
  570. *
  571. * HTC will block the receiver if the EpRecvAlloc callback fails to provide a
  572. * packet. The caller can use this API to indicate to HTC when resources
  573. * (buffers) are available such that the receiver can be unblocked and HTC
  574. * may re-attempt fetching the pending message.
  575. * This API is not required if the user uses the EpRecvRefill callback or uses
  576. * the HTCAddReceivePacket()API to recycle or provide receive packets to HTC.
  577. * Return: None
  578. */
  579. void htc_unblock_recv(HTC_HANDLE HTCHandle);
  580. /**
  581. * htc_add_receive_pkt_multiple - Add multiple receive packets to HTC
  582. * @HTCHandle - HTC handle
  583. * @pPktQueue - HTC receive packet queue holding packets to add
  584. *
  585. * User must supply HTC packets for capturing incoming HTC frames.
  586. * The caller mmust initialize each HTC packet using the
  587. * SET_HTC_PACKET_INFO_RX_REFILL() macro. The queue must only contain
  588. * recv packets for the same endpoint. Caller supplies a pointer to an
  589. * HTC_PACKET_QUEUE structure holding the recv packet. This API will
  590. * remove the packets from the pkt queue and place them into internal
  591. * recv packet list.
  592. * The caller may allocate the pkt queue on the stack to hold the pkts.
  593. * Return: A_OK on success
  594. */
  595. A_STATUS htc_add_receive_pkt_multiple(HTC_HANDLE HTCHandle,
  596. HTC_PACKET_QUEUE *pPktQueue);
  597. /**
  598. * htc_is_endpoint_active - Check if an endpoint is marked active
  599. * @HTCHandle - HTC handle
  600. * @Endpoint - endpoint to check for active state
  601. *
  602. * Return: returns true if Endpoint is Active
  603. */
  604. bool htc_is_endpoint_active(HTC_HANDLE HTCHandle,
  605. HTC_ENDPOINT_ID Endpoint);
  606. /**
  607. * htc_set_pkt_dbg - Set up debug flag for HTC packets
  608. * @HTCHandle - HTC handle
  609. * @dbg_flag - enable or disable flag
  610. *
  611. * Return: none
  612. */
  613. void htc_set_pkt_dbg(HTC_HANDLE handle, A_BOOL dbg_flag);
  614. /**
  615. * htc_set_nodrop_pkt - Set up nodrop pkt flag for mboxping nodrop pkt
  616. * @HTCHandle - HTC handle
  617. * @isNodropPkt - indicates whether it is nodrop pkt
  618. *
  619. * Return: None
  620. *
  621. */
  622. void htc_set_nodrop_pkt(HTC_HANDLE HTCHandle, A_BOOL isNodropPkt);
  623. /**
  624. * htc_enable_hdr_length_check - Set up htc_hdr_length_check flag
  625. * @HTCHandle - HTC handle
  626. * @htc_hdr_length_check - flag to indicate whether htc header length check is
  627. * required
  628. *
  629. * Return: None
  630. *
  631. */
  632. void
  633. htc_enable_hdr_length_check(HTC_HANDLE htc_handle, bool htc_hdr_length_check);
  634. /**
  635. * htc_get_num_recv_buffers - Get the number of recv buffers currently queued
  636. * into an HTC endpoint
  637. * @HTCHandle - HTC handle
  638. * @Endpoint - endpoint to check
  639. *
  640. * Return: returns number of buffers in queue
  641. *
  642. */
  643. int htc_get_num_recv_buffers(HTC_HANDLE HTCHandle,
  644. HTC_ENDPOINT_ID Endpoint);
  645. /**
  646. * htc_set_target_failure_callback - Set the target failure handling callback
  647. * in HTC layer
  648. * @HTCHandle - HTC handle
  649. * @Callback - target failure handling callback
  650. *
  651. * Return: None
  652. */
  653. void htc_set_target_failure_callback(HTC_HANDLE HTCHandle,
  654. HTC_TARGET_FAILURE Callback);
  655. /* internally used functions for testing... */
  656. void htc_enable_recv(HTC_HANDLE HTCHandle);
  657. void htc_disable_recv(HTC_HANDLE HTCHandle);
  658. A_STATUS HTCWaitForPendingRecv(HTC_HANDLE HTCHandle,
  659. uint32_t TimeoutInMs,
  660. bool *pbIsRecvPending);
  661. /* function to fetch stats from htc layer*/
  662. struct ol_ath_htc_stats *ieee80211_ioctl_get_htc_stats(HTC_HANDLE
  663. HTCHandle);
  664. /**
  665. * htc_get_tx_queue_depth() - get the tx queue depth of an htc endpoint
  666. * @htc_handle: htc handle
  667. * @enpoint_id: endpoint to check
  668. *
  669. * Return: htc_handle tx queue depth
  670. */
  671. int htc_get_tx_queue_depth(HTC_HANDLE htc_handle, HTC_ENDPOINT_ID endpoint_id);
  672. #ifdef WLAN_FEATURE_FASTPATH
  673. void htc_ctrl_msg_cmpl(HTC_HANDLE htc_pdev, HTC_ENDPOINT_ID htc_ep_id);
  674. #define HTC_TX_DESC_FILL(_htc_tx_desc, _download_len, _ep_id, _seq_no) \
  675. do { \
  676. HTC_WRITE32((_htc_tx_desc), \
  677. SM((_download_len), HTC_FRAME_HDR_PAYLOADLEN) | \
  678. SM((_ep_id), HTC_FRAME_HDR_ENDPOINTID)); \
  679. HTC_WRITE32((uint32_t *)(_htc_tx_desc) + 1, \
  680. SM((_seq_no), HTC_FRAME_HDR_CONTROLBYTES1)); \
  681. } while (0)
  682. #endif /* WLAN_FEATURE_FASTPATH */
  683. #ifdef __cplusplus
  684. }
  685. #endif
  686. void htc_get_control_endpoint_tx_host_credits(HTC_HANDLE HTCHandle,
  687. int *credit);
  688. void htc_dump_counter_info(HTC_HANDLE HTCHandle);
  689. void *htc_get_targetdef(HTC_HANDLE htc_handle);
  690. #ifdef FEATURE_RUNTIME_PM
  691. int htc_runtime_suspend(HTC_HANDLE htc_ctx);
  692. int htc_runtime_resume(HTC_HANDLE htc_ctx);
  693. #endif
  694. void htc_global_credit_flow_disable(void);
  695. void htc_global_credit_flow_enable(void);
  696. /* Disable ASPM : Disable PCIe low power */
  697. bool htc_can_suspend_link(HTC_HANDLE HTCHandle);
  698. void htc_vote_link_down(HTC_HANDLE HTCHandle);
  699. void htc_vote_link_up(HTC_HANDLE HTCHandle);
  700. #ifdef IPA_OFFLOAD
  701. void htc_ipa_get_ce_resource(HTC_HANDLE htc_handle,
  702. qdf_shared_mem_t **ce_sr,
  703. uint32_t *ce_sr_ring_size,
  704. qdf_dma_addr_t *ce_reg_paddr);
  705. #else
  706. #define htc_ipa_get_ce_resource(htc_handle, \
  707. ce_sr, ce_sr_ring_size, ce_reg_paddr) /* NO-OP */
  708. #endif /* IPA_OFFLOAD */
  709. #if defined(DEBUG_HL_LOGGING) && defined(CONFIG_HL_SUPPORT)
  710. /**
  711. * htc_dump_bundle_stats() - dump tx and rx htc message bundle stats
  712. * @HTCHandle: htc handle
  713. *
  714. * Return: None
  715. */
  716. void htc_dump_bundle_stats(HTC_HANDLE HTCHandle);
  717. /**
  718. * htc_clear_bundle_stats() - clear tx and rx htc message bundle stats
  719. * @HTCHandle: htc handle
  720. *
  721. * Return: None
  722. */
  723. void htc_clear_bundle_stats(HTC_HANDLE HTCHandle);
  724. #endif
  725. #ifdef FEATURE_RUNTIME_PM
  726. int htc_pm_runtime_get(HTC_HANDLE htc_handle);
  727. int htc_pm_runtime_put(HTC_HANDLE htc_handle);
  728. /**
  729. * htc_dec_return_runtime_cnt: Decrement htc runtime count
  730. * @htc: HTC handle
  731. *
  732. * Return: value of runtime count after decrement
  733. */
  734. int32_t htc_dec_return_runtime_cnt(HTC_HANDLE htc);
  735. #else
  736. static inline int htc_pm_runtime_get(HTC_HANDLE htc_handle) { return 0; }
  737. static inline int htc_pm_runtime_put(HTC_HANDLE htc_handle) { return 0; }
  738. static inline
  739. int32_t htc_dec_return_runtime_cnt(HTC_HANDLE htc)
  740. {
  741. return -1;
  742. }
  743. #endif
  744. /**
  745. * htc_set_async_ep() - set async HTC end point
  746. * user should call this function after htc_connect_service before
  747. * queing any packets to end point
  748. * @HTCHandle: htc handle
  749. * @HTC_ENDPOINT_ID: end point id
  750. * @value: true or false
  751. *
  752. * Return: None
  753. */
  754. void htc_set_async_ep(HTC_HANDLE HTCHandle,
  755. HTC_ENDPOINT_ID htc_ep_id, bool value);
  756. /**
  757. * htc_set_wmi_endpoint_count: Set number of WMI endpoint
  758. * @htc_handle: HTC handle
  759. * @wmi_ep_count: WMI enpoint count
  760. *
  761. * return: None
  762. */
  763. void htc_set_wmi_endpoint_count(HTC_HANDLE htc_handle, uint8_t wmi_ep_count);
  764. /**
  765. * htc_get_wmi_endpoint_count: Get number of WMI endpoint
  766. * @htc_handle: HTC handle
  767. *
  768. * return: WMI enpoint count
  769. */
  770. uint8_t htc_get_wmi_endpoint_count(HTC_HANDLE htc_handle);
  771. /**
  772. * htc_print_credit_history: print HTC credit history in buffer
  773. * @htc: HTC handle
  774. * @count: Number of lines to be copied
  775. * @print: Print callback to print in the buffer
  776. * @print_priv: any data required by the print method, e.g. a file handle
  777. *
  778. * return: None
  779. */
  780. #ifdef FEATURE_HTC_CREDIT_HISTORY
  781. void htc_print_credit_history(HTC_HANDLE htc, uint32_t count,
  782. qdf_abstract_print * print, void *print_priv);
  783. #else
  784. static inline
  785. void htc_print_credit_history(HTC_HANDLE htc, uint32_t count,
  786. qdf_abstract_print *print, void *print_priv)
  787. {
  788. print(print_priv, "HTC Credit History Feature is disabled");
  789. }
  790. #endif
  791. #ifdef SYSTEM_PM_CHECK
  792. /**
  793. * htc_system_resume() - Send out any pending WMI/HTT
  794. * messages pending in htc queues on system resume.
  795. * @htc: HTC handle
  796. *
  797. * Return: None
  798. */
  799. void htc_system_resume(HTC_HANDLE htc);
  800. #else
  801. static inline void htc_system_resume(HTC_HANDLE htc)
  802. {
  803. }
  804. #endif
  805. #endif /* _HTC_API_H_ */