OLD | NEW |
(Empty) | |
| 1 //------------------------------------------------------------------------------ |
| 2 // <copyright file="htc_packet.h" company="Atheros"> |
| 3 // Copyright (c) 2007-2008 Atheros Corporation. All rights reserved. |
| 4 // |
| 5 // This program is free software; you can redistribute it and/or modify |
| 6 // it under the terms of the GNU General Public License version 2 as |
| 7 // published by the Free Software Foundation; |
| 8 // |
| 9 // Software distributed under the License is distributed on an "AS |
| 10 // IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
| 11 // implied. See the License for the specific language governing |
| 12 // rights and limitations under the License. |
| 13 // |
| 14 // |
| 15 //------------------------------------------------------------------------------ |
| 16 //============================================================================== |
| 17 // Author(s): ="Atheros" |
| 18 //============================================================================== |
| 19 #ifndef HTC_PACKET_H_ |
| 20 #define HTC_PACKET_H_ |
| 21 |
| 22 |
| 23 #include "dl_list.h" |
| 24 |
| 25 /* ------ Endpoint IDS ------ */ |
| 26 typedef enum |
| 27 { |
| 28 ENDPOINT_UNUSED = -1, |
| 29 ENDPOINT_0 = 0, |
| 30 ENDPOINT_1 = 1, |
| 31 ENDPOINT_2 = 2, |
| 32 ENDPOINT_3, |
| 33 ENDPOINT_4, |
| 34 ENDPOINT_5, |
| 35 ENDPOINT_6, |
| 36 ENDPOINT_7, |
| 37 ENDPOINT_8, |
| 38 ENDPOINT_MAX, |
| 39 } HTC_ENDPOINT_ID; |
| 40 |
| 41 struct _HTC_PACKET; |
| 42 |
| 43 typedef void (* HTC_PACKET_COMPLETION)(void *,struct _HTC_PACKET *); |
| 44 |
| 45 typedef A_UINT16 HTC_TX_TAG; |
| 46 |
| 47 typedef struct _HTC_TX_PACKET_INFO { |
| 48 HTC_TX_TAG Tag; /* tag used to selective flush packets */ |
| 49 int CreditsUsed; /* number of credits used for this TX packet (
HTC internal) */ |
| 50 A_UINT8 SendFlags; /* send flags (HTC internal) */ |
| 51 int SeqNo; /* internal seq no for debugging (HTC internal
) */ |
| 52 } HTC_TX_PACKET_INFO; |
| 53 |
| 54 #define HTC_TX_PACKET_TAG_ALL 0 /* a tag of zero is reserved and use
d to flush ALL packets */ |
| 55 #define HTC_TX_PACKET_TAG_INTERNAL 1 /* inter
nal tags start here */ |
| 56 #define HTC_TX_PACKET_TAG_USER_DEFINED (HTC_TX_PACKET_TAG_INTERNAL + 9) /* user-
defined tags start here */ |
| 57 |
| 58 typedef struct _HTC_RX_PACKET_INFO { |
| 59 A_UINT32 ExpectedHdr; /* HTC internal use */ |
| 60 A_UINT32 HTCRxFlags; /* HTC internal use */ |
| 61 A_UINT32 IndicationFlags; /* indication flags set on each RX packet in
dication */ |
| 62 } HTC_RX_PACKET_INFO; |
| 63 |
| 64 #define HTC_RX_FLAGS_INDICATE_MORE_PKTS (1 << 0) /* more packets on this endp
oint are being fetched */ |
| 65 |
| 66 /* wrapper around endpoint-specific packets */ |
| 67 typedef struct _HTC_PACKET { |
| 68 DL_LIST ListLink; /* double link */ |
| 69 void *pPktContext; /* caller's per packet specific context */ |
| 70 |
| 71 A_UINT8 *pBufferStart; /* the true buffer start , the caller can |
| 72 store the real buffer start here. In |
| 73 receive callbacks, the HTC layer sets pBu
ffer |
| 74 to the start of the payload past the head
er. This |
| 75 field allows the caller to reset pBuffer
when it |
| 76 recycles receive packets back to HTC */ |
| 77 /* |
| 78 * Pointer to the start of the buffer. In the transmit |
| 79 * direction this points to the start of the payload. In the |
| 80 * receive direction, however, the buffer when queued up |
| 81 * points to the start of the HTC header but when returned |
| 82 * to the caller points to the start of the payload |
| 83 */ |
| 84 A_UINT8 *pBuffer; /* payload start (RX/TX) */ |
| 85 A_UINT32 BufferLength; /* length of buffer */ |
| 86 A_UINT32 ActualLength; /* actual length of payload */ |
| 87 HTC_ENDPOINT_ID Endpoint; /* endpoint that this packet was sent/recv'd
from */ |
| 88 A_STATUS Status; /* completion status */ |
| 89 union { |
| 90 HTC_TX_PACKET_INFO AsTx; /* Tx Packet specific info */ |
| 91 HTC_RX_PACKET_INFO AsRx; /* Rx Packet specific info */ |
| 92 } PktInfo; |
| 93 |
| 94 /* the following fields are for internal HTC use */ |
| 95 HTC_PACKET_COMPLETION Completion; /* completion */ |
| 96 void *pContext; /* HTC private completion context */ |
| 97 } HTC_PACKET; |
| 98 |
| 99 |
| 100 |
| 101 #define COMPLETE_HTC_PACKET(p,status) \ |
| 102 { \ |
| 103 (p)->Status = (status); \ |
| 104 (p)->Completion((p)->pContext,(p)); \ |
| 105 } |
| 106 |
| 107 #define INIT_HTC_PACKET_INFO(p,b,len) \ |
| 108 { \ |
| 109 (p)->pBufferStart = (b); \ |
| 110 (p)->BufferLength = (len); \ |
| 111 } |
| 112 |
| 113 /* macro to set an initial RX packet for refilling HTC */ |
| 114 #define SET_HTC_PACKET_INFO_RX_REFILL(p,c,b,len,ep) \ |
| 115 { \ |
| 116 (p)->pPktContext = (c); \ |
| 117 (p)->pBuffer = (b); \ |
| 118 (p)->pBufferStart = (b); \ |
| 119 (p)->BufferLength = (len); \ |
| 120 (p)->Endpoint = (ep); \ |
| 121 } |
| 122 |
| 123 /* fast macro to recycle an RX packet that will be re-queued to HTC */ |
| 124 #define HTC_PACKET_RESET_RX(p) \ |
| 125 { (p)->pBuffer = (p)->pBufferStart; (p)->ActualLength = 0; } |
| 126 |
| 127 /* macro to set packet parameters for TX */ |
| 128 #define SET_HTC_PACKET_INFO_TX(p,c,b,len,ep,tag) \ |
| 129 { \ |
| 130 (p)->pPktContext = (c); \ |
| 131 (p)->pBuffer = (b); \ |
| 132 (p)->ActualLength = (len); \ |
| 133 (p)->Endpoint = (ep); \ |
| 134 (p)->PktInfo.AsTx.Tag = (tag); \ |
| 135 } |
| 136 |
| 137 /* HTC Packet Queueing Macros */ |
| 138 typedef struct _HTC_PACKET_QUEUE { |
| 139 DL_LIST QueueHead; |
| 140 int Depth; |
| 141 } HTC_PACKET_QUEUE; |
| 142 |
| 143 /* initialize queue */ |
| 144 #define INIT_HTC_PACKET_QUEUE(pQ) \ |
| 145 { \ |
| 146 DL_LIST_INIT(&(pQ)->QueueHead); \ |
| 147 (pQ)->Depth = 0; \ |
| 148 } |
| 149 |
| 150 /* enqueue HTC packet to the tail of the queue */ |
| 151 #define HTC_PACKET_ENQUEUE(pQ,p) \ |
| 152 { DL_ListInsertTail(&(pQ)->QueueHead,&(p)->ListLink); \ |
| 153 (pQ)->Depth++; \ |
| 154 } |
| 155 |
| 156 /* enqueue HTC packet to the tail of the queue */ |
| 157 #define HTC_PACKET_ENQUEUE_TO_HEAD(pQ,p) \ |
| 158 { DL_ListInsertHead(&(pQ)->QueueHead,&(p)->ListLink); \ |
| 159 (pQ)->Depth++; \ |
| 160 } |
| 161 /* test if a queue is empty */ |
| 162 #define HTC_QUEUE_EMPTY(pQ) ((pQ)->Depth == 0) |
| 163 /* get packet at head without removing it */ |
| 164 static INLINE HTC_PACKET *HTC_GET_PKT_AT_HEAD(HTC_PACKET_QUEUE *queue) { |
| 165 if (queue->Depth == 0) { |
| 166 return NULL; |
| 167 } |
| 168 return A_CONTAINING_STRUCT((DL_LIST_GET_ITEM_AT_HEAD(&queue->QueueHead)),HTC
_PACKET,ListLink); |
| 169 } |
| 170 /* remove a packet from a queue, where-ever it is in the queue */ |
| 171 #define HTC_PACKET_REMOVE(pQ,p) \ |
| 172 { \ |
| 173 DL_ListRemove(&(p)->ListLink); \ |
| 174 (pQ)->Depth--; \ |
| 175 } |
| 176 |
| 177 /* dequeue an HTC packet from the head of the queue */ |
| 178 static INLINE HTC_PACKET *HTC_PACKET_DEQUEUE(HTC_PACKET_QUEUE *queue) { |
| 179 DL_LIST *pItem = DL_ListRemoveItemFromHead(&queue->QueueHead); |
| 180 if (pItem != NULL) { |
| 181 queue->Depth--; |
| 182 return A_CONTAINING_STRUCT(pItem, HTC_PACKET, ListLink); |
| 183 } |
| 184 return NULL; |
| 185 } |
| 186 |
| 187 /* dequeue an HTC packet from the tail of the queue */ |
| 188 static INLINE HTC_PACKET *HTC_PACKET_DEQUEUE_TAIL(HTC_PACKET_QUEUE *queue) { |
| 189 DL_LIST *pItem = DL_ListRemoveItemFromTail(&queue->QueueHead); |
| 190 if (pItem != NULL) { |
| 191 queue->Depth--; |
| 192 return A_CONTAINING_STRUCT(pItem, HTC_PACKET, ListLink); |
| 193 } |
| 194 return NULL; |
| 195 } |
| 196 |
| 197 #define HTC_PACKET_QUEUE_DEPTH(pQ) (pQ)->Depth |
| 198 |
| 199 |
| 200 #define HTC_GET_ENDPOINT_FROM_PKT(p) (p)->Endpoint |
| 201 #define HTC_GET_TAG_FROM_PKT(p) (p)->PktInfo.AsTx.Tag |
| 202 |
| 203 /* transfer the packets from one queue to the tail of another queue */ |
| 204 #define HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(pQDest,pQSrc) \ |
| 205 { \ |
| 206 DL_ListTransferItemsToTail(&(pQDest)->QueueHead,&(pQSrc)->QueueHead); \ |
| 207 (pQDest)->Depth += (pQSrc)->Depth; \ |
| 208 (pQSrc)->Depth = 0; \ |
| 209 } |
| 210 |
| 211 /* fast version to init and add a single packet to a queue */ |
| 212 #define INIT_HTC_PACKET_QUEUE_AND_ADD(pQ,pP) \ |
| 213 { \ |
| 214 DL_LIST_INIT_AND_ADD(&(pQ)->QueueHead,&(pP)->ListLink) \ |
| 215 (pQ)->Depth = 1; \ |
| 216 } |
| 217 |
| 218 #define HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pQ, pPTemp) \ |
| 219 ITERATE_OVER_LIST_ALLOW_REMOVE(&(pQ)->QueueHead,(pPTemp), HTC_PACKET, ListLi
nk) |
| 220 |
| 221 #define HTC_PACKET_QUEUE_ITERATE_END ITERATE_END |
| 222 |
| 223 #endif /*HTC_PACKET_H_*/ |
OLD | NEW |