1 //------------------------------------------------------------------------------
2 // Copyright (c) 2004-2010 Atheros Communications Inc.
3 // All rights reserved.
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.
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.
21 // Author(s): ="Atheros"
22 //------------------------------------------------------------------------------
26 #include "htc_packet.h"
28 #define AR6000_DATA_OFFSET 64
30 void a_netbuf_enqueue(A_NETBUF_QUEUE_T *q, void *pkt)
32 skb_queue_tail((struct sk_buff_head *) q, (struct sk_buff *) pkt);
35 void a_netbuf_prequeue(A_NETBUF_QUEUE_T *q, void *pkt)
37 skb_queue_head((struct sk_buff_head *) q, (struct sk_buff *) pkt);
40 void *a_netbuf_dequeue(A_NETBUF_QUEUE_T *q)
42 return((void *) skb_dequeue((struct sk_buff_head *) q));
45 int a_netbuf_queue_size(A_NETBUF_QUEUE_T *q)
47 return(skb_queue_len((struct sk_buff_head *) q));
50 int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q)
52 return(skb_queue_empty((struct sk_buff_head *) q));
55 void a_netbuf_queue_init(A_NETBUF_QUEUE_T *q)
57 skb_queue_head_init((struct sk_buff_head *) q);
61 a_netbuf_alloc(int size)
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());
71 * Allocate an SKB w.o. any encapsulation requirement.
74 a_netbuf_alloc_raw(int size)
78 skb = dev_alloc_skb(size);
84 a_netbuf_free(void *bufPtr)
86 struct sk_buff *skb = (struct sk_buff *)bufPtr;
91 u32 a_netbuf_to_len(void *bufPtr)
93 return (((struct sk_buff *)bufPtr)->len);
97 a_netbuf_to_data(void *bufPtr)
99 return (((struct sk_buff *)bufPtr)->data);
103 * Add len # of bytes to the beginning of the network buffer
104 * pointed to by bufPtr
107 a_netbuf_push(void *bufPtr, s32 len)
109 skb_push((struct sk_buff *)bufPtr, len);
115 * Add len # of bytes to the beginning of the network buffer
116 * pointed to by bufPtr and also fill with data
119 a_netbuf_push_data(void *bufPtr, char *srcPtr, s32 len)
121 skb_push((struct sk_buff *) bufPtr, len);
122 memcpy(((struct sk_buff *)bufPtr)->data, srcPtr, len);
128 * Add len # of bytes to the end of the network buffer
129 * pointed to by bufPtr
132 a_netbuf_put(void *bufPtr, s32 len)
134 skb_put((struct sk_buff *)bufPtr, len);
140 * Add len # of bytes to the end of the network buffer
141 * pointed to by bufPtr and also fill with data
144 a_netbuf_put_data(void *bufPtr, char *srcPtr, s32 len)
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);
156 * Trim the network buffer pointed to by bufPtr to len # of bytes
159 a_netbuf_setlen(void *bufPtr, s32 len)
161 skb_trim((struct sk_buff *)bufPtr, len);
167 * Chop of len # of bytes from the end of the buffer.
170 a_netbuf_trim(void *bufPtr, s32 len)
172 skb_trim((struct sk_buff *)bufPtr, ((struct sk_buff *)bufPtr)->len - len);
178 * Chop of len # of bytes from the end of the buffer and return the data.
181 a_netbuf_trim_data(void *bufPtr, char *dstPtr, s32 len)
183 char *start = (char*)(((struct sk_buff *)bufPtr)->data +
184 (((struct sk_buff *)bufPtr)->len - len));
186 memcpy(dstPtr, start, len);
187 skb_trim((struct sk_buff *)bufPtr, ((struct sk_buff *)bufPtr)->len - len);
194 * Returns the number of bytes available to a a_netbuf_push()
196 s32 a_netbuf_headroom(void *bufPtr)
198 return (skb_headroom((struct sk_buff *)bufPtr));
202 * Removes specified number of bytes from the beginning of the buffer
205 a_netbuf_pull(void *bufPtr, s32 len)
207 skb_pull((struct sk_buff *)bufPtr, len);
213 * Removes specified number of bytes from the beginning of the buffer
214 * and return the data
217 a_netbuf_pull_data(void *bufPtr, char *dstPtr, s32 len)
219 memcpy(dstPtr, ((struct sk_buff *)bufPtr)->data, len);
220 skb_pull((struct sk_buff *)bufPtr, len);
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);