1 //------------------------------------------------------------------------------
2 // <copyright file="htc_packet.h" company="Atheros">
3 // Copyright (c) 2007-2010 Atheros Corporation. All rights reserved.
6 // Permission to use, copy, modify, and/or distribute this software for any
7 // purpose with or without fee is hereby granted, provided that the above
8 // copyright notice and this permission notice appear in all copies.
10 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 //------------------------------------------------------------------------------
20 //==============================================================================
21 // Author(s): ="Atheros"
22 //==============================================================================
29 /* ------ Endpoint IDS ------ */
47 typedef void (* HTC_PACKET_COMPLETION)(void *,struct _HTC_PACKET *);
49 typedef A_UINT16 HTC_TX_TAG;
51 typedef struct _HTC_TX_PACKET_INFO {
52 HTC_TX_TAG Tag; /* tag used to selective flush packets */
53 int CreditsUsed; /* number of credits used for this TX packet (HTC internal) */
54 u8 SendFlags; /* send flags (HTC internal) */
55 int SeqNo; /* internal seq no for debugging (HTC internal) */
58 #define HTC_TX_PACKET_TAG_ALL 0 /* a tag of zero is reserved and used to flush ALL packets */
59 #define HTC_TX_PACKET_TAG_INTERNAL 1 /* internal tags start here */
60 #define HTC_TX_PACKET_TAG_USER_DEFINED (HTC_TX_PACKET_TAG_INTERNAL + 9) /* user-defined tags start here */
62 typedef struct _HTC_RX_PACKET_INFO {
63 A_UINT32 ExpectedHdr; /* HTC internal use */
64 A_UINT32 HTCRxFlags; /* HTC internal use */
65 A_UINT32 IndicationFlags; /* indication flags set on each RX packet indication */
68 #define HTC_RX_FLAGS_INDICATE_MORE_PKTS (1 << 0) /* more packets on this endpoint are being fetched */
70 /* wrapper around endpoint-specific packets */
71 typedef struct _HTC_PACKET {
72 DL_LIST ListLink; /* double link */
73 void *pPktContext; /* caller's per packet specific context */
75 u8 *pBufferStart; /* the true buffer start , the caller can
76 store the real buffer start here. In
77 receive callbacks, the HTC layer sets pBuffer
78 to the start of the payload past the header. This
79 field allows the caller to reset pBuffer when it
80 recycles receive packets back to HTC */
82 * Pointer to the start of the buffer. In the transmit
83 * direction this points to the start of the payload. In the
84 * receive direction, however, the buffer when queued up
85 * points to the start of the HTC header but when returned
86 * to the caller points to the start of the payload
88 u8 *pBuffer; /* payload start (RX/TX) */
89 A_UINT32 BufferLength; /* length of buffer */
90 A_UINT32 ActualLength; /* actual length of payload */
91 HTC_ENDPOINT_ID Endpoint; /* endpoint that this packet was sent/recv'd from */
92 int Status; /* completion status */
94 HTC_TX_PACKET_INFO AsTx; /* Tx Packet specific info */
95 HTC_RX_PACKET_INFO AsRx; /* Rx Packet specific info */
98 /* the following fields are for internal HTC use */
99 HTC_PACKET_COMPLETION Completion; /* completion */
100 void *pContext; /* HTC private completion context */
105 #define COMPLETE_HTC_PACKET(p,status) \
107 (p)->Status = (status); \
108 (p)->Completion((p)->pContext,(p)); \
111 #define INIT_HTC_PACKET_INFO(p,b,len) \
113 (p)->pBufferStart = (b); \
114 (p)->BufferLength = (len); \
117 /* macro to set an initial RX packet for refilling HTC */
118 #define SET_HTC_PACKET_INFO_RX_REFILL(p,c,b,len,ep) \
120 (p)->pPktContext = (c); \
121 (p)->pBuffer = (b); \
122 (p)->pBufferStart = (b); \
123 (p)->BufferLength = (len); \
124 (p)->Endpoint = (ep); \
127 /* fast macro to recycle an RX packet that will be re-queued to HTC */
128 #define HTC_PACKET_RESET_RX(p) \
129 { (p)->pBuffer = (p)->pBufferStart; (p)->ActualLength = 0; }
131 /* macro to set packet parameters for TX */
132 #define SET_HTC_PACKET_INFO_TX(p,c,b,len,ep,tag) \
134 (p)->pPktContext = (c); \
135 (p)->pBuffer = (b); \
136 (p)->ActualLength = (len); \
137 (p)->Endpoint = (ep); \
138 (p)->PktInfo.AsTx.Tag = (tag); \
141 /* HTC Packet Queueing Macros */
142 typedef struct _HTC_PACKET_QUEUE {
147 /* initialize queue */
148 #define INIT_HTC_PACKET_QUEUE(pQ) \
150 DL_LIST_INIT(&(pQ)->QueueHead); \
154 /* enqueue HTC packet to the tail of the queue */
155 #define HTC_PACKET_ENQUEUE(pQ,p) \
156 { DL_ListInsertTail(&(pQ)->QueueHead,&(p)->ListLink); \
160 /* enqueue HTC packet to the tail of the queue */
161 #define HTC_PACKET_ENQUEUE_TO_HEAD(pQ,p) \
162 { DL_ListInsertHead(&(pQ)->QueueHead,&(p)->ListLink); \
165 /* test if a queue is empty */
166 #define HTC_QUEUE_EMPTY(pQ) ((pQ)->Depth == 0)
167 /* get packet at head without removing it */
168 static INLINE HTC_PACKET *HTC_GET_PKT_AT_HEAD(HTC_PACKET_QUEUE *queue) {
169 if (queue->Depth == 0) {
172 return A_CONTAINING_STRUCT((DL_LIST_GET_ITEM_AT_HEAD(&queue->QueueHead)),HTC_PACKET,ListLink);
174 /* remove a packet from a queue, where-ever it is in the queue */
175 #define HTC_PACKET_REMOVE(pQ,p) \
177 DL_ListRemove(&(p)->ListLink); \
181 /* dequeue an HTC packet from the head of the queue */
182 static INLINE HTC_PACKET *HTC_PACKET_DEQUEUE(HTC_PACKET_QUEUE *queue) {
183 DL_LIST *pItem = DL_ListRemoveItemFromHead(&queue->QueueHead);
186 return A_CONTAINING_STRUCT(pItem, HTC_PACKET, ListLink);
191 /* dequeue an HTC packet from the tail of the queue */
192 static INLINE HTC_PACKET *HTC_PACKET_DEQUEUE_TAIL(HTC_PACKET_QUEUE *queue) {
193 DL_LIST *pItem = DL_ListRemoveItemFromTail(&queue->QueueHead);
196 return A_CONTAINING_STRUCT(pItem, HTC_PACKET, ListLink);
201 #define HTC_PACKET_QUEUE_DEPTH(pQ) (pQ)->Depth
204 #define HTC_GET_ENDPOINT_FROM_PKT(p) (p)->Endpoint
205 #define HTC_GET_TAG_FROM_PKT(p) (p)->PktInfo.AsTx.Tag
207 /* transfer the packets from one queue to the tail of another queue */
208 #define HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(pQDest,pQSrc) \
210 DL_ListTransferItemsToTail(&(pQDest)->QueueHead,&(pQSrc)->QueueHead); \
211 (pQDest)->Depth += (pQSrc)->Depth; \
212 (pQSrc)->Depth = 0; \
215 /* fast version to init and add a single packet to a queue */
216 #define INIT_HTC_PACKET_QUEUE_AND_ADD(pQ,pP) \
218 DL_LIST_INIT_AND_ADD(&(pQ)->QueueHead,&(pP)->ListLink) \
222 #define HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pQ, pPTemp) \
223 ITERATE_OVER_LIST_ALLOW_REMOVE(&(pQ)->QueueHead,(pPTemp), HTC_PACKET, ListLink)
225 #define HTC_PACKET_QUEUE_ITERATE_END ITERATE_END
227 #endif /*HTC_PACKET_H_*/