1 /*
2 * wbuf.h
3 *
4 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name Texas Instruments nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34
35 /***************************************************************************/
36 /* */
37 /* MODULE: wbuf.h */
38 /* PURPOSE: manages the allocation/free and field access of the WBUF */
39 /* */
40 /***************************************************************************/
41 #ifndef _WBUF_H_
42 #define _WBUF_H_
43
44 #include <linux/version.h>
45 #include <linux/skbuff.h>
46 #include "tidef.h"
47 #include "queue.h"
48
49 typedef void WBUF;
50
51 /* Packet types */
52 typedef enum
53 {
54 TX_PKT_TYPE_MGMT = 0x01,
55 TX_PKT_TYPE_EAPOL = 0x02,
56 TX_PKT_TYPE_ETHER = 0x04, /* Data packets from the Network interface. */
57 TX_PKT_TYPE_WLAN_DATA = 0x08 /* Currently includes Null and IAPP packets. */
58 } TX_PKT_TYPE;
59
60 #define TX_PKT_FLAGS_LINK_TEST 0x1 /* Tx-Packet-Flag */
61 #define WSPI_PAD_BYTES 16 /* Add padding before data buffer for WSPI overhead */
62
63 /* user callback definition (in tx complete) */
64 typedef void *CB_ARG;
65 typedef void (*CB_FUNC)(CB_ARG cb_arg);
66
67 /*
68 * wbuf user fields:
69 */
70 typedef struct
71 {
72 TQueNodeHdr queNodeHdr; /* The header used for queueing the WBUF */
73 TX_PKT_TYPE pktType; /* wbuf packet type */
74 CB_FUNC cb_func; /* callback function to use in tx complete */
75 CB_ARG cb_arg; /* callback argument to use in tx complete */
76 TI_UINT8 Tid; /* WLAN TID (traffic identity) */
77 TI_UINT8 hdrLen; /* WLAN header length, not including alignment pad. */
78 TI_UINT8 flags; /* Some application flags, see Tx-Packet-Flags defs above. */
79 } WBUF_PARAMS;
80
81
82
83 #define WBUF_DATA(pWbuf) ( ((struct sk_buff *)(pWbuf))->data )
84 #define WBUF_LEN(pWbuf) ( ((struct sk_buff *)(pWbuf))->len )
85 #define WBUF_PRIORITY(pWbuf) ( ((struct sk_buff *)(pWbuf))->priority )
86 #define WBUF_DEV(pWbuf) ( ((struct sk_buff *)(pWbuf))->dev )
87 #define WBUF_DEV_SET(pWbuf,pDev) ( ((struct sk_buff *)(pWbuf))->dev) = ((struct net_device *)(pDev))
88 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
89 #define WBUF_STAMP(pWbuf) ( ((struct sk_buff *)(pWbuf))->tstamp.off_usec )
90 #else
91 #define WBUF_STAMP(pWbuf) ( ((struct sk_buff *)(pWbuf))->tstamp.tv.nsec )
92 #endif
93 #define WBUF_CB(pWbuf) ( ((struct sk_buff *)(pWbuf))->cb )
94 #define WBUF_PKT_TYPE(pWbuf) ( ((WBUF_PARAMS *)&(WBUF_CB(pWbuf)))->pktType )
95 #define WBUF_CB_FUNC(pWbuf) ( ((WBUF_PARAMS *)&(WBUF_CB(pWbuf)))->cb_func )
96 #define WBUF_CB_ARG(pWbuf) ( ((WBUF_PARAMS *)&(WBUF_CB(pWbuf)))->cb_arg )
97 #define WBUF_TID(pWbuf) ( ((WBUF_PARAMS *)&(WBUF_CB(pWbuf)))->Tid )
98 #define WBUF_HDR_LEN(pWbuf) ( ((WBUF_PARAMS *)&(WBUF_CB(pWbuf)))->hdrLen )
99 #define WBUF_FLAGS(pWbuf) ( ((WBUF_PARAMS *)&(WBUF_CB(pWbuf)))->flags )
100
101 /* The offset of the node-header field from the WBUF entry (for queueing) */
102 #define WBUF_NODE_HDR_OFFSET \
103 ( (unsigned long) &( ( (WBUF_PARAMS *) &( ( (struct sk_buff *)0 )->cb ) )->queNodeHdr ) )
104
105 /*
106 * Allocate WBUF for Tx/Rx packets.
107 * Add 16 bytes before the data buffer for WSPI overhead!
108 */
WbufAlloc(TI_HANDLE hOs,TI_UINT32 len)109 static inline WBUF *WbufAlloc (TI_HANDLE hOs, TI_UINT32 len)
110 {
111 gfp_t flags = (in_atomic()) ? GFP_ATOMIC : GFP_KERNEL;
112 WBUF *pWbuf = alloc_skb(len + WSPI_PAD_BYTES, flags);
113
114 if (!pWbuf)
115 {
116 return NULL;
117 }
118 WBUF_DATA (pWbuf) += WSPI_PAD_BYTES;
119 return pWbuf;
120 }
121
122 #define WbufFree(hOs, pWbuf) ( dev_kfree_skb((struct sk_buff *)pWbuf) )
123 #define WbufReserve(hOs, pWbuf,len) ( skb_reserve((struct sk_buff *)pWbuf,(int)len) )
124
125 #endif
126