htc_api.h 35 KB

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