eaafa900a3f5be44177fb27d2b8580d588c7c130
[madwifi/.git] / net80211 / ieee80211_skb.h
1 /*-
2  * Copyright (c) 2007 Michael Taylor, Apprion
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * $Id: ieee80211_skb.h 2647 2007-08-09 08:43:58Z mtaylor $
28  */
29 #ifndef _NET80211_IEEE80211_SKB_H_
30 #define _NET80211_IEEE80211_SKB_H_
31
32 /*******************************************************************************
33  * Globals
34  ******************************************************************************/
35
36 #ifdef IEEE80211_DEBUG_REFCNT
37
38 /* Count of currently tracked skbs */
39 extern atomic_t skb_total_counter;
40 /* Count of currently tracked skbs' references */
41 extern atomic_t skb_refs_counter;
42
43 #endif /* #ifdef IEEE80211_DEBUG_REFCNT */
44
45 /*******************************************************************************
46  * Public API
47  ******************************************************************************/
48
49 /* SKB_XX(...) macros will blow up if _skb is NULL (detect problems early) */
50 #define SKB_CB(_skb)            ((struct ieee80211_cb *)(_skb)->cb)
51 #define SKB_NI(_skb)            (SKB_CB(_skb)->ni)
52
53 #define M_FLAG_SET(_skb, _flag) \
54         (SKB_CB(_skb)->flags |= (_flag))
55 #define M_FLAG_CLR(_skb, _flag) \
56         (SKB_CB(_skb)->flags &= ~(_flag))
57 #define M_FLAG_GET(_skb, _flag) \
58         (SKB_CB(_skb)->flags & (_flag))
59 #define M_FLAG_KEEP_ONLY(_skb, _flag) \
60         (SKB_CB(_skb)->flags &= (_flag))
61
62 #define M_PWR_SAV_SET(skb) M_FLAG_SET((skb), M_PWR_SAV)
63 #define M_PWR_SAV_CLR(skb) M_FLAG_CLR((skb), M_PWR_SAV)
64 #define M_PWR_SAV_GET(skb) M_FLAG_GET((skb), M_PWR_SAV)
65
66 /* SKBs on the power save queue are tagged with an age and
67  * timed out.  We reuse the hardware checksum field in the
68  * mbuf packet header to store this data.
69  * XXX: use private CB area. */
70 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
71 #define skb_age csum_offset
72 #else
73 #define skb_age csum
74 #endif
75
76 #define M_AGE_SET(_skb,_v)      ((_skb)->skb_age = (_v))
77 #define M_AGE_GET(_skb)         ((_skb)->skb_age)
78 #define M_AGE_SUB(_skb,_adj)    ((_skb)->skb_age -= (_adj))
79
80 /* ieee80211_dev_kfree_skb will release one reference from SKB.
81  * If SKB refcount is going to zero:
82  *  - Free the node reference and set it to null.
83  *  - Break the linked list, clearing next skb's prev pointer if possible. */
84 void ieee80211_dev_kfree_skb(struct sk_buff **pskb);
85
86 static inline void ieee80211_skb_copy_noderef(struct sk_buff *src, 
87                 struct sk_buff *dst)
88 {
89         if (SKB_NI(src) != NULL)
90                 SKB_NI(dst) = ieee80211_ref_node(SKB_NI(src));
91 }
92
93 /* ieee80211_dev_kfree_skb_list will invoke ieee80211_dev_kfree_skb on each node in
94  * a list of skbs, starting with the first. */
95 void ieee80211_dev_kfree_skb_list(struct sk_buff **pskb);
96
97 struct sk_buff *ieee80211_dev_alloc_skb(int size);
98
99 void ieee80211_skb_track(struct sk_buff *skb);
100 void ieee80211_skb_untrack(struct sk_buff *skb);
101
102 #ifdef IEEE80211_DEBUG_REFCNT
103 int ieee80211_skb_counter(void);
104 int ieee80211_skb_references(void);
105 #else
106 #define ieee80211_skb_counter() (0)
107 #define ieee80211_skb_references() (0)
108 #endif
109
110 /*******************************************************************************
111  * skbuff leak/refcount debugging Replacement Functions
112  ******************************************************************************/
113
114 #ifdef IEEE80211_DEBUG_REFCNT
115
116 int vlan_hwaccel_rx_debug(struct sk_buff *skb, struct vlan_group *grp,
117                 unsigned short vlan_tag, const char *func, int line);
118 int netif_rx_debug(struct sk_buff *skb, const char *func, int line);
119 struct sk_buff *alloc_skb_debug(unsigned int length, gfp_t gfp_mask,
120                 const char *func, int line);
121 struct sk_buff *dev_alloc_skb_debug(unsigned int length,
122                 const char *func, int line);
123 struct sk_buff *skb_clone_debug(struct sk_buff *skb, gfp_t pri, 
124                 const char *func, int line);
125 struct sk_buff *skb_copy_debug(struct sk_buff *skb, gfp_t pri, 
126                 const char *func, int line);
127 struct sk_buff *skb_get_debug(struct sk_buff *skb, 
128                 const char *func, int line);
129 struct sk_buff *skb_realloc_headroom_debug(struct sk_buff *skb, unsigned int headroom, 
130                 const char *func, int line);
131 struct sk_buff *pskb_copy_debug(struct sk_buff *skb, gfp_t pri,
132                 const char *func, int line);
133 int dev_queue_xmit_debug(struct sk_buff *skb,
134                 const char *func, int line);
135 struct sk_buff *skb_share_check_debug(struct sk_buff *skb, gfp_t pri,
136                 const char *func, int line);
137 void kfree_skb_fast_debug(struct sk_buff *skb, 
138                 const char *func, int line);
139 struct sk_buff *skb_unshare_debug(struct sk_buff *skb, gfp_t pri,
140                 const char *func, int line);
141 struct sk_buff *skb_copy_expand_debug(const struct sk_buff *skb, int newheadroom, 
142                 int newtailroom, gfp_t gfp_mask, 
143                 const char *func, int line);
144
145 #undef alloc_skb
146 #undef dev_alloc_skb
147 #undef dev_kfree_skb
148 #undef dev_kfree_skb_any
149 #undef dev_kfree_skb_irq
150 #undef dev_queue_xmit
151 #undef kfree_skb
152 #undef kfree_skb_fast
153 #undef netif_rx
154 #undef pskb_copy
155 #undef skb_clone
156 #undef skb_copy
157 #undef skb_copy_expand
158 #undef skb_get
159 #undef skb_realloc_headroom
160 #undef skb_share_check
161 #undef skb_unshare
162 #undef vlan_hwaccel_rx
163
164 #define skb_unshare(_skb, _pri) \
165         skb_unshare_debug(_skb, _pri, __func__, __LINE__)
166 #define skb_copy_expand(_skb, _newheadroom, _newtailroom, _gfp_mask) \
167         skb_copy_expand_debug(_skb, _newheadroom, _newtailroom, _gfp_mask, __func__, __LINE__)
168 #define vlan_hwaccel_rx(_skb, _grp, _tag) \
169         vlan_hwaccel_rx_debug(_skb, _grp, _tag, __func__, __LINE__)
170 #define netif_rx(_skb) \
171         netif_rx_debug(_skb, __func__, __LINE__)
172 #define alloc_skb(_length, _gfp_mask) \
173         alloc_skb_debug(_length, _gfp_mask, __func__, __LINE__)
174 #define dev_alloc_skb(_length) \
175         dev_alloc_skb_debug(_length, __func__, __LINE__)
176 #define dev_kfree_skb_irq(_skb) \
177         unref_skb(_skb, UNREF_USE_DEV_KFREE_SKB_IRQ, __func__, __LINE__)
178 #define dev_kfree_skb_any(_skb) \
179         unref_skb(_skb, UNREF_USE_DEV_KFREE_SKB_ANY, __func__, __LINE__)
180 #define dev_kfree_skb(_skb) \
181         unref_skb(_skb, UNREF_USE_DEV_KFREE_SKB, __func__, __LINE__)
182 #define kfree_skb(_skb) \
183         unref_skb(_skb, UNREF_USE_KFREE_SKB, __func__, __LINE__)
184 #define skb_clone(_skb, _pri) \
185         skb_clone_debug(_skb, _pri, __func__, __LINE__)
186 #define skb_share_check(_skb, _pri) \
187         skb_share_check_debug(_skb, _pri, __func__, __LINE__)
188 #define kfree_skb_fast(_skb) \
189         kfree_skb_fast_debug(_skb, __func__, __LINE__)
190 #define skb_realloc_headroom(_skb, _headroom) \
191         skb_realloc_headroom_debug(_skb, _headroom, __func__, __LINE__)
192 #define pskb_copy(_skb, _pri) \
193         pskb_copy_debug(_skb, _pri, __func__, __LINE__)
194 #define skb_get(_skb) \
195         skb_get_debug(_skb, __func__, __LINE__)
196 #define skb_copy(_skb, _pri) \
197         skb_copy_debug(_skb, _pri, __func__, __LINE__)
198 #define dev_queue_xmit(_skb) \
199         dev_queue_xmit_debug(_skb, __func__, __LINE__)
200 #endif /* #ifdef IEEE80211_DEBUG_REFCNT */
201
202 #endif /* _NET80211_IEEE80211_SKB_H_ */
203