mwifiex: use cfg80211 dynamic scan table and cfg80211_get_bss API
[pandora-kernel.git] / drivers / staging / ath6kl / include / htc_packet.h
1 //------------------------------------------------------------------------------
2 // <copyright file="htc_packet.h" company="Atheros">
3 //    Copyright (c) 2007-2010 Atheros Corporation.  All rights reserved.
4 // 
5 //
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.
9 //
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.
17 //
18 //
19 //------------------------------------------------------------------------------
20 //==============================================================================
21 // Author(s): ="Atheros"
22 //==============================================================================
23 #ifndef HTC_PACKET_H_
24 #define HTC_PACKET_H_
25
26
27 #include "dl_list.h"
28
29 /* ------ Endpoint IDS ------ */
30 typedef enum
31 {
32     ENDPOINT_UNUSED = -1,
33     ENDPOINT_0 = 0,
34     ENDPOINT_1 = 1,
35     ENDPOINT_2 = 2,
36     ENDPOINT_3,
37     ENDPOINT_4,
38     ENDPOINT_5,
39     ENDPOINT_6,
40     ENDPOINT_7,
41     ENDPOINT_8,
42     ENDPOINT_MAX,
43 } HTC_ENDPOINT_ID;
44
45 struct htc_packet;
46
47 typedef void (* HTC_PACKET_COMPLETION)(void *,struct htc_packet *);
48
49 typedef u16 HTC_TX_TAG;
50
51 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) */
56 };
57
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 */
61
62 struct htc_rx_packet_info {
63     u32 ExpectedHdr;        /* HTC internal use */
64     u32 HTCRxFlags;         /* HTC internal use */
65     u32 IndicationFlags;    /* indication flags set on each RX packet indication */
66 };
67
68 #define HTC_RX_FLAGS_INDICATE_MORE_PKTS  (1 << 0)   /* more packets on this endpoint are being fetched */
69
70 /* wrapper around endpoint-specific packets */
71 struct htc_packet {
72     struct dl_list         ListLink;       /* double link */
73     void            *pPktContext;   /* caller's per packet specific context */
74
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 */
81     /*
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
87      */
88     u8 *pBuffer;       /* payload start (RX/TX) */
89     u32 BufferLength;   /* length of buffer */
90     u32 ActualLength;   /* actual length of payload */
91     HTC_ENDPOINT_ID Endpoint;       /* endpoint that this packet was sent/recv'd from */
92     int        Status;         /* completion status */
93     union {
94         struct htc_tx_packet_info  AsTx;   /* Tx Packet specific info */
95         struct htc_rx_packet_info  AsRx;   /* Rx Packet specific info */
96     } PktInfo;
97
98     /* the following fields are for internal HTC use */
99     HTC_PACKET_COMPLETION Completion;   /* completion */
100     void                  *pContext;    /* HTC private completion context */
101 };
102
103
104
105 #define COMPLETE_HTC_PACKET(p,status)        \
106 {                                            \
107     (p)->Status = (status);                  \
108     (p)->Completion((p)->pContext,(p));      \
109 }
110
111 #define INIT_HTC_PACKET_INFO(p,b,len)             \
112 {                                                 \
113     (p)->pBufferStart = (b);                      \
114     (p)->BufferLength = (len);                    \
115 }
116
117 /* macro to set an initial RX packet for refilling HTC */
118 #define SET_HTC_PACKET_INFO_RX_REFILL(p,c,b,len,ep) \
119 {                                                 \
120     (p)->pPktContext = (c);                       \
121     (p)->pBuffer = (b);                           \
122     (p)->pBufferStart = (b);                      \
123     (p)->BufferLength = (len);                    \
124     (p)->Endpoint = (ep);                         \
125 }
126
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; }  
130
131 /* macro to set packet parameters for TX */
132 #define SET_HTC_PACKET_INFO_TX(p,c,b,len,ep,tag)  \
133 {                                                 \
134     (p)->pPktContext = (c);                       \
135     (p)->pBuffer = (b);                           \
136     (p)->ActualLength = (len);                    \
137     (p)->Endpoint = (ep);                         \
138     (p)->PktInfo.AsTx.Tag = (tag);                \
139 }
140
141 /* HTC Packet Queueing Macros */
142 struct htc_packet_queue {
143     struct dl_list     QueueHead;
144     int         Depth;    
145 };
146  
147 /* initialize queue */
148 #define INIT_HTC_PACKET_QUEUE(pQ)   \
149 {                                   \
150     DL_LIST_INIT(&(pQ)->QueueHead); \
151     (pQ)->Depth = 0;                \
152 }
153
154 /* enqueue HTC packet to the tail of the queue */
155 #define HTC_PACKET_ENQUEUE(pQ,p)                        \
156 {   DL_ListInsertTail(&(pQ)->QueueHead,&(p)->ListLink); \
157     (pQ)->Depth++;                                      \
158 }
159
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); \
163     (pQ)->Depth++;                                      \
164 }
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 struct htc_packet *HTC_GET_PKT_AT_HEAD(struct htc_packet_queue *queue)   {
169     if (queue->Depth == 0) {
170         return NULL; 
171     }  
172     return A_CONTAINING_STRUCT((DL_LIST_GET_ITEM_AT_HEAD(&queue->QueueHead)),struct htc_packet,ListLink);
173 }
174 /* remove a packet from a queue, where-ever it is in the queue */
175 #define HTC_PACKET_REMOVE(pQ,p)     \
176 {                                   \
177     DL_ListRemove(&(p)->ListLink);  \
178     (pQ)->Depth--;                  \
179 }
180
181 /* dequeue an HTC packet from the head of the queue */
182 static INLINE struct htc_packet *HTC_PACKET_DEQUEUE(struct htc_packet_queue *queue) {
183     struct dl_list    *pItem = DL_ListRemoveItemFromHead(&queue->QueueHead);
184     if (pItem != NULL) {
185         queue->Depth--;
186         return A_CONTAINING_STRUCT(pItem, struct htc_packet, ListLink);
187     }
188     return NULL;
189 }
190
191 /* dequeue an HTC packet from the tail of the queue */
192 static INLINE struct htc_packet *HTC_PACKET_DEQUEUE_TAIL(struct htc_packet_queue *queue) {
193     struct dl_list    *pItem = DL_ListRemoveItemFromTail(&queue->QueueHead);
194     if (pItem != NULL) {
195         queue->Depth--;
196         return A_CONTAINING_STRUCT(pItem, struct htc_packet, ListLink);
197     }
198     return NULL;
199 }
200
201 #define HTC_PACKET_QUEUE_DEPTH(pQ) (pQ)->Depth
202
203
204 #define HTC_GET_ENDPOINT_FROM_PKT(p) (p)->Endpoint
205 #define HTC_GET_TAG_FROM_PKT(p)      (p)->PktInfo.AsTx.Tag
206
207     /* transfer the packets from one queue to the tail of another queue */
208 #define HTC_PACKET_QUEUE_TRANSFER_TO_TAIL(pQDest,pQSrc) \
209 {                                                                           \
210     DL_ListTransferItemsToTail(&(pQDest)->QueueHead,&(pQSrc)->QueueHead);   \
211     (pQDest)->Depth += (pQSrc)->Depth;                                      \
212     (pQSrc)->Depth = 0;                                                     \
213 }
214
215     /* fast version to init and add a single packet to a queue */
216 #define INIT_HTC_PACKET_QUEUE_AND_ADD(pQ,pP) \
217 {                                            \
218     DL_LIST_INIT_AND_ADD(&(pQ)->QueueHead,&(pP)->ListLink)  \
219     (pQ)->Depth = 1;                                        \
220 }
221     
222 #define HTC_PACKET_QUEUE_ITERATE_ALLOW_REMOVE(pQ, pPTemp) \
223     ITERATE_OVER_LIST_ALLOW_REMOVE(&(pQ)->QueueHead,(pPTemp), struct htc_packet, ListLink) 
224
225 #define HTC_PACKET_QUEUE_ITERATE_END ITERATE_END
226         
227 #endif /*HTC_PACKET_H_*/