blob: 17ae26cc4484c39444b40e85a62dc49975d92966 [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
2 * Copyright (c) 2012, Code Aurora Forum. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22#if !defined( __WLAN_QCT_PAL_PACKET_H )
23#define __WLAN_QCT_PAL_PACKET_H
24
25/**=========================================================================
26
27 \file wlan_qct_pal_packet.h
28
29 \brief define PAL packet. wpt = (Wlan Pal Type)
30
31 Definitions for platform independent.
32
33 Copyright 2010 (c) Qualcomm, Incorporated. All Rights Reserved.
34
35 Qualcomm Confidential and Proprietary.
36
37 ========================================================================*/
38
39#include "wlan_qct_pal_type.h"
40#include "wlan_qct_pal_status.h"
41
42// The size of the data buffer in vos/pal packets
43// Explanation:
44// MTU size = 1500 bytes
45// Max number of BD/PDUs required to hold payload of 1500 =
46// 12 PDUs (124 bytes each) + 1 BD (12 bytes for payload) =
47// 13 BD/PDUs = 13 x 128 = 1664 bytes
48//
49// In case of A-MSDU with each MSDU having payload of 1500 bytes:
50// 1st MSDU = requires 13 BD/PDUs as per the above equation.
51// 2nd MSDU = HW inserts an extra BD to hold the information of the 2nd
52// MSDU and the payload portion of this BD is unused which means to cover
53// 1500 bytes we require 13 PDUs.
54// So 13 PDUs + 1 BD = 14 BD/PDUs = 1792 bytes.
55//
56// HOWEVER
57// In case of A-MSDU with errors, the ADU will push to the host up to
58// 2346 bytes. If that is the 2nd or later MSDU the worst case is:
59// 1 Prepended BD/PDU
60// 1 BD/PDU containing the 1st 4 bytes of the delimiter
61// 1 BD/PDU containing the last 10 bytes of the delimiter
62// plus the first 114 of the payload
63// 18 BD/PDUs containing the remaining 2232 bytes of the payload
64// 2346 - 114 = 2232; 2232 / 124 = 18
65// So 21 BD/PDUs are required
Jeff Johnsone7245742012-09-05 17:12:55 -070066
67//The size of AMSDU frame per spec can be a max of 3839 bytes
68// in BD/PDUs that means 30 (one BD = 128 bytes)
69// we must add the size of the 802.11 header to that
70#define VPKT_SIZE_BUFFER (30 * 128) + 32
Jeff Johnson295189b2012-06-20 16:38:30 -070071
72typedef enum
73{
74 ///Packet is used to transmit 802.11 Management frames.
75 eWLAN_PAL_PKT_TYPE_TX_802_11_MGMT,
76 ///Packet is used to transmit 802.11 Data frames.
77 eWLAN_PAL_PKT_TYPE_TX_802_11_DATA,
78 ///Packet is used to transmit 802.3 Data frames.
79 eWLAN_PAL_PKT_TYPE_TX_802_3_DATA,
80 ///Packet contains Received data of an unknown frame type
81 eWLAN_PAL_PKT_TYPE_RX_RAW
82} wpt_packet_type;
83
84
85typedef struct swpt_packet
86{
87 /*
88 Pointer to a buffer for BD for TX packets
89 For RX packets. The pBD MUST set to NULL.
90 PAL packet shall set the pointer point to the start of the flat buffer
91 where the BD starts.
92 */
93 void *pBD;
94 //Physical address for pBD for DMA-able devices
95 void *pBDPhys;
96 //OS dependent strucutre used only by OS specific code.
97 void *pOSStruct;
98 void *pktMetaInfo;
99 wpt_packet_type pktType;
100 //The number of bytes pBD uses. It MUST be set to 0 for RX packets
101 wpt_uint16 BDLength;
102
103 //Internal data for PAL packet implementation usage only
104 void *pInternalData;
105} wpt_packet;
106
107typedef struct swpt_iterator
108{
109 void *pNext;
110 void *pCur;
111 void *pContext;
112} wpt_iterator;
113
114
115//pPkt is a pointer to wpt_packet
116#define WPAL_PACKET_SET_BD_POINTER(pPkt, pBd) ( (pPkt)->pBD = (pBd) )
117#define WPAL_PACKET_GET_BD_POINTER(pPkt) ( (pPkt)->pBD )
118//Access the physical address of BD
119#define WPAL_PACKET_SET_BD_PHYS(pPkt, pBdPhys) ( (pPkt)->pBDPhys = (pBdPhys) )
120#define WPAL_PACKET_GET_BD_PHYS(pPkt) ( (pPkt)->pBDPhys )
121#define WPAL_PACKET_SET_BD_LENGTH(pPkt, len) ( (pPkt)->BDLength = (len) )
122#define WPAL_PACKET_GET_BD_LENGTH(pPkt) ( (pPkt)->BDLength )
123#define WPAL_PACKET_SET_METAINFO_POINTER(pPkt, p) ( (pPkt)->pktMetaInfo = (p) )
124#define WPAL_PACKET_GET_METAINFO_POINTER(pPkt) ( (pPkt)->pktMetaInfo )
125#define WPAL_PACKET_SET_TYPE(pPkt, type) ( (pPkt)->pktType = (type) )
126#define WPAL_PACKET_GET_TYPE(pPkt) ( (pPkt)->pktType )
127#define WPAL_PACKET_SET_OS_STRUCT_POINTER(pPkt, pStruct) ( (pPkt)->pOSStruct = (pStruct) )
128#define WPAL_PACKET_GET_OS_STRUCT_POINTER(pPkt) ( (pPkt)->pOSStruct )
129#define WPAL_PACKET_IS_FLAT_BUF(pktType) ( (eWLAN_PAL_PKT_TYPE_RX_RAW == (pktType)) || \
130 (eWLAN_PAL_PKT_TYPE_TX_802_11_MGMT == (pktType)) )
131
132/* RX RAW packet alloc fail due to out of resource CB function type */
133typedef void ( *wpalPacketLowPacketCB )( wpt_packet *pPacket, void *usrData );
134
135
136/*---------------------------------------------------------------------------
137 wpalPacketInit – Initialize all wpt_packet related objects. Allocate memory for wpt_packet.
138 Allocate memory for TX management frames and RX frames.
139 For our legacy UMAC, it is not needed because vos_packet contains wpt_packet.
140 Param:
141 pPalContext – A context PAL uses??
142 Return:
143 eWLAN_PAL_STATUS_SUCCESS -- success
144---------------------------------------------------------------------------*/
145wpt_status wpalPacketInit(void *pPalContext);
146
147/*---------------------------------------------------------------------------
148 wpalPacketClose – Free all allocated resource by wpalPacketInit.
149 For our legacy UMAC, it is not needed because vos_packet contains pal_packet.
150 Param:
151 pPalContext – A context PAL uses??
152 Return:
153 eWLAN_PAL_STATUS_SUCCESS -- success
154---------------------------------------------------------------------------*/
155wpt_status wpalPacketClose(void *pPalContext);
156
157
158/*---------------------------------------------------------------------------
159 wpalPacketAlloc – Allocate a wpt_packet from PAL.
160 Param:
161 pPalContext – A context PAL uses??
162 pktType – specify the type of wpt_packet to allocate
163 nPktSize - specify the maximum size of the packet buffer.
164 Return:
165 A pointer to the wpt_packet. NULL means fail.
166---------------------------------------------------------------------------*/
167wpt_packet * wpalPacketAlloc(wpt_packet_type pktType, wpt_uint32 nPktSize,
168 wpalPacketLowPacketCB rxLowCB, void *usrdata);
169
170/*---------------------------------------------------------------------------
171 wpalPacketFree – Free a wpt_packet chain for one particular type.
172 Packet type is carried in wpt_packet structure.
173 Param:
174 pPalContext – A context PAL uses??
175 pPkt - pointer to a packet to be freed.
176 Return:
177 eWLAN_PAL_STATUS_SUCCESS - success
178---------------------------------------------------------------------------*/
179wpt_status wpalPacketFree(wpt_packet *pPkt);
180
181/*---------------------------------------------------------------------------
182 wpalPacketGetLength – Get number of bytes in a wpt_packet.
183 Param:
184 pPalContext – PAL context returned from PAL open
185 pPkt - pointer to a packet to be freed.
186 Return:
187 Length of the data include layer-2 headers. For example, if the frame is 802.3,
188 the length includes the ethernet header.
189---------------------------------------------------------------------------*/
190wpt_uint32 wpalPacketGetLength(wpt_packet *pPkt);
191
192/*---------------------------------------------------------------------------
193 wpalPacketRawTrimHead – Move the starting offset and reduce packet length.
194 The function can only be used with raw packets,
195 whose buffer is one piece and allocated by WLAN driver.
196 Param:
197 pPkt - pointer to a wpt_packet.
198 size – number of bytes to take off the head.
199 Return:
200 eWPAL_STATUS_SUCCESS - success. Fail otherwise.
201---------------------------------------------------------------------------*/
202wpt_status wpalPacketRawTrimHead(wpt_packet *pPkt, wpt_uint32 size);
203
204/*---------------------------------------------------------------------------
205 wpalPacketRawTrimTail – reduce the length of the packet. The function can
206 only be used with raw packets, whose buffer is one piece and
207 allocated by WLAN driver. This also reduce the length of the packet.
208 Param:
209 pPkt - pointer to a wpt_packet.
210 size – number of bytes to take of the packet length
211 Return:
212 eWLAN_PAL_STATUS_SUCCESS – success. Otherwise fail.
213---------------------------------------------------------------------------*/
214wpt_status wpalPacketRawTrimTail(wpt_packet *pPkt, wpt_uint32 size);
215
216
217/*---------------------------------------------------------------------------
218 wpalPacketGetRawBuf – Return the starting buffer's virtual address for the RAW flat buffer
219 It is inline in hope of faster implementation for certain platform.
220 Param:
221 pPkt - pointer to a wpt_packet.
222 Return:
223 NULL - fail.
224 Otherwise the address of the starting of the buffer
225---------------------------------------------------------------------------*/
226extern WPT_INLINE wpt_uint8 *wpalPacketGetRawBuf(wpt_packet *pPkt);
227
228
229/*---------------------------------------------------------------------------
230 wpalPacketSetRxLength – Set the valid data length on a RX packet. This function must
231 be called once per RX packet per receiving. It indicates the available data length from
232 the start of the buffer.
233 Param:
234 pPkt - pointer to a wpt_packet.
235 Return:
236 NULL - fail.
237 Otherwise the address of the starting of the buffer
238---------------------------------------------------------------------------*/
239extern WPT_INLINE wpt_status wpalPacketSetRxLength(wpt_packet *pPkt, wpt_uint32 len);
240
241
242/*---------------------------------------------------------------------------
243 wpalIteratorInit – Initialize an interator by updating pCur to first item.
244 Param:
245 pIter – pointer to a caller allocated wpt_iterator
246 pPacket – pointer to a wpt_packet
247 Return:
248 eWLAN_PAL_STATUS_SUCCESS - success
249---------------------------------------------------------------------------*/
250wpt_status wpalIteratorInit(wpt_iterator *pIter, wpt_packet *pPacket);
251
252/*---------------------------------------------------------------------------
253 wpalIteratorNext – Get the address for the next item
254 Param:
255 pIter – pointer to a caller allocated wpt_iterator
256 pPacket – pointer to a wpt_packet
257 ppAddr – Caller allocated pointer to return the address of the item. For DMA-able devices, this is the physical address of the item.
258 pLen – To return the number of bytes in the item.
259 Return:
260 eWLAN_PAL_STATUS_SUCCESS - success
261---------------------------------------------------------------------------*/
262wpt_status wpalIteratorNext(wpt_iterator *pIter, wpt_packet *pPacket, void **ppAddr, wpt_uint32 *pLen);
263
264
265/*---------------------------------------------------------------------------
266 wpalLockPacketForTransfer – Packet must be locked before transfer can begin,
267 the lock will ensure that the DMA engine has access to the data packet
268 in a cache coherent manner
269
270 Param:
271 pPacket – pointer to a wpt_packet
272
273 Return:
274 eWLAN_PAL_STATUS_SUCCESS - success
275---------------------------------------------------------------------------*/
276wpt_status wpalLockPacketForTransfer( wpt_packet *pPacket);
277
278/*---------------------------------------------------------------------------
279 wpalUnlockPacket – Once the transfer has been completed the packet should
280 be unlocked so that normal operation may resume
281 Param:
282 pPacket – pointer to a wpt_packet
283
284 Return:
285 eWLAN_PAL_STATUS_SUCCESS - success
286---------------------------------------------------------------------------*/
287wpt_status wpalUnlockPacket( wpt_packet *pPacket);
288
289/*---------------------------------------------------------------------------
290 wpalPacketGetFragCount – Get count of memory chains (fragments)
291 in a packet
292 Param:
293 pPacket – pointer to a wpt_packet
294
295 Return:
296 memory fragment count in a packet
297---------------------------------------------------------------------------*/
298wpt_int32 wpalPacketGetFragCount(wpt_packet *pPkt);
299
300/*---------------------------------------------------------------------------
301 wpalIsPacketLocked – Check whether the Packet is locked for DMA.
302 Param:
303 pPacket – pointer to a wpt_packet
304
305 Return:
306 eWLAN_PAL_STATUS_SUCCESS
307 eWLAN_PAL_STATUS_E_FAILURE
308 eWLAN_PAL_STATUS_E_INVAL
309---------------------------------------------------------------------------*/
310wpt_status wpalIsPacketLocked( wpt_packet *pPacket);
311
312#endif // __WLAN_QCT_PAL_PACKET_H