4 * Copyright (c) 2004-2007 Atheros Communications Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation;
12 * Software distributed under the License is distributed on an "AS
13 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * rights and limitations under the License.
20 #include <linux/kernel.h>
21 #include <linux/skbuff.h>
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 skb = dev_alloc_skb(AR6000_DATA_OFFSET + sizeof(HTC_PACKET) + size);
65 skb_reserve(skb, AR6000_DATA_OFFSET + sizeof(HTC_PACKET));
70 * Allocate an SKB w.o. any encapsulation requirement.
73 a_netbuf_alloc_raw(int size)
77 skb = dev_alloc_skb(size);
83 a_netbuf_free(void *bufPtr)
85 struct sk_buff *skb = (struct sk_buff *)bufPtr;
91 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, A_INT32 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, A_INT32 len)
121 skb_push((struct sk_buff *) bufPtr, len);
122 A_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, A_INT32 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, A_INT32 len)
146 char *start = ((struct sk_buff *)bufPtr)->data +
147 ((struct sk_buff *)bufPtr)->len;
148 skb_put((struct sk_buff *)bufPtr, len);
149 A_MEMCPY(start, srcPtr, len);
156 * Trim the network buffer pointed to by bufPtr to len # of bytes
159 a_netbuf_setlen(void *bufPtr, A_INT32 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, A_INT32 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, A_INT32 len)
183 char *start = ((struct sk_buff *)bufPtr)->data +
184 (((struct sk_buff *)bufPtr)->len - len);
186 A_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()
197 a_netbuf_headroom(void *bufPtr)
199 return (skb_headroom((struct sk_buff *)bufPtr));
203 * Removes specified number of bytes from the beginning of the buffer
206 a_netbuf_pull(void *bufPtr, A_INT32 len)
208 skb_pull((struct sk_buff *)bufPtr, len);
214 * Removes specified number of bytes from the beginning of the buffer
215 * and return the data
218 a_netbuf_pull_data(void *bufPtr, char *dstPtr, A_INT32 len)
220 A_MEMCPY(dstPtr, ((struct sk_buff *)bufPtr)->data, len);
221 skb_pull((struct sk_buff *)bufPtr, len);