2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted (subject to the limitations in the
7 * disclaimer below) provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
17 * * Neither the name of Qualcomm Atheros nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * (c) Copyright Atheros Communications
37 * FreeBSD specific prototypes
39 #ifndef _ADF_NBUF_PVT_H
40 #define _ADF_NBUF_PVT_H
43 //#include <Magpie_api.h>
45 //#include <adf_nbuf_api.h>
47 #define __ADF_NBUF_NULL NULL
48 #define __ADF_NBUF_CTX_BUF
50 typedef VBUF * __adf_nbuf_t;
55 typedef struct __adf_nbuf_qhead {
61 typedef __adf_nbuf_qhead_t __adf_nbuf_queue_t;
64 __adf_nbuf_alloc(adf_os_size_t size,
65 a_uint32_t reserve, a_uint32_t align);
68 __adf_nbuf_free(__adf_nbuf_t buf);
72 __adf_nbuf_push_head(__adf_nbuf_t buf, adf_os_size_t size);
75 __adf_nbuf_pull_head(__adf_nbuf_t buf, adf_os_size_t size);
78 __adf_nbuf_put_tail(__adf_nbuf_t buf, adf_os_size_t size);
82 __adf_nbuf_trim_tail(__adf_nbuf_t buf, adf_os_size_t size);
85 __adf_nbuf_realloc_headroom(__adf_nbuf_t buf,
89 __adf_nbuf_realloc_tailroom(__adf_nbuf_t buf,
93 __adf_nbuf_expand(__adf_nbuf_t buf,
94 a_uint32_t headroom, a_uint32_t tailroom);
97 __adf_nbuf_copy(__adf_nbuf_t src);
100 __adf_nbuf_unshare(__adf_nbuf_t src);
103 __adf_nbuf_frag_info(__adf_nbuf_t buf, adf_os_sglist_t *sg);
107 __adf_nbuf_get_priv(__adf_nbuf_t buf);
111 __adf_nbuf_queue_add(__adf_nbuf_qhead_t *qhead,
115 __adf_nbuf_queue_remove(__adf_nbuf_qhead_t *qhead);
118 __adf_nbuf_tx_cksum_info(__adf_nbuf_t buf,
123 __adf_nbuf_set_rx_cksum(__adf_nbuf_t buf, adf_nbuf_rx_cksum_t *cksum);
125 __adf_nbuf_get_tso_info(__adf_nbuf_t buf, adf_nbuf_tso_t *tso);
128 __adf_nbuf_get_vlan_info(adf_net_handle_t hdl,
130 adf_net_vlanhdr_t *vlan);
133 __adf_nbuf_dmamap_info(__adf_os_dma_map_t bmap, adf_os_dmamap_info_t *sg);
136 * @brief return the last mbuf
140 * @return struct mbuf*
144 __adf_nbuf_last(VBUF *buf);
148 * @brief num bytes in the head
152 * @return num of bytes available
156 __adf_nbuf_headroom(__adf_nbuf_t buf);
160 * @brief num of bytes available in the tail excluding the priv
165 * @return num of bytes
169 __adf_nbuf_tailroom(__adf_nbuf_t buf);
173 * @brief get the entire packet length
177 * @return total length of packet (sum of all frag lengths)
181 __adf_nbuf_len(__adf_nbuf_t buf);
185 * @brief Clone the nbuf (will not create writeable copies)
189 * @return Read-only copy of the nbuf (including clusters)
192 __adf_nbuf_clone(__adf_nbuf_t src);
195 __adf_nbuf_cat(__adf_nbuf_t dst, __adf_nbuf_t src);
199 * @brief check if the mbuf is cloned or not
206 __adf_nbuf_is_cloned(__adf_nbuf_t buf);
209 * @brief This will return the header's addr & m_len
213 __adf_nbuf_peek_header(__adf_nbuf_t buf, a_uint8_t **addr,
218 * @brief init the queue
222 __adf_nbuf_queue_init(__adf_nbuf_qhead_t *qhead);
225 * @brief return the length of queue
232 __adf_nbuf_queue_len(__adf_nbuf_qhead_t *qhead);
235 * @brief returns the first guy in the Q
238 * @return (NULL if the Q is empty)
242 __adf_nbuf_queue_first(__adf_nbuf_queue_t *qhead);
245 * @brief return the next packet from packet chain
247 * @param buf (packet)
249 * @return (NULL if no packets are there)
252 __adf_nbuf_queue_next(__adf_nbuf_t buf);
256 * @brief check if the queue is empty or not
263 __adf_nbuf_is_queue_empty(__adf_nbuf_qhead_t *qhead);
266 __adf_nbuf_create_frm_frag(__adf_nbuf_queue_t *head);
268 __adf_nbuf_split_to_frag(__adf_nbuf_t buf, __adf_nbuf_queue_t *qhead);
273 * @brief This will return the header's addr & m_len
276 __adf_nbuf_peek_header(__adf_nbuf_t buf, a_uint8_t **addr,
279 VDESC *desc = buf->desc_list;
281 *addr = desc->buf_addr + desc->data_offset;
282 *len = desc->data_size;
286 * @brief return the last mbuf
290 * @return struct mbuf*
292 static inline VDESC *
293 __adf_nbuf_last(VBUF *buf)
295 VDESC *desc = buf->desc_list;
297 //for(; desc->next_desc != NULL; desc = desc->next_desc)
299 while(desc->next_desc != NULL)
301 desc = desc->next_desc;
308 * @brief num bytes in the head
312 * @return num of bytes available
314 static inline a_uint32_t
315 __adf_nbuf_headroom(__adf_nbuf_t buf)
317 return buf->desc_list->data_offset;
321 * @brief num of bytes available in the tail excluding the priv
326 * @return num of bytes
329 static inline a_uint32_t
330 __adf_nbuf_tailroom(__adf_nbuf_t buf)
332 VDESC *last_desc = __adf_nbuf_last(buf);
334 return last_desc->buf_size - last_desc->data_offset - last_desc->data_size;
338 * @brief get the entire packet length
342 * @return total length of packet (sum of all frag lengths)
344 static inline a_uint32_t
345 __adf_nbuf_len(__adf_nbuf_t buf)
347 return buf->buf_length;
351 * @brief put data in the head
354 * @param len (how much data to put)
356 * @return new data pointer ,NULL if the len is more than the
357 * space available in the head frag.
359 static inline a_uint8_t *
360 __adf_nbuf_push_head(__adf_nbuf_t buf, adf_os_size_t len)
362 a_uint8_t *ptr = NULL;
363 VDESC *desc = buf->desc_list;
365 desc->data_offset -= len;
366 desc->data_size += len;
367 buf->buf_length += len;
368 ptr = desc->buf_addr + desc->data_offset;
374 * @brief add data in the end of tail
377 * @param len (how much data to put)
379 * @return previous tail (data+len),NULL if the len is more than
382 static inline a_uint8_t *
383 __adf_nbuf_put_tail(__adf_nbuf_t buf, adf_os_size_t len)
385 a_uint8_t *tail = NULL;
386 VDESC *last_desc = __adf_nbuf_last(buf);
388 tail = last_desc->buf_addr + last_desc->data_offset + last_desc->data_size;
389 last_desc->data_size += len;
390 buf->buf_length += len;
396 * @brief strip data from head
399 * @param len (how much data to rip)
401 * @return new data pointer
403 static inline a_uint8_t *
404 __adf_nbuf_pull_head(__adf_nbuf_t buf, adf_os_size_t len)
406 a_uint8_t *ptr = NULL;
407 VDESC *desc = buf->desc_list;
409 desc->data_offset += len;
410 desc->data_size -= len;
411 buf->buf_length -= len;
412 ptr = desc->buf_addr + desc->data_offset;
418 * @brief retrieve the priv space pointer from nbuf
420 * @param buf (nbuf to attach the priv space)
422 * @return uint8_t* ( pointer to the data )
424 static inline a_uint8_t *
425 __adf_nbuf_get_priv(__adf_nbuf_t buf)
427 //adf_os_assert(buf != NULL);
433 * @brief returns the first guy in the Q
436 * @return (NULL if the Q is empty)
438 static inline __adf_nbuf_t
439 __adf_nbuf_queue_first(__adf_nbuf_queue_t *qhead)
444 * @brief return the next packet from packet chain
446 * @param buf (packet)
448 * @return (NULL if no packets are there)
450 static inline __adf_nbuf_t
451 __adf_nbuf_queue_next(__adf_nbuf_t buf)
453 return buf->next_buf;