2 * (c) Copyright Atheros Communications
3 * FreeBSD specific prototypes
5 #ifndef _ADF_NBUF_PVT_H
6 #define _ADF_NBUF_PVT_H
9 //#include <Magpie_api.h>
11 //#include <adf_nbuf_api.h>
13 #define __ADF_NBUF_NULL NULL
14 #define __ADF_NBUF_CTX_BUF
16 typedef VBUF * __adf_nbuf_t;
21 typedef struct __adf_nbuf_qhead {
27 typedef __adf_nbuf_qhead_t __adf_nbuf_queue_t;
30 __adf_nbuf_alloc(adf_os_size_t size,
31 a_uint32_t reserve, a_uint32_t align);
34 __adf_nbuf_free(__adf_nbuf_t buf);
38 __adf_nbuf_push_head(__adf_nbuf_t buf, adf_os_size_t size);
41 __adf_nbuf_pull_head(__adf_nbuf_t buf, adf_os_size_t size);
44 __adf_nbuf_put_tail(__adf_nbuf_t buf, adf_os_size_t size);
48 __adf_nbuf_trim_tail(__adf_nbuf_t buf, adf_os_size_t size);
51 __adf_nbuf_realloc_headroom(__adf_nbuf_t buf,
55 __adf_nbuf_realloc_tailroom(__adf_nbuf_t buf,
59 __adf_nbuf_expand(__adf_nbuf_t buf,
60 a_uint32_t headroom, a_uint32_t tailroom);
63 __adf_nbuf_copy(__adf_nbuf_t src);
66 __adf_nbuf_unshare(__adf_nbuf_t src);
69 __adf_nbuf_frag_info(__adf_nbuf_t buf, adf_os_sglist_t *sg);
73 __adf_nbuf_get_priv(__adf_nbuf_t buf);
77 __adf_nbuf_queue_add(__adf_nbuf_qhead_t *qhead,
81 __adf_nbuf_queue_remove(__adf_nbuf_qhead_t *qhead);
84 __adf_nbuf_tx_cksum_info(__adf_nbuf_t buf,
89 __adf_nbuf_set_rx_cksum(__adf_nbuf_t buf, adf_nbuf_rx_cksum_t *cksum);
91 __adf_nbuf_get_tso_info(__adf_nbuf_t buf, adf_nbuf_tso_t *tso);
94 __adf_nbuf_get_vlan_info(adf_net_handle_t hdl,
96 adf_net_vlanhdr_t *vlan);
99 __adf_nbuf_dmamap_info(__adf_os_dma_map_t bmap, adf_os_dmamap_info_t *sg);
102 * @brief return the last mbuf
106 * @return struct mbuf*
110 __adf_nbuf_last(VBUF *buf);
114 * @brief num bytes in the head
118 * @return num of bytes available
122 __adf_nbuf_headroom(__adf_nbuf_t buf);
126 * @brief num of bytes available in the tail excluding the priv
131 * @return num of bytes
135 __adf_nbuf_tailroom(__adf_nbuf_t buf);
139 * @brief get the entire packet length
143 * @return total length of packet (sum of all frag lengths)
147 __adf_nbuf_len(__adf_nbuf_t buf);
151 * @brief Clone the nbuf (will not create writeable copies)
155 * @return Read-only copy of the nbuf (including clusters)
158 __adf_nbuf_clone(__adf_nbuf_t src);
161 __adf_nbuf_cat(__adf_nbuf_t dst, __adf_nbuf_t src);
165 * @brief check if the mbuf is cloned or not
172 __adf_nbuf_is_cloned(__adf_nbuf_t buf);
175 * @brief This will return the header's addr & m_len
179 __adf_nbuf_peek_header(__adf_nbuf_t buf, a_uint8_t **addr,
184 * @brief init the queue
188 __adf_nbuf_queue_init(__adf_nbuf_qhead_t *qhead);
191 * @brief return the length of queue
198 __adf_nbuf_queue_len(__adf_nbuf_qhead_t *qhead);
201 * @brief returns the first guy in the Q
204 * @return (NULL if the Q is empty)
208 __adf_nbuf_queue_first(__adf_nbuf_queue_t *qhead);
211 * @brief return the next packet from packet chain
213 * @param buf (packet)
215 * @return (NULL if no packets are there)
218 __adf_nbuf_queue_next(__adf_nbuf_t buf);
222 * @brief check if the queue is empty or not
229 __adf_nbuf_is_queue_empty(__adf_nbuf_qhead_t *qhead);
232 __adf_nbuf_create_frm_frag(__adf_nbuf_queue_t *head);
234 __adf_nbuf_split_to_frag(__adf_nbuf_t buf, __adf_nbuf_queue_t *qhead);
239 * @brief This will return the header's addr & m_len
242 __adf_nbuf_peek_header(__adf_nbuf_t buf, a_uint8_t **addr,
245 VDESC *desc = buf->desc_list;
247 *addr = desc->buf_addr + desc->data_offset;
248 *len = desc->data_size;
252 * @brief return the last mbuf
256 * @return struct mbuf*
258 static inline VDESC *
259 __adf_nbuf_last(VBUF *buf)
261 VDESC *desc = buf->desc_list;
263 //for(; desc->next_desc != NULL; desc = desc->next_desc)
265 while(desc->next_desc != NULL)
267 desc = desc->next_desc;
274 * @brief num bytes in the head
278 * @return num of bytes available
280 static inline a_uint32_t
281 __adf_nbuf_headroom(__adf_nbuf_t buf)
283 return buf->desc_list->data_offset;
287 * @brief num of bytes available in the tail excluding the priv
292 * @return num of bytes
295 static inline a_uint32_t
296 __adf_nbuf_tailroom(__adf_nbuf_t buf)
298 VDESC *last_desc = __adf_nbuf_last(buf);
300 return last_desc->buf_size - last_desc->data_offset - last_desc->data_size;
304 * @brief get the entire packet length
308 * @return total length of packet (sum of all frag lengths)
310 static inline a_uint32_t
311 __adf_nbuf_len(__adf_nbuf_t buf)
313 return buf->buf_length;
317 * @brief put data in the head
320 * @param len (how much data to put)
322 * @return new data pointer ,NULL if the len is more than the
323 * space available in the head frag.
325 static inline a_uint8_t *
326 __adf_nbuf_push_head(__adf_nbuf_t buf, adf_os_size_t len)
328 a_uint8_t *ptr = NULL;
329 VDESC *desc = buf->desc_list;
331 desc->data_offset -= len;
332 desc->data_size += len;
333 buf->buf_length += len;
334 ptr = desc->buf_addr + desc->data_offset;
340 * @brief add data in the end of tail
343 * @param len (how much data to put)
345 * @return previous tail (data+len),NULL if the len is more than
348 static inline a_uint8_t *
349 __adf_nbuf_put_tail(__adf_nbuf_t buf, adf_os_size_t len)
351 a_uint8_t *tail = NULL;
352 VDESC *last_desc = __adf_nbuf_last(buf);
354 tail = last_desc->buf_addr + last_desc->data_offset + last_desc->data_size;
355 last_desc->data_size += len;
356 buf->buf_length += len;
362 * @brief strip data from head
365 * @param len (how much data to rip)
367 * @return new data pointer
369 static inline a_uint8_t *
370 __adf_nbuf_pull_head(__adf_nbuf_t buf, adf_os_size_t len)
372 a_uint8_t *ptr = NULL;
373 VDESC *desc = buf->desc_list;
375 desc->data_offset += len;
376 desc->data_size -= len;
377 buf->buf_length -= len;
378 ptr = desc->buf_addr + desc->data_offset;
384 * @brief retrieve the priv space pointer from nbuf
386 * @param buf (nbuf to attach the priv space)
388 * @return uint8_t* ( pointer to the data )
390 static inline a_uint8_t *
391 __adf_nbuf_get_priv(__adf_nbuf_t buf)
393 //adf_os_assert(buf != NULL);
399 * @brief returns the first guy in the Q
402 * @return (NULL if the Q is empty)
404 static inline __adf_nbuf_t
405 __adf_nbuf_queue_first(__adf_nbuf_queue_t *qhead)
410 * @brief return the next packet from packet chain
412 * @param buf (packet)
414 * @return (NULL if no packets are there)
416 static inline __adf_nbuf_t
417 __adf_nbuf_queue_next(__adf_nbuf_t buf)
419 return buf->next_buf;