123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460 |
- //------------------------------------------------------------------------------
- // <copyright file="htc_api.h" company="Atheros">
- // Copyright (c) 2007-2008 Atheros Corporation. All rights reserved.
- //
- // This program is free software; you can redistribute it and/or modify
- // it under the terms of the GNU General Public License version 2 as
- // published by the Free Software Foundation;
- //
- // Software distributed under the License is distributed on an "AS
- // IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- // implied. See the License for the specific language governing
- // rights and limitations under the License.
- //
- //
- //------------------------------------------------------------------------------
- //==============================================================================
- // Author(s): ="Atheros"
- //==============================================================================
- #ifndef _HTC_API_H_
- #define _HTC_API_H_
- #include <htc.h>
- #include <htc_services.h>
- #include "htc_packet.h"
- #ifdef __cplusplus
- extern "C" {
- #endif /* __cplusplus */
- /* TODO.. for BMI */
- #define ENDPOINT1 0
- // TODO -remove me, but we have to fix BMI first
- #define HTC_MAILBOX_NUM_MAX 4
- /* this is the amount of header room required by users of HTC */
- #define HTC_HEADER_LEN HTC_HDR_LENGTH
- typedef void *HTC_HANDLE;
- typedef A_UINT16 HTC_SERVICE_ID;
- typedef struct _HTC_INIT_INFO {
- void *pContext; /* context for target failure notification */
- void (*TargetFailure)(void *Instance, A_STATUS Status);
- } HTC_INIT_INFO;
- /* per service connection send completion */
- typedef void (*HTC_EP_SEND_PKT_COMPLETE)(void *,HTC_PACKET *);
- /* per service connection pkt received */
- typedef void (*HTC_EP_RECV_PKT)(void *,HTC_PACKET *);
- /* Optional per service connection receive buffer re-fill callback,
- * Packets are allocated from a global pool and indicated up
- * to the network stack. The driver never gets the packets back from the stack. So
- * refill callback can be used to allocate and re-queue buffers into HTC.
- *
- * On other cases,, the network stack can call into the driver's specifc "return_packet" handler and
- * the driver can re-queue these buffers into HTC. In this regard a refill callback is
- * unnecessary */
- typedef void (*HTC_EP_RECV_REFILL)(void *, HTC_ENDPOINT_ID Endpoint);
- /* Optional per service connection receive buffer allocation callback.
- * On some systems packet buffers are an extremely limited resource. Rather than
- * queue largest-possible-sized buffers to HTC, some systems would rather
- * allocate a specific size as the packet is received. The trade off is
- * slightly more processing (callback invoked for each RX packet)
- * for the benefit of committing fewer buffer resources into HTC.
- *
- * The callback is provided the length of the pending packet to fetch. This includes the
- * HTC header length plus the length of payload. The callback can return a pointer to
- * the allocated HTC packet for immediate use.
- *
- * NOTE*** This callback is mutually exclusive with the the refill callback above.
- *
- * */
- typedef HTC_PACKET *(*HTC_EP_RECV_ALLOC)(void *, HTC_ENDPOINT_ID Endpoint, int Length);
- typedef enum _HTC_SEND_FULL_ACTION {
- HTC_SEND_FULL_KEEP = 0, /* packet that overflowed should be kept in the queue */
- HTC_SEND_FULL_DROP = 1, /* packet that overflowed should be dropped */
- } HTC_SEND_FULL_ACTION;
- /* Optional per service connection callback when a send queue is full. This can occur if the
- * host continues queueing up TX packets faster than credits can arrive
- * To prevent the host from continuously queueing packets
- * and consuming resources, this callback is provided so that that the host
- * can disable TX in the subsystem (i.e. network stack).
- * This callback is invoked for each packet that "overflows" the HTC queue. The callback can
- * determine whether the new packet that overflowed the queue can be kept (HTC_SEND_FULL_KEEP) or
- * dropped (HTC_SEND_FULL_DROP). If a packet is dropped, the EpTxComplete handler will be called
- * and the packet's status field will be set to A_NO_RESOURCE.
- * In other cases, "per-packet" indication for each completed TX packet, this
- * closed loop mechanism will prevent the network stack from overunning the NIC
- * The packet to keep or drop is passed for inspection to the registered handler the handler
- * must ONLY inspect the packet, it may not free or reclaim the packet. */
- typedef HTC_SEND_FULL_ACTION (*HTC_EP_SEND_QUEUE_FULL)(void *, HTC_PACKET *pPacket);
- typedef struct _HTC_EP_CALLBACKS {
- void *pContext; /* context for each callback */
- HTC_EP_SEND_PKT_COMPLETE EpTxComplete; /* tx completion callback for connected endpoint */
- HTC_EP_RECV_PKT EpRecv; /* receive callback for connected endpoint */
- HTC_EP_RECV_REFILL EpRecvRefill; /* OPTIONAL receive re-fill callback for connected endpoint */
- HTC_EP_SEND_QUEUE_FULL EpSendFull; /* OPTIONAL send full callback */
- HTC_EP_RECV_ALLOC EpRecvAlloc; /* OPTIONAL recv allocation callback */
- } HTC_EP_CALLBACKS;
- /* service connection information */
- typedef struct _HTC_SERVICE_CONNECT_REQ {
- HTC_SERVICE_ID ServiceID; /* service ID to connect to */
- A_UINT16 ConnectionFlags; /* connection flags, see htc protocol definition */
- A_UINT8 *pMetaData; /* ptr to optional service-specific meta-data */
- A_UINT8 MetaDataLength; /* optional meta data length */
- HTC_EP_CALLBACKS EpCallbacks; /* endpoint callbacks */
- int MaxSendQueueDepth; /* maximum depth of any send queue */
- } HTC_SERVICE_CONNECT_REQ;
- /* service connection response information */
- typedef struct _HTC_SERVICE_CONNECT_RESP {
- A_UINT8 *pMetaData; /* caller supplied buffer to optional meta-data */
- A_UINT8 BufferLength; /* length of caller supplied buffer */
- A_UINT8 ActualLength; /* actual length of meta data */
- HTC_ENDPOINT_ID Endpoint; /* endpoint to communicate over */
- int MaxMsgLength; /* max length of all messages over this endpoint */
- A_UINT8 ConnectRespCode; /* connect response code from target */
- } HTC_SERVICE_CONNECT_RESP;
- /* endpoint distribution structure */
- typedef struct _HTC_ENDPOINT_CREDIT_DIST {
- struct _HTC_ENDPOINT_CREDIT_DIST *pNext;
- struct _HTC_ENDPOINT_CREDIT_DIST *pPrev;
- HTC_SERVICE_ID ServiceID; /* Service ID (set by HTC) */
- HTC_ENDPOINT_ID Endpoint; /* endpoint for this distribution struct (set by HTC) */
- A_UINT32 DistFlags; /* distribution flags, distribution function can
- set default activity using SET_EP_ACTIVE() macro */
- int TxCreditsNorm; /* credits for normal operation, anything above this
- indicates the endpoint is over-subscribed, this field
- is only relevant to the credit distribution function */
- int TxCreditsMin; /* floor for credit distribution, this field is
- only relevant to the credit distribution function */
- int TxCreditsAssigned; /* number of credits assigned to this EP, this field
- is only relevant to the credit dist function */
- int TxCredits; /* current credits available, this field is used by
- HTC to determine whether a message can be sent or
- must be queued */
- int TxCreditsToDist; /* pending credits to distribute on this endpoint, this
- is set by HTC when credit reports arrive.
- The credit distribution functions sets this to zero
- when it distributes the credits */
- int TxCreditsSeek; /* this is the number of credits that the current pending TX
- packet needs to transmit. This is set by HTC when
- and endpoint needs credits in order to transmit */
- int TxCreditSize; /* size in bytes of each credit (set by HTC) */
- int TxCreditsPerMaxMsg; /* credits required for a maximum sized messages (set by HTC) */
- void *pHTCReserved; /* reserved for HTC use */
- int TxQueueDepth; /* current depth of TX queue , i.e. messages waiting for credits
- This field is valid only when HTC_CREDIT_DIST_ACTIVITY_CHANGE
- or HTC_CREDIT_DIST_SEND_COMPLETE is indicated on an endpoint
- that has non-zero credits to recover
- */
- } HTC_ENDPOINT_CREDIT_DIST;
- #define HTC_EP_ACTIVE ((A_UINT32) (((A_UINT32) 1) << 31))
- /* macro to check if an endpoint has gone active, useful for credit
- * distributions */
- #define IS_EP_ACTIVE(epDist) ((epDist)->DistFlags & HTC_EP_ACTIVE)
- #define SET_EP_ACTIVE(epDist) (epDist)->DistFlags |= HTC_EP_ACTIVE
- /* credit distibution code that is passed into the distrbution function,
- * there are mandatory and optional codes that must be handled */
- typedef enum _HTC_CREDIT_DIST_REASON {
- HTC_CREDIT_DIST_SEND_COMPLETE = 0, /* credits available as a result of completed
- send operations (MANDATORY) resulting in credit reports */
- HTC_CREDIT_DIST_ACTIVITY_CHANGE = 1, /* a change in endpoint activity occured (OPTIONAL) */
- HTC_CREDIT_DIST_SEEK_CREDITS, /* an endpoint needs to "seek" credits (OPTIONAL) */
- HTC_DUMP_CREDIT_STATE /* for debugging, dump any state information that is kept by
- the distribution function */
- } HTC_CREDIT_DIST_REASON;
- typedef void (*HTC_CREDIT_DIST_CALLBACK)(void *Context,
- HTC_ENDPOINT_CREDIT_DIST *pEPList,
- HTC_CREDIT_DIST_REASON Reason);
- typedef void (*HTC_CREDIT_INIT_CALLBACK)(void *Context,
- HTC_ENDPOINT_CREDIT_DIST *pEPList,
- int TotalCredits);
- /* endpoint statistics action */
- typedef enum _HTC_ENDPOINT_STAT_ACTION {
- HTC_EP_STAT_SAMPLE = 0, /* only read statistics */
- HTC_EP_STAT_SAMPLE_AND_CLEAR = 1, /* sample and immediately clear statistics */
- HTC_EP_STAT_CLEAR /* clear only */
- } HTC_ENDPOINT_STAT_ACTION;
- /* endpoint statistics */
- typedef struct _HTC_ENDPOINT_STATS {
- A_UINT32 TxCreditLowIndications; /* number of times the host set the credit-low flag in a send message on
- this endpoint */
- A_UINT32 TxIssued; /* running count of TX packets issued */
- A_UINT32 TxDropped; /* tx packets that were dropped */
- A_UINT32 TxCreditRpts; /* running count of total credit reports received for this endpoint */
- A_UINT32 TxCreditRptsFromRx; /* credit reports received from this endpoint's RX packets */
- A_UINT32 TxCreditRptsFromOther; /* credit reports received from RX packets of other endpoints */
- A_UINT32 TxCreditRptsFromEp0; /* credit reports received from endpoint 0 RX packets */
- A_UINT32 TxCreditsFromRx; /* count of credits received via Rx packets on this endpoint */
- A_UINT32 TxCreditsFromOther; /* count of credits received via another endpoint */
- A_UINT32 TxCreditsFromEp0; /* count of credits received via another endpoint */
- A_UINT32 TxCreditsConsummed; /* count of consummed credits */
- A_UINT32 TxCreditsReturned; /* count of credits returned */
- A_UINT32 RxReceived; /* count of RX packets received */
- A_UINT32 RxLookAheads; /* count of lookahead records
- found in messages received on this endpoint */
- } HTC_ENDPOINT_STATS;
- /* ------ Function Prototypes ------ */
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- @desc: Create an instance of HTC over the underlying HIF device
- @function name: HTCCreate
- @input: HifDevice - hif device handle,
- pInfo - initialization information
- @output:
- @return: HTC_HANDLE on success, NULL on failure
- @notes:
- @example:
- @see also: HTCDestroy
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- HTC_HANDLE HTCCreate(void *HifDevice, HTC_INIT_INFO *pInfo);
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- @desc: Get the underlying HIF device handle
- @function name: HTCGetHifDevice
- @input: HTCHandle - handle passed into the AddInstance callback
- @output:
- @return: opaque HIF device handle usable in HIF API calls.
- @notes:
- @example:
- @see also:
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- void *HTCGetHifDevice(HTC_HANDLE HTCHandle);
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- @desc: Set credit distribution parameters
- @function name: HTCSetCreditDistribution
- @input: HTCHandle - HTC handle
- pCreditDistCont - caller supplied context to pass into distribution functions
- CreditDistFunc - Distribution function callback
- CreditDistInit - Credit Distribution initialization callback
- ServicePriorityOrder - Array containing list of service IDs, lowest index is highest
- priority
- ListLength - number of elements in ServicePriorityOrder
- @output:
- @return:
- @notes: The user can set a custom credit distribution function to handle special requirements
- for each endpoint. A default credit distribution routine can be used by setting
- CreditInitFunc to NULL. The default credit distribution is only provided for simple
- "fair" credit distribution without regard to any prioritization.
- @example:
- @see also:
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- void HTCSetCreditDistribution(HTC_HANDLE HTCHandle,
- void *pCreditDistContext,
- HTC_CREDIT_DIST_CALLBACK CreditDistFunc,
- HTC_CREDIT_INIT_CALLBACK CreditInitFunc,
- HTC_SERVICE_ID ServicePriorityOrder[],
- int ListLength);
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- @desc: Wait for the target to indicate the HTC layer is ready
- @function name: HTCWaitTarget
- @input: HTCHandle - HTC handle
- @output:
- @return:
- @notes: This API blocks until the target responds with an HTC ready message.
- The caller should not connect services until the target has indicated it is
- ready.
- @example:
- @see also: HTCConnectService
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- A_STATUS HTCWaitTarget(HTC_HANDLE HTCHandle);
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- @desc: Start target service communications
- @function name: HTCStart
- @input: HTCHandle - HTC handle
- @output:
- @return:
- @notes: This API indicates to the target that the service connection phase is complete
- and the target can freely start all connected services. This API should only be
- called AFTER all service connections have been made. TCStart will issue a
- SETUP_COMPLETE message to the target to indicate that all service connections
- have been made and the target can start communicating over the endpoints.
- @example:
- @see also: HTCConnectService
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- A_STATUS HTCStart(HTC_HANDLE HTCHandle);
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- @desc: Add receive packet to HTC
- @function name: HTCAddReceivePkt
- @input: HTCHandle - HTC handle
- pPacket - HTC receive packet to add
- @output:
- @return: A_OK on success
- @notes: user must supply HTC packets for capturing incomming HTC frames. The caller
- must initialize each HTC packet using the SET_HTC_PACKET_INFO_RX_REFILL()
- macro.
- @example:
- @see also:
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- A_STATUS HTCAddReceivePkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket);
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- @desc: Connect to an HTC service
- @function name: HTCConnectService
- @input: HTCHandle - HTC handle
- pReq - connection details
- @output: pResp - connection response
- @return:
- @notes: Service connections must be performed before HTCStart. User provides callback handlers
- for various endpoint events.
- @example:
- @see also: HTCStart
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- A_STATUS HTCConnectService(HTC_HANDLE HTCHandle,
- HTC_SERVICE_CONNECT_REQ *pReq,
- HTC_SERVICE_CONNECT_RESP *pResp);
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- @desc: Send an HTC packet
- @function name: HTCSendPkt
- @input: HTCHandle - HTC handle
- pPacket - packet to send
- @output:
- @return: A_OK
- @notes: Caller must initialize packet using SET_HTC_PACKET_INFO_TX() macro.
- This interface is fully asynchronous. On error, HTC SendPkt will
- call the registered Endpoint callback to cleanup the packet.
- @example:
- @see also: HTCFlushEndpoint
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- A_STATUS HTCSendPkt(HTC_HANDLE HTCHandle, HTC_PACKET *pPacket);
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- @desc: Stop HTC service communications
- @function name: HTCStop
- @input: HTCHandle - HTC handle
- @output:
- @return:
- @notes: HTC communications is halted. All receive and pending TX packets will
- be flushed.
- @example:
- @see also:
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- void HTCStop(HTC_HANDLE HTCHandle);
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- @desc: Destory HTC service
- @function name: HTCDestroy
- @input: HTCHandle
- @output:
- @return:
- @notes: This cleans up all resources allocated by HTCCreate().
- @example:
- @see also: HTCCreate
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- void HTCDestroy(HTC_HANDLE HTCHandle);
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- @desc: Flush pending TX packets
- @function name: HTCFlushEndpoint
- @input: HTCHandle - HTC handle
- Endpoint - Endpoint to flush
- Tag - flush tag
- @output:
- @return:
- @notes: The Tag parameter is used to selectively flush packets with matching tags.
- The value of 0 forces all packets to be flush regardless of tag.
- @example:
- @see also: HTCSendPkt
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- void HTCFlushEndpoint(HTC_HANDLE HTCHandle, HTC_ENDPOINT_ID Endpoint, HTC_TX_TAG Tag);
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- @desc: Dump credit distribution state
- @function name: HTCDumpCreditStates
- @input: HTCHandle - HTC handle
- @output:
- @return:
- @notes: This dumps all credit distribution information to the debugger
- @example:
- @see also:
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- void HTCDumpCreditStates(HTC_HANDLE HTCHandle);
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- @desc: Indicate a traffic activity change on an endpoint
- @function name: HTCIndicateActivityChange
- @input: HTCHandle - HTC handle
- Endpoint - endpoint in which activity has changed
- Active - TRUE if active, FALSE if it has become inactive
- @output:
- @return:
- @notes: This triggers the registered credit distribution function to
- re-adjust credits for active/inactive endpoints.
- @example:
- @see also:
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- void HTCIndicateActivityChange(HTC_HANDLE HTCHandle,
- HTC_ENDPOINT_ID Endpoint,
- A_BOOL Active);
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- @desc: Get endpoint statistics
- @function name: HTCGetEndpointStatistics
- @input: HTCHandle - HTC handle
- Endpoint - Endpoint identifier
- Action - action to take with statistics
- @output:
- pStats - statistics that were sampled (can be NULL if Action is HTC_EP_STAT_CLEAR)
- @return: TRUE if statistics profiling is enabled, otherwise FALSE.
- @notes: Statistics is a compile-time option and this function may return FALSE
- if HTC is not compiled with profiling.
- The caller can specify the statistic "action" to take when sampling
- the statistics. This includes:
- HTC_EP_STAT_SAMPLE: The pStats structure is filled with the current values.
- HTC_EP_STAT_SAMPLE_AND_CLEAR: The structure is filled and the current statistics
- are cleared.
- HTC_EP_STAT_CLEA : the statistics are cleared, the called can pass a NULL value for
- pStats
- @example:
- @see also:
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- A_BOOL HTCGetEndpointStatistics(HTC_HANDLE HTCHandle,
- HTC_ENDPOINT_ID Endpoint,
- HTC_ENDPOINT_STAT_ACTION Action,
- HTC_ENDPOINT_STATS *pStats);
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- @desc: Unblock HTC message reception
- @function name: HTCUnblockRecv
- @input: HTCHandle - HTC handle
- @output:
- @return:
- @notes:
- HTC will block the receiver if the EpRecvAlloc callback fails to provide a packet.
- The caller can use this API to indicate to HTC when resources (buffers) are available
- such that the receiver can be unblocked and HTC may re-attempt fetching the pending message.
- This API is not required if the user uses the EpRecvRefill callback or uses the HTCAddReceivePacket()
- API to recycle or provide receive packets to HTC.
- @example:
- @see also:
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- void HTCUnblockRecv(HTC_HANDLE HTCHandle);
- /* internally used functions for testing... */
- void HTCEnableRecv(HTC_HANDLE HTCHandle);
- void HTCDisableRecv(HTC_HANDLE HTCHandle);
- #ifdef __cplusplus
- }
- #endif
- #endif /* _HTC_API_H_ */
|