| 1 | /* |
| 2 | * |
| 3 | * Copyright (c) 2007 Atheros Communications Inc. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation; |
| 10 | * |
| 11 | * Software distributed under the License is distributed on an "AS |
| 12 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
| 13 | * implied. See the License for the specific language governing |
| 14 | * rights and limitations under the License. |
| 15 | * |
| 16 | * |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #ifndef HTC_PACKET_H_ |
| 21 | #define HTC_PACKET_H_ |
| 22 | |
| 23 | |
| 24 | #include "dl_list.h" |
| 25 | |
| 26 | struct _HTC_PACKET; |
| 27 | |
| 28 | typedef void (* HTC_PACKET_COMPLETION)(void *,struct _HTC_PACKET *); |
| 29 | |
| 30 | typedef A_UINT16 HTC_TX_TAG; |
| 31 | |
| 32 | typedef struct _HTC_TX_PACKET_INFO { |
| 33 | HTC_TX_TAG Tag; /* tag used to selective flush packets */ |
| 34 | } HTC_TX_PACKET_INFO; |
| 35 | |
| 36 | #define HTC_TX_PACKET_TAG_ALL 0 /* a tag of zero is reserved and used to flush ALL packets */ |
| 37 | #define HTC_TX_PACKET_TAG_INTERNAL 1 /* internal tags start here */ |
| 38 | #define HTC_TX_PACKET_TAG_USER_DEFINED (HTC_TX_PACKET_TAG_INTERNAL + 9) /* user-defined tags start here */ |
| 39 | |
| 40 | typedef struct _HTC_RX_PACKET_INFO { |
| 41 | A_UINT32 Unused; /* for future use and to make compilers happy */ |
| 42 | } HTC_RX_PACKET_INFO; |
| 43 | |
| 44 | /* wrapper around endpoint-specific packets */ |
| 45 | typedef struct _HTC_PACKET { |
| 46 | DL_LIST ListLink; /* double link */ |
| 47 | void *pPktContext; /* caller's per packet specific context */ |
| 48 | |
| 49 | A_UINT8 *pBufferStart; /* the true buffer start , the caller can |
| 50 | store the real buffer start here. In |
| 51 | receive callbacks, the HTC layer sets pBuffer |
| 52 | to the start of the payload past the header. This |
| 53 | field allows the caller to reset pBuffer when it |
| 54 | recycles receive packets back to HTC */ |
| 55 | /* |
| 56 | * Pointer to the start of the buffer. In the transmit |
| 57 | * direction this points to the start of the payload. In the |
| 58 | * receive direction, however, the buffer when queued up |
| 59 | * points to the start of the HTC header but when returned |
| 60 | * to the caller points to the start of the payload |
| 61 | */ |
| 62 | A_UINT8 *pBuffer; /* payload start (RX/TX) */ |
| 63 | A_UINT32 BufferLength; /* length of buffer */ |
| 64 | A_UINT32 ActualLength; /* actual length of payload */ |
| 65 | int Endpoint; /* endpoint that this packet was sent/recv'd from */ |
| 66 | A_STATUS Status; /* completion status */ |
| 67 | union { |
| 68 | HTC_TX_PACKET_INFO AsTx; /* Tx Packet specific info */ |
| 69 | HTC_RX_PACKET_INFO AsRx; /* Rx Packet specific info */ |
| 70 | } PktInfo; |
| 71 | |
| 72 | /* the following fields are for internal HTC use */ |
| 73 | HTC_PACKET_COMPLETION Completion; /* completion */ |
| 74 | void *pContext; /* HTC private completion context */ |
| 75 | A_UINT32 HTCReserved; /* reserved */ |
| 76 | } HTC_PACKET; |
| 77 | |
| 78 | |
| 79 | |
| 80 | #define COMPLETE_HTC_PACKET(p,status) \ |
| 81 | { \ |
| 82 | (p)->Status = (status); \ |
| 83 | (p)->Completion((p)->pContext,(p)); \ |
| 84 | } |
| 85 | |
| 86 | #define INIT_HTC_PACKET_INFO(p,b,len) \ |
| 87 | { \ |
| 88 | (p)->pBufferStart = (b); \ |
| 89 | (p)->BufferLength = (len); \ |
| 90 | } |
| 91 | |
| 92 | /* macro to set an initial RX packet for refilling HTC */ |
| 93 | #define SET_HTC_PACKET_INFO_RX_REFILL(p,c,b,len,ep) \ |
| 94 | { \ |
| 95 | (p)->pPktContext = (c); \ |
| 96 | (p)->pBuffer = (b); \ |
| 97 | (p)->pBufferStart = (b); \ |
| 98 | (p)->BufferLength = (len); \ |
| 99 | (p)->Endpoint = (ep); \ |
| 100 | } |
| 101 | |
| 102 | /* fast macro to recycle an RX packet that will be re-queued to HTC */ |
| 103 | #define HTC_PACKET_RESET_RX(p) \ |
| 104 | (p)->pBuffer = (p)->pBufferStart |
| 105 | |
| 106 | /* macro to set packet parameters for TX */ |
| 107 | #define SET_HTC_PACKET_INFO_TX(p,c,b,len,ep,tag) \ |
| 108 | { \ |
| 109 | (p)->pPktContext = (c); \ |
| 110 | (p)->pBuffer = (b); \ |
| 111 | (p)->ActualLength = (len); \ |
| 112 | (p)->Endpoint = (ep); \ |
| 113 | (p)->PktInfo.AsTx.Tag = (tag); \ |
| 114 | } |
| 115 | |
| 116 | /* HTC Packet Queueing Macros */ |
| 117 | typedef DL_LIST HTC_PACKET_QUEUE; |
| 118 | /* initialize queue */ |
| 119 | #define INIT_HTC_PACKET_QUEUE(pQ) DL_LIST_INIT((pQ)) |
| 120 | /* enqueue HTC packet to the tail of the queue */ |
| 121 | #define HTC_PACKET_ENQUEUE(pQ,p) DL_ListInsertTail((pQ),&(p)->ListLink) |
| 122 | /* test if a queue is empty */ |
| 123 | #define HTC_QUEUE_EMPTY(pQ) DL_LIST_IS_EMPTY((pQ)) |
| 124 | /* get packet at head without removing it */ |
| 125 | #define HTC_GET_PKT_AT_HEAD(pQ) A_CONTAINING_STRUCT((DL_LIST_GET_ITEM_AT_HEAD(pQ)),HTC_PACKET,ListLink); |
| 126 | /* remove a packet from the current list it is linked to */ |
| 127 | #define HTC_PACKET_REMOVE(p) DL_ListRemove(&(p)->ListLink) |
| 128 | |
| 129 | /* dequeue an HTC packet from the head of the queue */ |
| 130 | static INLINE HTC_PACKET *HTC_PACKET_DEQUEUE(HTC_PACKET_QUEUE *queue) { |
| 131 | DL_LIST *pItem = DL_ListRemoveItemFromHead(queue); |
| 132 | if (pItem != NULL) { |
| 133 | return A_CONTAINING_STRUCT(pItem, HTC_PACKET, ListLink); |
| 134 | } |
| 135 | return NULL; |
| 136 | } |
| 137 | |
| 138 | #endif /*HTC_PACKET_H_*/ |
| 139 | |