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 //------------------------------------------------------------------------------
27 #include "htc_packet.h"
29 #define AR6000_DATA_OFFSET 64
31 void a_netbuf_enqueue(A_NETBUF_QUEUE_T *q, void *pkt)
33 skb_queue_tail((struct sk_buff_head *) q, (struct sk_buff *) pkt);
36 void a_netbuf_prequeue(A_NETBUF_QUEUE_T *q, void *pkt)
38 skb_queue_head((struct sk_buff_head *) q, (struct sk_buff *) pkt);
41 void *a_netbuf_dequeue(A_NETBUF_QUEUE_T *q)
43 return((void *) skb_dequeue((struct sk_buff_head *) q));
46 int a_netbuf_queue_size(A_NETBUF_QUEUE_T *q)
48 return(skb_queue_len((struct sk_buff_head *) q));
51 int a_netbuf_queue_empty(A_NETBUF_QUEUE_T *q)
53 return(skb_queue_empty((struct sk_buff_head *) q));
56 void a_netbuf_queue_init(A_NETBUF_QUEUE_T *q)
58 skb_queue_head_init((struct sk_buff_head *) q);
62 a_netbuf_alloc(int size)
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());
72 * Allocate an SKB w.o. any encapsulation requirement.
75 a_netbuf_alloc_raw(int size)
79 skb = dev_alloc_skb(size);
85 a_netbuf_free(void *bufPtr)
87 struct sk_buff *skb = (struct sk_buff *)bufPtr;
93 a_netbuf_to_len(void *bufPtr)
95 return (((struct sk_buff *)bufPtr)->len);
99 a_netbuf_to_data(void *bufPtr)
101 return (((struct sk_buff *)bufPtr)->data);
105 * Add len # of bytes to the beginning of the network buffer
106 * pointed to by bufPtr
109 a_netbuf_push(void *bufPtr, A_INT32 len)
111 skb_push((struct sk_buff *)bufPtr, len);
117 * Add len # of bytes to the beginning of the network buffer
118 * pointed to by bufPtr and also fill with data
121 a_netbuf_push_data(void *bufPtr, char *srcPtr, A_INT32 len)
123 skb_push((struct sk_buff *) bufPtr, len);
124 A_MEMCPY(((struct sk_buff *)bufPtr)->data, srcPtr, len);
130 * Add len # of bytes to the end of the network buffer
131 * pointed to by bufPtr
134 a_netbuf_put(void *bufPtr, A_INT32 len)
136 skb_put((struct sk_buff *)bufPtr, len);
142 * Add len # of bytes to the end of the network buffer
143 * pointed to by bufPtr and also fill with data
146 a_netbuf_put_data(void *bufPtr, char *srcPtr, A_INT32 len)
148 char *start = (char*)(((struct sk_buff *)bufPtr)->data +
149 ((struct sk_buff *)bufPtr)->len);
150 skb_put((struct sk_buff *)bufPtr, len);
151 A_MEMCPY(start, srcPtr, len);
158 * Trim the network buffer pointed to by bufPtr to len # of bytes
161 a_netbuf_setlen(void *bufPtr, A_INT32 len)
163 skb_trim((struct sk_buff *)bufPtr, len);
169 * Chop of len # of bytes from the end of the buffer.
172 a_netbuf_trim(void *bufPtr, A_INT32 len)
174 skb_trim((struct sk_buff *)bufPtr, ((struct sk_buff *)bufPtr)->len - len);
180 * Chop of len # of bytes from the end of the buffer and return the data.
183 a_netbuf_trim_data(void *bufPtr, char *dstPtr, A_INT32 len)
185 char *start = (char*)(((struct sk_buff *)bufPtr)->data +
186 (((struct sk_buff *)bufPtr)->len - len));
188 A_MEMCPY(dstPtr, start, len);
189 skb_trim((struct sk_buff *)bufPtr, ((struct sk_buff *)bufPtr)->len - len);
196 * Returns the number of bytes available to a a_netbuf_push()
199 a_netbuf_headroom(void *bufPtr)
201 return (skb_headroom((struct sk_buff *)bufPtr));
205 * Removes specified number of bytes from the beginning of the buffer
208 a_netbuf_pull(void *bufPtr, A_INT32 len)
210 skb_pull((struct sk_buff *)bufPtr, len);
216 * Removes specified number of bytes from the beginning of the buffer
217 * and return the data
220 a_netbuf_pull_data(void *bufPtr, char *dstPtr, A_INT32 len)
222 A_MEMCPY(dstPtr, ((struct sk_buff *)bufPtr)->data, len);
223 skb_pull((struct sk_buff *)bufPtr, len);
228 #ifdef EXPORT_HCI_BRIDGE_INTERFACE
229 EXPORT_SYMBOL(a_netbuf_to_data);
230 EXPORT_SYMBOL(a_netbuf_put);
231 EXPORT_SYMBOL(a_netbuf_pull);
232 EXPORT_SYMBOL(a_netbuf_alloc);
233 EXPORT_SYMBOL(a_netbuf_free);