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