Commit | Line | Data |
---|---|---|
30295c89 VM |
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 | //------------------------------------------------------------------------------ | |
30295c89 VM |
23 | #include <a_config.h> |
24 | #include "athdefs.h" | |
25 | #include "a_types.h" | |
26 | #include "a_osapi.h" | |
27 | #include "htc_packet.h" | |
28 | ||
29 | #define AR6000_DATA_OFFSET 64 | |
30 | ||
31 | void a_netbuf_enqueue(A_NETBUF_QUEUE_T *q, void *pkt) | |
32 | { | |
33 | skb_queue_tail((struct sk_buff_head *) q, (struct sk_buff *) pkt); | |
34 | } | |
35 | ||
36 | void a_netbuf_prequeue(A_NETBUF_QUEUE_T *q, void *pkt) | |
37 | { | |
38 | skb_queue_head((struct sk_buff_head *) q, (struct sk_buff *) pkt); | |
39 | } | |
40 | ||
41 | void *a_netbuf_dequeue(A_NETBUF_QUEUE_T *q) | |
42 | { | |
43 | return((void *) skb_dequeue((struct sk_buff_head *) q)); | |
44 | } | |
45 | ||
46 | int a_netbuf_queue_size(A_NETBUF_QUEUE_T *q) | |
47 | { | |
48 | return(skb_queue_len((struct sk_buff_head *) q)); | |
49 | } | |
50 | ||
51 | int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q) | |
52 | { | |
53 | return(skb_queue_empty((struct sk_buff_head *) q)); | |
54 | } | |
55 | ||
56 | void a_netbuf_queue_init(A_NETBUF_QUEUE_T *q) | |
57 | { | |
58 | skb_queue_head_init((struct sk_buff_head *) q); | |
59 | } | |
60 | ||
61 | void * | |
62 | a_netbuf_alloc(int size) | |
63 | { | |
64 | struct sk_buff *skb; | |
65 | size += 2 * (A_GET_CACHE_LINE_BYTES()); /* add some cacheline space at front and back of buffer */ | |
66 | skb = dev_alloc_skb(AR6000_DATA_OFFSET + sizeof(HTC_PACKET) + size); | |
67 | skb_reserve(skb, AR6000_DATA_OFFSET + sizeof(HTC_PACKET) + A_GET_CACHE_LINE_BYTES()); | |
68 | return ((void *)skb); | |
69 | } | |
70 | ||
71 | /* | |
72 | * Allocate an SKB w.o. any encapsulation requirement. | |
73 | */ | |
74 | void * | |
75 | a_netbuf_alloc_raw(int size) | |
76 | { | |
77 | struct sk_buff *skb; | |
78 | ||
79 | skb = dev_alloc_skb(size); | |
80 | ||
81 | return ((void *)skb); | |
82 | } | |
83 | ||
84 | void | |
85 | a_netbuf_free(void *bufPtr) | |
86 | { | |
87 | struct sk_buff *skb = (struct sk_buff *)bufPtr; | |
88 | ||
89 | dev_kfree_skb(skb); | |
90 | } | |
91 | ||
e1ce2a3a | 92 | u32 a_netbuf_to_len(void *bufPtr) |
30295c89 VM |
93 | { |
94 | return (((struct sk_buff *)bufPtr)->len); | |
95 | } | |
96 | ||
97 | void * | |
98 | a_netbuf_to_data(void *bufPtr) | |
99 | { | |
100 | return (((struct sk_buff *)bufPtr)->data); | |
101 | } | |
102 | ||
103 | /* | |
104 | * Add len # of bytes to the beginning of the network buffer | |
105 | * pointed to by bufPtr | |
106 | */ | |
1f4c34bd | 107 | int |
f68057e6 | 108 | a_netbuf_push(void *bufPtr, s32 len) |
30295c89 VM |
109 | { |
110 | skb_push((struct sk_buff *)bufPtr, len); | |
111 | ||
4f69cef0 | 112 | return 0; |
30295c89 VM |
113 | } |
114 | ||
115 | /* | |
116 | * Add len # of bytes to the beginning of the network buffer | |
117 | * pointed to by bufPtr and also fill with data | |
118 | */ | |
1f4c34bd | 119 | int |
f68057e6 | 120 | a_netbuf_push_data(void *bufPtr, char *srcPtr, s32 len) |
30295c89 VM |
121 | { |
122 | skb_push((struct sk_buff *) bufPtr, len); | |
05209262 | 123 | memcpy(((struct sk_buff *)bufPtr)->data, srcPtr, len); |
30295c89 | 124 | |
4f69cef0 | 125 | return 0; |
30295c89 VM |
126 | } |
127 | ||
128 | /* | |
129 | * Add len # of bytes to the end of the network buffer | |
130 | * pointed to by bufPtr | |
131 | */ | |
1f4c34bd | 132 | int |
f68057e6 | 133 | a_netbuf_put(void *bufPtr, s32 len) |
30295c89 VM |
134 | { |
135 | skb_put((struct sk_buff *)bufPtr, len); | |
136 | ||
4f69cef0 | 137 | return 0; |
30295c89 VM |
138 | } |
139 | ||
140 | /* | |
141 | * Add len # of bytes to the end of the network buffer | |
142 | * pointed to by bufPtr and also fill with data | |
143 | */ | |
1f4c34bd | 144 | int |
f68057e6 | 145 | a_netbuf_put_data(void *bufPtr, char *srcPtr, s32 len) |
30295c89 VM |
146 | { |
147 | char *start = (char*)(((struct sk_buff *)bufPtr)->data + | |
148 | ((struct sk_buff *)bufPtr)->len); | |
149 | skb_put((struct sk_buff *)bufPtr, len); | |
05209262 | 150 | memcpy(start, srcPtr, len); |
30295c89 | 151 | |
4f69cef0 | 152 | return 0; |
30295c89 VM |
153 | } |
154 | ||
155 | ||
156 | /* | |
157 | * Trim the network buffer pointed to by bufPtr to len # of bytes | |
158 | */ | |
1f4c34bd | 159 | int |
f68057e6 | 160 | a_netbuf_setlen(void *bufPtr, s32 len) |
30295c89 VM |
161 | { |
162 | skb_trim((struct sk_buff *)bufPtr, len); | |
163 | ||
4f69cef0 | 164 | return 0; |
30295c89 VM |
165 | } |
166 | ||
167 | /* | |
168 | * Chop of len # of bytes from the end of the buffer. | |
169 | */ | |
1f4c34bd | 170 | int |
f68057e6 | 171 | a_netbuf_trim(void *bufPtr, s32 len) |
30295c89 VM |
172 | { |
173 | skb_trim((struct sk_buff *)bufPtr, ((struct sk_buff *)bufPtr)->len - len); | |
174 | ||
4f69cef0 | 175 | return 0; |
30295c89 VM |
176 | } |
177 | ||
178 | /* | |
179 | * Chop of len # of bytes from the end of the buffer and return the data. | |
180 | */ | |
1f4c34bd | 181 | int |
f68057e6 | 182 | a_netbuf_trim_data(void *bufPtr, char *dstPtr, s32 len) |
30295c89 VM |
183 | { |
184 | char *start = (char*)(((struct sk_buff *)bufPtr)->data + | |
185 | (((struct sk_buff *)bufPtr)->len - len)); | |
186 | ||
05209262 | 187 | memcpy(dstPtr, start, len); |
30295c89 VM |
188 | skb_trim((struct sk_buff *)bufPtr, ((struct sk_buff *)bufPtr)->len - len); |
189 | ||
4f69cef0 | 190 | return 0; |
30295c89 VM |
191 | } |
192 | ||
193 | ||
194 | /* | |
195 | * Returns the number of bytes available to a a_netbuf_push() | |
196 | */ | |
f68057e6 | 197 | s32 a_netbuf_headroom(void *bufPtr) |
30295c89 VM |
198 | { |
199 | return (skb_headroom((struct sk_buff *)bufPtr)); | |
200 | } | |
201 | ||
202 | /* | |
203 | * Removes specified number of bytes from the beginning of the buffer | |
204 | */ | |
1f4c34bd | 205 | int |
f68057e6 | 206 | a_netbuf_pull(void *bufPtr, s32 len) |
30295c89 VM |
207 | { |
208 | skb_pull((struct sk_buff *)bufPtr, len); | |
209 | ||
4f69cef0 | 210 | return 0; |
30295c89 VM |
211 | } |
212 | ||
213 | /* | |
214 | * Removes specified number of bytes from the beginning of the buffer | |
215 | * and return the data | |
216 | */ | |
1f4c34bd | 217 | int |
f68057e6 | 218 | a_netbuf_pull_data(void *bufPtr, char *dstPtr, s32 len) |
30295c89 | 219 | { |
05209262 | 220 | memcpy(dstPtr, ((struct sk_buff *)bufPtr)->data, len); |
30295c89 VM |
221 | skb_pull((struct sk_buff *)bufPtr, len); |
222 | ||
4f69cef0 | 223 | return 0; |
30295c89 VM |
224 | } |
225 | ||
226 | #ifdef EXPORT_HCI_BRIDGE_INTERFACE | |
227 | EXPORT_SYMBOL(a_netbuf_to_data); | |
228 | EXPORT_SYMBOL(a_netbuf_put); | |
229 | EXPORT_SYMBOL(a_netbuf_pull); | |
230 | EXPORT_SYMBOL(a_netbuf_alloc); | |
231 | EXPORT_SYMBOL(a_netbuf_free); | |
232 | #endif |