htc_api.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948
  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. /**
  358. * htc_link_vote_user_id - user ids for each link vote type
  359. * @HTC_LINK_VOTE_INVALID_MIN_USER_ID: min user id
  360. * @HTC_LINK_VOTE_SAP_USER_ID: sap user id
  361. * @HTC_LINK_VOTE_GO_USER_ID: go user id
  362. * @HTC_LINK_VOTE_NDP_USER_ID: ndp user id
  363. * @HTC_LINK_VOTE_SAP_DFS_USER_ID: sap dfs user id
  364. * @HTC_LINK_VOTE_STA_USER_ID: sta user id
  365. * @HTC_LINK_VOTE_INVALID_MAX_USER_ID: max user id
  366. */
  367. enum htc_link_vote_user_id {
  368. HTC_LINK_VOTE_INVALID_MIN_USER_ID = 0,
  369. HTC_LINK_VOTE_SAP_USER_ID = 1,
  370. HTC_LINK_VOTE_GO_USER_ID = 2,
  371. HTC_LINK_VOTE_NDP_USER_ID = 3,
  372. HTC_LINK_VOTE_SAP_DFS_USER_ID = 4,
  373. HTC_LINK_VOTE_STA_USER_ID = 5,
  374. HTC_LINK_VOTE_INVALID_MAX_USER_ID
  375. };
  376. /* ------ Function Prototypes ------ */
  377. /**
  378. * htc_create - Create an instance of HTC over the underlying HIF device
  379. * @HifDevice: hif device handle,
  380. * @pInfo: initialization information
  381. * @osdev: QDF device structure
  382. * @con_mode: driver connection mode
  383. *
  384. * Return: HTC_HANDLE on success, NULL on failure
  385. */
  386. HTC_HANDLE htc_create(void *HifDevice, struct htc_init_info *pInfo,
  387. qdf_device_t osdev, uint32_t con_mode);
  388. /**
  389. * htc_get_hif_device - Get the underlying HIF device handle
  390. * @HTCHandle: handle passed into the AddInstance callback
  391. *
  392. * Return: opaque HIF device handle usable in HIF API calls.
  393. */
  394. void *htc_get_hif_device(HTC_HANDLE HTCHandle);
  395. /**
  396. * htc_set_credit_distribution - Set credit distribution parameters
  397. * @HTCHandle: HTC handle
  398. * @pCreditDistCont: caller supplied context to pass into distribution functions
  399. * @CreditDistFunc: Distribution function callback
  400. * @CreditDistInit: Credit Distribution initialization callback
  401. * @ServicePriorityOrder: Array containing list of service IDs, lowest index
  402. * @is highestpriority: ListLength - number of elements in ServicePriorityOrder
  403. *
  404. * The user can set a custom credit distribution function to handle
  405. * special requirementsfor each endpoint. A default credit distribution
  406. * routine can be used by setting CreditInitFunc to NULL. The default
  407. * credit distribution is only provided for simple "fair" credit distribution
  408. * without regard to any prioritization.
  409. * Return: None
  410. */
  411. void htc_set_credit_distribution(HTC_HANDLE HTCHandle,
  412. void *pCreditDistContext,
  413. HTC_CREDIT_DIST_CALLBACK CreditDistFunc,
  414. HTC_CREDIT_INIT_CALLBACK CreditInitFunc,
  415. HTC_SERVICE_ID ServicePriorityOrder[],
  416. int ListLength);
  417. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  418. * Wait for the target to indicate the HTC layer is ready
  419. * htc_wait_target
  420. * @HTCHandle - HTC handle
  421. *
  422. * This API blocks until the target responds with an HTC ready message.
  423. * The caller should not connect services until the target has indicated it is
  424. * ready.
  425. * Return: None
  426. */
  427. QDF_STATUS htc_wait_target(HTC_HANDLE HTCHandle);
  428. /**
  429. * htc_start - Start target service communications
  430. * @HTCHandle - HTC handle
  431. *
  432. * This API indicates to the target that the service connection phase
  433. * is completeand the target can freely start all connected services. This
  434. * API should only be called AFTER all service connections have been made.
  435. * TCStart will issue a SETUP_COMPLETE message to the target to indicate that
  436. * all service connections have been made and the target can start
  437. * communicating over the endpoints.
  438. * Return: None
  439. */
  440. QDF_STATUS htc_start(HTC_HANDLE HTCHandle);
  441. /**
  442. * htc_connect_service - Connect to an HTC service
  443. * @HTCHandle - HTC handle
  444. * @pReq - connection details
  445. * @pResp - connection response
  446. *
  447. * Service connections must be performed before htc_start.
  448. * User provides callback handlersfor various endpoint events.
  449. * Return: None
  450. */
  451. QDF_STATUS htc_connect_service(HTC_HANDLE HTCHandle,
  452. struct htc_service_connect_req *pReq,
  453. struct htc_service_connect_resp *pResp);
  454. /**
  455. * htc_dump - HTC register log dump
  456. * @HTCHandle - HTC handle
  457. * @CmdId - Log command
  458. * @start - start/print logs
  459. *
  460. * Register logs will be started/printed/ be flushed.
  461. * Return: None
  462. */
  463. void htc_dump(HTC_HANDLE HTCHandle, uint8_t CmdId, bool start);
  464. /**
  465. * htc_ce_taklet_debug_dump - Dump ce tasklet rings debug data
  466. * @HTCHandle - HTC handle
  467. *
  468. * Debug logs will be printed.
  469. * Return: None
  470. */
  471. void htc_ce_tasklet_debug_dump(HTC_HANDLE htc_handle);
  472. /**
  473. * htc_send_pkt - Send an HTC packet
  474. * @HTCHandle - HTC handle
  475. * @pPacket - packet to send
  476. *
  477. * Caller must initialize packet using SET_HTC_PACKET_INFO_TX() macro.
  478. * This interface is fully asynchronous. On error, HTC SendPkt will
  479. * call the registered Endpoint callback to cleanup the packet.
  480. * Return: QDF_STATUS_SUCCESS
  481. */
  482. QDF_STATUS htc_send_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket);
  483. /**
  484. * htc_send_data_pkt - Send an HTC packet containing a tx descriptor and data
  485. * @HTCHandle - HTC handle
  486. * @pPacket - packet to send
  487. *
  488. * Caller must initialize packet using SET_HTC_PACKET_INFO_TX() macro.
  489. * Caller must provide headroom in an initial fragment added to the
  490. * network buffer to store a HTC_FRAME_HDR.
  491. * This interface is fully asynchronous. On error, htc_send_data_pkt will
  492. * call the registered Endpoint EpDataTxComplete callback to cleanup
  493. * the packet.
  494. * Return: A_OK
  495. */
  496. #ifdef ATH_11AC_TXCOMPACT
  497. QDF_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, qdf_nbuf_t netbuf,
  498. int Epid, int ActualLength);
  499. #else /*ATH_11AC_TXCOMPACT */
  500. QDF_STATUS htc_send_data_pkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket,
  501. uint8_t more_data);
  502. #endif /*ATH_11AC_TXCOMPACT */
  503. /**
  504. * htc_flush_surprise_remove - Flush HTC when target is removed surprisely
  505. * service communications
  506. * @HTCHandle - HTC handle
  507. *
  508. * All receive and pending TX packets will be flushed.
  509. * Return: None
  510. */
  511. void htc_flush_surprise_remove(HTC_HANDLE HTCHandle);
  512. /**
  513. * htc_stop - Stop HTC service communications
  514. * @HTCHandle - HTC handle
  515. *
  516. * HTC communications is halted. All receive and pending TX packets
  517. * will be flushed.
  518. * Return: None
  519. */
  520. void htc_stop(HTC_HANDLE HTCHandle);
  521. /**
  522. * htc_destroy - Destroy HTC service
  523. * @HTCHandle - HTC handle
  524. *
  525. * This cleans up all resources allocated by htc_create().
  526. * Return: None
  527. */
  528. void htc_destroy(HTC_HANDLE HTCHandle);
  529. /**
  530. * htc_flush_endpoint - Flush pending TX packets
  531. * @HTCHandle - HTC handle
  532. * @Endpoint - Endpoint to flush
  533. * @Tag - flush tag
  534. *
  535. * The Tag parameter is used to selectively flush packets with matching
  536. * tags. The value of 0 forces all packets to be flush regardless of tag
  537. * Return: None
  538. */
  539. void htc_flush_endpoint(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint,
  540. HTC_TX_TAG Tag);
  541. /**
  542. * htc_dump_credit_states - Dump credit distribution state
  543. * @HTCHandle - HTC handle
  544. *
  545. * This dumps all credit distribution information to the debugger
  546. * Return: None
  547. */
  548. void htc_dump_credit_states(HTC_HANDLE HTCHandle);
  549. /**
  550. * htc_indicate_activity_change - Indicate a traffic activity change on an
  551. * endpoint
  552. * @HTCHandle - HTC handle
  553. * @Endpoint - endpoint in which activity has changed
  554. * @Active - true if active, false if it has become inactive
  555. *
  556. * This triggers the registered credit distribution function to
  557. * re-adjust credits for active/inactive endpoints.
  558. * Return: None
  559. */
  560. void htc_indicate_activity_change(HTC_HANDLE HTCHandle,
  561. HTC_ENDPOINT_ID Endpoint, bool Active);
  562. /**
  563. * htc_get_endpoint_statistics - Get endpoint statistics
  564. * @HTCHandle - HTC handle
  565. * @Endpoint - Endpoint identifier
  566. * @Action - action to take with statistics
  567. * @pStats - statistics that were sampled (can be NULL if Action is
  568. * HTC_EP_STAT_CLEAR)
  569. *
  570. * Statistics is a compile-time option and this function may return
  571. * false if HTC is not compiled with profiling.
  572. * The caller can specify the statistic "action" to take when sampling
  573. * the statistics. This includes :
  574. * HTC_EP_STAT_SAMPLE : The pStats structure is filled with the current
  575. * values.
  576. * HTC_EP_STAT_SAMPLE_AND_CLEAR : The structure is filled and the current
  577. * statisticsare cleared.
  578. * HTC_EP_STAT_CLEA : the statistics are cleared, the called can pass
  579. * a NULL value for pStats
  580. * Return: true if statistics profiling is enabled, otherwise false.
  581. */
  582. bool htc_get_endpoint_statistics(HTC_HANDLE HTCHandle,
  583. HTC_ENDPOINT_ID Endpoint,
  584. enum htc_endpoint_stat_action Action,
  585. struct htc_endpoint_stats *pStats);
  586. /**
  587. * htc_unblock_recv - Unblock HTC message reception
  588. * @HTCHandle - HTC handle
  589. *
  590. * HTC will block the receiver if the EpRecvAlloc callback fails to provide a
  591. * packet. The caller can use this API to indicate to HTC when resources
  592. * (buffers) are available such that the receiver can be unblocked and HTC
  593. * may re-attempt fetching the pending message.
  594. * This API is not required if the user uses the EpRecvRefill callback or uses
  595. * the HTCAddReceivePacket()API to recycle or provide receive packets to HTC.
  596. * Return: None
  597. */
  598. void htc_unblock_recv(HTC_HANDLE HTCHandle);
  599. /**
  600. * htc_add_receive_pkt_multiple - Add multiple receive packets to HTC
  601. * @HTCHandle - HTC handle
  602. * @pPktQueue - HTC receive packet queue holding packets to add
  603. *
  604. * User must supply HTC packets for capturing incoming HTC frames.
  605. * The caller mmust initialize each HTC packet using the
  606. * SET_HTC_PACKET_INFO_RX_REFILL() macro. The queue must only contain
  607. * recv packets for the same endpoint. Caller supplies a pointer to an
  608. * HTC_PACKET_QUEUE structure holding the recv packet. This API will
  609. * remove the packets from the pkt queue and place them into internal
  610. * recv packet list.
  611. * The caller may allocate the pkt queue on the stack to hold the pkts.
  612. * Return: A_OK on success
  613. */
  614. A_STATUS htc_add_receive_pkt_multiple(HTC_HANDLE HTCHandle,
  615. HTC_PACKET_QUEUE *pPktQueue);
  616. /**
  617. * htc_is_endpoint_active - Check if an endpoint is marked active
  618. * @HTCHandle - HTC handle
  619. * @Endpoint - endpoint to check for active state
  620. *
  621. * Return: returns true if Endpoint is Active
  622. */
  623. bool htc_is_endpoint_active(HTC_HANDLE HTCHandle,
  624. HTC_ENDPOINT_ID Endpoint);
  625. /**
  626. * htc_set_pkt_dbg - Set up debug flag for HTC packets
  627. * @HTCHandle - HTC handle
  628. * @dbg_flag - enable or disable flag
  629. *
  630. * Return: none
  631. */
  632. void htc_set_pkt_dbg(HTC_HANDLE handle, A_BOOL dbg_flag);
  633. /**
  634. * htc_set_nodrop_pkt - Set up nodrop pkt flag for mboxping nodrop pkt
  635. * @HTCHandle - HTC handle
  636. * @isNodropPkt - indicates whether it is nodrop pkt
  637. *
  638. * Return: None
  639. *
  640. */
  641. void htc_set_nodrop_pkt(HTC_HANDLE HTCHandle, A_BOOL isNodropPkt);
  642. /**
  643. * htc_enable_hdr_length_check - Set up htc_hdr_length_check flag
  644. * @HTCHandle - HTC handle
  645. * @htc_hdr_length_check - flag to indicate whether htc header length check is
  646. * required
  647. *
  648. * Return: None
  649. *
  650. */
  651. void
  652. htc_enable_hdr_length_check(HTC_HANDLE htc_handle, bool htc_hdr_length_check);
  653. /**
  654. * htc_get_num_recv_buffers - Get the number of recv buffers currently queued
  655. * into an HTC endpoint
  656. * @HTCHandle - HTC handle
  657. * @Endpoint - endpoint to check
  658. *
  659. * Return: returns number of buffers in queue
  660. *
  661. */
  662. int htc_get_num_recv_buffers(HTC_HANDLE HTCHandle,
  663. HTC_ENDPOINT_ID Endpoint);
  664. /**
  665. * htc_set_target_failure_callback - Set the target failure handling callback
  666. * in HTC layer
  667. * @HTCHandle - HTC handle
  668. * @Callback - target failure handling callback
  669. *
  670. * Return: None
  671. */
  672. void htc_set_target_failure_callback(HTC_HANDLE HTCHandle,
  673. HTC_TARGET_FAILURE Callback);
  674. /* internally used functions for testing... */
  675. void htc_enable_recv(HTC_HANDLE HTCHandle);
  676. void htc_disable_recv(HTC_HANDLE HTCHandle);
  677. A_STATUS HTCWaitForPendingRecv(HTC_HANDLE HTCHandle,
  678. uint32_t TimeoutInMs,
  679. bool *pbIsRecvPending);
  680. /* function to fetch stats from htc layer*/
  681. struct ol_ath_htc_stats *ieee80211_ioctl_get_htc_stats(HTC_HANDLE
  682. HTCHandle);
  683. /**
  684. * htc_get_tx_queue_depth() - get the tx queue depth of an htc endpoint
  685. * @htc_handle: htc handle
  686. * @enpoint_id: endpoint to check
  687. *
  688. * Return: htc_handle tx queue depth
  689. */
  690. int htc_get_tx_queue_depth(HTC_HANDLE htc_handle, HTC_ENDPOINT_ID endpoint_id);
  691. #ifdef WLAN_FEATURE_FASTPATH
  692. void htc_ctrl_msg_cmpl(HTC_HANDLE htc_pdev, HTC_ENDPOINT_ID htc_ep_id);
  693. #define HTC_TX_DESC_FILL(_htc_tx_desc, _download_len, _ep_id, _seq_no) \
  694. do { \
  695. HTC_WRITE32((_htc_tx_desc), \
  696. SM((_download_len), HTC_FRAME_HDR_PAYLOADLEN) | \
  697. SM((_ep_id), HTC_FRAME_HDR_ENDPOINTID)); \
  698. HTC_WRITE32((uint32_t *)(_htc_tx_desc) + 1, \
  699. SM((_seq_no), HTC_FRAME_HDR_CONTROLBYTES1)); \
  700. } while (0)
  701. #endif /* WLAN_FEATURE_FASTPATH */
  702. #ifdef __cplusplus
  703. }
  704. #endif
  705. void htc_get_control_endpoint_tx_host_credits(HTC_HANDLE HTCHandle,
  706. int *credit);
  707. void htc_dump_counter_info(HTC_HANDLE HTCHandle);
  708. void *htc_get_targetdef(HTC_HANDLE htc_handle);
  709. #ifdef FEATURE_RUNTIME_PM
  710. int htc_runtime_suspend(HTC_HANDLE htc_ctx);
  711. int htc_runtime_resume(HTC_HANDLE htc_ctx);
  712. #endif
  713. void htc_global_credit_flow_disable(void);
  714. void htc_global_credit_flow_enable(void);
  715. /* Disable ASPM : Disable PCIe low power */
  716. bool htc_can_suspend_link(HTC_HANDLE HTCHandle);
  717. #ifdef IPA_OFFLOAD
  718. void htc_ipa_get_ce_resource(HTC_HANDLE htc_handle,
  719. qdf_shared_mem_t **ce_sr,
  720. uint32_t *ce_sr_ring_size,
  721. qdf_dma_addr_t *ce_reg_paddr);
  722. #else
  723. #define htc_ipa_get_ce_resource(htc_handle, \
  724. ce_sr, ce_sr_ring_size, ce_reg_paddr) /* NO-OP */
  725. #endif /* IPA_OFFLOAD */
  726. #if defined(DEBUG_HL_LOGGING) && defined(CONFIG_HL_SUPPORT)
  727. /**
  728. * htc_dump_bundle_stats() - dump tx and rx htc message bundle stats
  729. * @HTCHandle: htc handle
  730. *
  731. * Return: None
  732. */
  733. void htc_dump_bundle_stats(HTC_HANDLE HTCHandle);
  734. /**
  735. * htc_clear_bundle_stats() - clear tx and rx htc message bundle stats
  736. * @HTCHandle: htc handle
  737. *
  738. * Return: None
  739. */
  740. void htc_clear_bundle_stats(HTC_HANDLE HTCHandle);
  741. #endif
  742. #ifdef FEATURE_RUNTIME_PM
  743. int htc_pm_runtime_get(HTC_HANDLE htc_handle);
  744. int htc_pm_runtime_put(HTC_HANDLE htc_handle);
  745. /**
  746. * htc_dec_return_runtime_cnt: Decrement htc runtime count
  747. * @htc: HTC handle
  748. *
  749. * Return: value of runtime count after decrement
  750. */
  751. int32_t htc_dec_return_runtime_cnt(HTC_HANDLE htc);
  752. #else
  753. static inline int htc_pm_runtime_get(HTC_HANDLE htc_handle) { return 0; }
  754. static inline int htc_pm_runtime_put(HTC_HANDLE htc_handle) { return 0; }
  755. static inline
  756. int32_t htc_dec_return_runtime_cnt(HTC_HANDLE htc)
  757. {
  758. return -1;
  759. }
  760. #endif
  761. #ifdef WLAN_DEBUG_LINK_VOTE
  762. /**
  763. * htc_log_link_user_votes - API to log link user votes
  764. *
  765. * API to log the link user votes
  766. *
  767. * Return: void
  768. */
  769. void htc_log_link_user_votes(void);
  770. /**
  771. * htc_vote_link_down - API to vote for link down
  772. * @htc_handle: HTC handle
  773. * @id: PCIe link vote user id
  774. *
  775. * API for upper layers to call HIF to vote for link down
  776. *
  777. * Return: void
  778. */
  779. void htc_vote_link_down(HTC_HANDLE htc_handle, enum htc_link_vote_user_id id);
  780. /**
  781. * htc_vote_link_up - API to vote for link up
  782. * @htc_handle: HTC Handle
  783. * @id: PCIe link vote user id
  784. *
  785. * API for upper layers to call HIF to vote for link up
  786. *
  787. * Return: void
  788. */
  789. void htc_vote_link_up(HTC_HANDLE htc_handle, enum htc_link_vote_user_id id);
  790. #else
  791. static inline
  792. void htc_log_link_user_votes(void)
  793. {
  794. }
  795. static inline
  796. void htc_vote_link_down(HTC_HANDLE htc_handle, enum htc_link_vote_user_id id)
  797. {
  798. }
  799. static inline
  800. void htc_vote_link_up(HTC_HANDLE htc_handle, enum htc_link_vote_user_id id)
  801. {
  802. }
  803. #endif
  804. /**
  805. * htc_set_async_ep() - set async HTC end point
  806. * user should call this function after htc_connect_service before
  807. * queing any packets to end point
  808. * @HTCHandle: htc handle
  809. * @HTC_ENDPOINT_ID: end point id
  810. * @value: true or false
  811. *
  812. * Return: None
  813. */
  814. void htc_set_async_ep(HTC_HANDLE HTCHandle,
  815. HTC_ENDPOINT_ID htc_ep_id, bool value);
  816. /**
  817. * htc_set_wmi_endpoint_count: Set number of WMI endpoint
  818. * @htc_handle: HTC handle
  819. * @wmi_ep_count: WMI enpoint count
  820. *
  821. * return: None
  822. */
  823. void htc_set_wmi_endpoint_count(HTC_HANDLE htc_handle, uint8_t wmi_ep_count);
  824. /**
  825. * htc_get_wmi_endpoint_count: Get number of WMI endpoint
  826. * @htc_handle: HTC handle
  827. *
  828. * return: WMI enpoint count
  829. */
  830. uint8_t htc_get_wmi_endpoint_count(HTC_HANDLE htc_handle);
  831. /**
  832. * htc_print_credit_history: print HTC credit history in buffer
  833. * @htc: HTC handle
  834. * @count: Number of lines to be copied
  835. * @print: Print callback to print in the buffer
  836. * @print_priv: any data required by the print method, e.g. a file handle
  837. *
  838. * return: None
  839. */
  840. #ifdef FEATURE_HTC_CREDIT_HISTORY
  841. void htc_print_credit_history(HTC_HANDLE htc, uint32_t count,
  842. qdf_abstract_print * print, void *print_priv);
  843. #else
  844. static inline
  845. void htc_print_credit_history(HTC_HANDLE htc, uint32_t count,
  846. qdf_abstract_print *print, void *print_priv)
  847. {
  848. print(print_priv, "HTC Credit History Feature is disabled");
  849. }
  850. #endif
  851. #ifdef SYSTEM_PM_CHECK
  852. /**
  853. * htc_system_resume() - Send out any pending WMI/HTT
  854. * messages pending in htc queues on system resume.
  855. * @htc: HTC handle
  856. *
  857. * Return: None
  858. */
  859. void htc_system_resume(HTC_HANDLE htc);
  860. #else
  861. static inline void htc_system_resume(HTC_HANDLE htc)
  862. {
  863. }
  864. #endif
  865. #endif /* _HTC_API_H_ */