]> Pileus Git - ~andy/linux/blob - drivers/staging/ath6kl/os/linux/netbuf.c
Merge branch 'next/board' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/linux...
[~andy/linux] / drivers / staging / ath6kl / os / linux / netbuf.c
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2004-2010 Atheros Communications Inc.
3 // All rights reserved.
4 //
5 // 
6 //
7 // Permission to use, copy, modify, and/or distribute this software for any
8 // purpose with or without fee is hereby granted, provided that the above
9 // copyright notice and this permission notice appear in all copies.
10 //
11 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 //
19 //
20 //
21 // Author(s): ="Atheros"
22 //------------------------------------------------------------------------------
23 #include <a_config.h>
24 #include "athdefs.h"
25 #include "a_osapi.h"
26 #include "htc_packet.h"
27
28 #define AR6000_DATA_OFFSET    64
29
30 void a_netbuf_enqueue(A_NETBUF_QUEUE_T *q, void *pkt)
31 {
32     skb_queue_tail((struct sk_buff_head *) q, (struct sk_buff *) pkt);
33 }
34
35 void a_netbuf_prequeue(A_NETBUF_QUEUE_T *q, void *pkt)
36 {
37     skb_queue_head((struct sk_buff_head *) q, (struct sk_buff *) pkt);
38 }
39
40 void *a_netbuf_dequeue(A_NETBUF_QUEUE_T *q)
41 {
42     return((void *) skb_dequeue((struct sk_buff_head *) q));
43 }
44
45 int a_netbuf_queue_size(A_NETBUF_QUEUE_T *q)
46 {
47     return(skb_queue_len((struct sk_buff_head *) q));
48 }
49
50 int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q)
51 {
52     return(skb_queue_empty((struct sk_buff_head *) q));
53 }
54
55 void a_netbuf_queue_init(A_NETBUF_QUEUE_T *q)
56 {
57     skb_queue_head_init((struct sk_buff_head *) q);
58 }
59
60 void *
61 a_netbuf_alloc(int size)
62 {
63     struct sk_buff *skb;
64     size += 2 * (A_GET_CACHE_LINE_BYTES()); /* add some cacheline space at front and back of buffer */
65     skb = dev_alloc_skb(AR6000_DATA_OFFSET + sizeof(struct htc_packet) + size);
66     skb_reserve(skb, AR6000_DATA_OFFSET + sizeof(struct htc_packet) + A_GET_CACHE_LINE_BYTES());    
67     return ((void *)skb);
68 }
69
70 /*
71  * Allocate an SKB w.o. any encapsulation requirement.
72  */
73 void *
74 a_netbuf_alloc_raw(int size)
75 {
76     struct sk_buff *skb;
77
78     skb = dev_alloc_skb(size);
79
80     return ((void *)skb);
81 }
82
83 void
84 a_netbuf_free(void *bufPtr)
85 {
86     struct sk_buff *skb = (struct sk_buff *)bufPtr;
87
88     dev_kfree_skb(skb);
89 }
90
91 u32 a_netbuf_to_len(void *bufPtr)
92 {
93     return (((struct sk_buff *)bufPtr)->len);
94 }
95
96 void *
97 a_netbuf_to_data(void *bufPtr)
98 {
99     return (((struct sk_buff *)bufPtr)->data);
100 }
101
102 /*
103  * Add len # of bytes to the beginning of the network buffer
104  * pointed to by bufPtr
105  */
106 int
107 a_netbuf_push(void *bufPtr, s32 len)
108 {
109     skb_push((struct sk_buff *)bufPtr, len);
110
111     return 0;
112 }
113
114 /*
115  * Add len # of bytes to the beginning of the network buffer
116  * pointed to by bufPtr and also fill with data
117  */
118 int
119 a_netbuf_push_data(void *bufPtr, char *srcPtr, s32 len)
120 {
121     skb_push((struct sk_buff *) bufPtr, len);
122     memcpy(((struct sk_buff *)bufPtr)->data, srcPtr, len);
123
124     return 0;
125 }
126
127 /*
128  * Add len # of bytes to the end of the network buffer
129  * pointed to by bufPtr
130  */
131 int
132 a_netbuf_put(void *bufPtr, s32 len)
133 {
134     skb_put((struct sk_buff *)bufPtr, len);
135
136     return 0;
137 }
138
139 /*
140  * Add len # of bytes to the end of the network buffer
141  * pointed to by bufPtr and also fill with data
142  */
143 int
144 a_netbuf_put_data(void *bufPtr, char *srcPtr, s32 len)
145 {
146     char *start = (char*)(((struct sk_buff *)bufPtr)->data +
147         ((struct sk_buff *)bufPtr)->len);
148     skb_put((struct sk_buff *)bufPtr, len);
149     memcpy(start, srcPtr, len);
150
151     return 0;
152 }
153
154
155 /*
156  * Trim the network buffer pointed to by bufPtr to len # of bytes 
157  */
158 int
159 a_netbuf_setlen(void *bufPtr, s32 len)
160 {
161     skb_trim((struct sk_buff *)bufPtr, len);
162
163     return 0;
164 }
165
166 /*
167  * Chop of len # of bytes from the end of the buffer.
168  */
169 int
170 a_netbuf_trim(void *bufPtr, s32 len)
171 {
172     skb_trim((struct sk_buff *)bufPtr, ((struct sk_buff *)bufPtr)->len - len);
173
174     return 0;
175 }
176
177 /*
178  * Chop of len # of bytes from the end of the buffer and return the data.
179  */
180 int
181 a_netbuf_trim_data(void *bufPtr, char *dstPtr, s32 len)
182 {
183     char *start = (char*)(((struct sk_buff *)bufPtr)->data +
184         (((struct sk_buff *)bufPtr)->len - len));
185     
186     memcpy(dstPtr, start, len);
187     skb_trim((struct sk_buff *)bufPtr, ((struct sk_buff *)bufPtr)->len - len);
188
189     return 0;
190 }
191
192
193 /*
194  * Returns the number of bytes available to a a_netbuf_push()
195  */
196 s32 a_netbuf_headroom(void *bufPtr)
197 {
198     return (skb_headroom((struct sk_buff *)bufPtr));
199 }
200
201 /*
202  * Removes specified number of bytes from the beginning of the buffer
203  */
204 int
205 a_netbuf_pull(void *bufPtr, s32 len)
206 {
207     skb_pull((struct sk_buff *)bufPtr, len);
208
209     return 0;
210 }
211
212 /*
213  * Removes specified number of bytes from the beginning of the buffer
214  * and return the data
215  */
216 int
217 a_netbuf_pull_data(void *bufPtr, char *dstPtr, s32 len)
218 {
219     memcpy(dstPtr, ((struct sk_buff *)bufPtr)->data, len);
220     skb_pull((struct sk_buff *)bufPtr, len);
221
222     return 0;
223 }
224
225 #ifdef EXPORT_HCI_BRIDGE_INTERFACE
226 EXPORT_SYMBOL(a_netbuf_to_data);
227 EXPORT_SYMBOL(a_netbuf_put);
228 EXPORT_SYMBOL(a_netbuf_pull);
229 EXPORT_SYMBOL(a_netbuf_alloc);
230 EXPORT_SYMBOL(a_netbuf_free);
231 #endif