Setting up repository
[linux-libre-firmware.git] / ath9k_htc / sboot / magpie_1_1 / sboot / adf / nbuf / inc / adf_nbuf_pvt.h
1 /*
2  * Copyright (c) 2013 Qualcomm Atheros, Inc.
3  * All rights reserved.
4  *
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:
8  *
9  *  * Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
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
15  *    distribution.
16  *
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.
20  *
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.
34  */
35 /*
36  * (c) Copyright Atheros Communications
37  *  FreeBSD specific prototypes 
38  */
39 #ifndef _ADF_NBUF_PVT_H
40 #define _ADF_NBUF_PVT_H
41
42 #include <osapi.h>
43 //#include <Magpie_api.h>
44 #include <vbuf_api.h>
45 //#include <adf_nbuf_api.h>
46
47 #define __ADF_NBUF_NULL         NULL
48 #define __ADF_NBUF_CTX_BUF      
49
50 typedef VBUF *     __adf_nbuf_t;
51
52 /**
53  * queue head
54  */
55 typedef struct __adf_nbuf_qhead {
56     VBUF             *head;
57     VBUF             *tail;    
58     a_uint32_t        qlen;
59 }__adf_nbuf_qhead_t;
60
61 typedef __adf_nbuf_qhead_t         __adf_nbuf_queue_t;
62
63 __adf_nbuf_t 
64 __adf_nbuf_alloc(adf_os_size_t size, 
65                  a_uint32_t reserve, a_uint32_t align);                                
66
67 void 
68 __adf_nbuf_free(__adf_nbuf_t  buf);
69
70 #ifndef _ROM_
71 a_uint8_t *   
72 __adf_nbuf_push_head(__adf_nbuf_t buf, adf_os_size_t size);
73  
74 a_uint8_t *    
75 __adf_nbuf_pull_head(__adf_nbuf_t buf, adf_os_size_t size);
76
77 a_uint8_t *    
78 __adf_nbuf_put_tail(__adf_nbuf_t buf, adf_os_size_t size);
79 #endif
80
81 void         
82 __adf_nbuf_trim_tail(__adf_nbuf_t buf, adf_os_size_t size);
83
84 __adf_nbuf_t 
85 __adf_nbuf_realloc_headroom(__adf_nbuf_t buf,
86                             a_uint32_t headroom);                           
87                             
88 __adf_nbuf_t 
89 __adf_nbuf_realloc_tailroom(__adf_nbuf_t buf, 
90                             a_uint32_t tailroom);
91                                                 
92 __adf_nbuf_t 
93 __adf_nbuf_expand(__adf_nbuf_t buf,
94                                a_uint32_t headroom, a_uint32_t tailroom);
95                                                                                
96 __adf_nbuf_t 
97 __adf_nbuf_copy(__adf_nbuf_t src);
98
99 __adf_nbuf_t 
100 __adf_nbuf_unshare(__adf_nbuf_t  src);
101
102 void         
103 __adf_nbuf_frag_info(__adf_nbuf_t buf, adf_os_sglist_t *sg);
104
105 #ifndef _ROM_
106 a_uint8_t *    
107 __adf_nbuf_get_priv(__adf_nbuf_t buf);
108 #endif
109
110 void         
111 __adf_nbuf_queue_add(__adf_nbuf_qhead_t *qhead, 
112                      __adf_nbuf_t buf);
113                                   
114 __adf_nbuf_t 
115 __adf_nbuf_queue_remove(__adf_nbuf_qhead_t *qhead);
116
117 a_uint32_t     
118 __adf_nbuf_tx_cksum_info(__adf_nbuf_t buf, 
119                          a_uint8_t **hdr_off, 
120                          a_uint8_t **where);
121                                       
122 void         
123 __adf_nbuf_set_rx_cksum(__adf_nbuf_t buf, adf_nbuf_rx_cksum_t *cksum);
124 void         
125 __adf_nbuf_get_tso_info(__adf_nbuf_t buf, adf_nbuf_tso_t *tso);
126
127 a_status_t   
128 __adf_nbuf_get_vlan_info(adf_net_handle_t hdl, 
129                                       __adf_nbuf_t buf, 
130                                       adf_net_vlanhdr_t *vlan);                                                                                                
131                                        
132 void         
133 __adf_nbuf_dmamap_info(__adf_os_dma_map_t bmap, adf_os_dmamap_info_t *sg);
134
135 /**
136  * @brief return the last mbuf
137  * 
138  * @param m0
139  * 
140  * @return struct mbuf*
141  */
142 #ifndef _ROM_
143 VDESC * 
144 __adf_nbuf_last(VBUF *buf);
145 #endif
146
147 /**
148  * @brief num bytes in the head
149  * 
150  * @param adf_nbuf
151  * 
152  * @return num of bytes available
153  */
154 #ifndef _ROM_
155 a_uint32_t
156 __adf_nbuf_headroom(__adf_nbuf_t  buf);
157 #endif
158
159 /**
160  * @brief num of bytes available in the tail excluding the priv
161  *        portion
162  * 
163  * @param adf_nbuf
164  * 
165  * @return num of bytes
166  */
167 #ifndef _ROM_
168 a_uint32_t 
169 __adf_nbuf_tailroom(__adf_nbuf_t  buf);
170 #endif
171
172 /**
173  * @brief get the entire packet length
174  * 
175  * @param adf_nbuf
176  * 
177  * @return total length of packet (sum of all frag lengths)
178  */ 
179 #ifndef _ROM_
180 a_uint32_t
181 __adf_nbuf_len(__adf_nbuf_t  buf);
182 #endif
183
184 /**
185  * @brief Clone the nbuf (will not create writeable copies)
186  * 
187  * @param adf_nbuf
188  * 
189  * @return Read-only copy of the nbuf (including clusters)
190  */
191 __adf_nbuf_t 
192 __adf_nbuf_clone(__adf_nbuf_t  src);
193
194 void
195 __adf_nbuf_cat(__adf_nbuf_t dst, __adf_nbuf_t src);
196
197
198 /*
199  * @brief check if the mbuf is cloned or not
200  * 
201  * @param buf
202  * 
203  * @return a_bool_t
204  */
205 a_bool_t
206 __adf_nbuf_is_cloned(__adf_nbuf_t  buf);
207
208 /**
209  * @brief This will return the header's addr & m_len
210  */
211 #ifndef _ROM_
212 void
213 __adf_nbuf_peek_header(__adf_nbuf_t buf, a_uint8_t   **addr, 
214                        a_uint32_t       *len);
215 #endif
216
217 /**
218  * @brief init the queue
219  * @param qhead
220  */
221 void 
222 __adf_nbuf_queue_init(__adf_nbuf_qhead_t *qhead);
223
224 /**
225  * @brief return the length of queue
226  * @param adf_qhead
227  * 
228  * @return length
229  * 
230  */
231 a_uint32_t  
232 __adf_nbuf_queue_len(__adf_nbuf_qhead_t *qhead);
233
234 /**
235  * @brief returns the first guy in the Q
236  * @param qhead
237  * 
238  * @return (NULL if the Q is empty)
239  */
240 #ifndef _ROM_
241 __adf_nbuf_t   
242 __adf_nbuf_queue_first(__adf_nbuf_queue_t *qhead);
243
244 /**
245  * @brief return the next packet from packet chain
246  * 
247  * @param buf (packet)
248  * 
249  * @return (NULL if no packets are there)
250  */
251 __adf_nbuf_t   
252 __adf_nbuf_queue_next(__adf_nbuf_t  buf);
253 #endif
254
255 /**
256  * @brief check if the queue is empty or not
257  * 
258  * @param qhead
259  * 
260  * @return a_bool_t
261  */
262 a_bool_t  
263 __adf_nbuf_is_queue_empty(__adf_nbuf_qhead_t *qhead);
264
265 __adf_nbuf_t
266 __adf_nbuf_create_frm_frag(__adf_nbuf_queue_t *head);
267 void
268 __adf_nbuf_split_to_frag(__adf_nbuf_t buf, __adf_nbuf_queue_t *qhead);
269
270 #ifdef _ROM_
271
272 /**
273  * @brief This will return the header's addr & m_len
274  */
275 static inline void
276 __adf_nbuf_peek_header(__adf_nbuf_t buf, a_uint8_t   **addr, 
277                        a_uint32_t       *len)
278 {
279     VDESC *desc = buf->desc_list;
280     
281     *addr = desc->buf_addr + desc->data_offset;
282     *len = desc->data_size; 
283 }
284
285 /**
286  * @brief return the last mbuf
287  * 
288  * @param m0
289  * 
290  * @return struct mbuf*
291  */
292 static inline VDESC * 
293 __adf_nbuf_last(VBUF *buf)
294 {
295     VDESC *desc = buf->desc_list;
296     
297     //for(; desc->next_desc != NULL; desc = desc->next_desc)
298     //    ;
299     while(desc->next_desc != NULL)
300     {
301         desc = desc->next_desc;
302     }
303     
304     return desc;
305 }
306
307 /**
308  * @brief num bytes in the head
309  * 
310  * @param adf_nbuf
311  * 
312  * @return num of bytes available
313  */
314 static inline a_uint32_t
315 __adf_nbuf_headroom(__adf_nbuf_t  buf)
316 {
317     return buf->desc_list->data_offset;
318 }
319
320 /**
321  * @brief num of bytes available in the tail excluding the priv
322  *        portion
323  * 
324  * @param adf_nbuf
325  * 
326  * @return num of bytes
327  */
328
329 static inline a_uint32_t 
330 __adf_nbuf_tailroom(__adf_nbuf_t  buf)
331 {
332     VDESC *last_desc = __adf_nbuf_last(buf);
333     
334     return last_desc->buf_size - last_desc->data_offset - last_desc->data_size;
335 }
336
337 /**
338  * @brief get the entire packet length
339  * 
340  * @param adf_nbuf
341  * 
342  * @return total length of packet (sum of all frag lengths)
343  */ 
344 static inline a_uint32_t
345 __adf_nbuf_len(__adf_nbuf_t  buf)
346 {
347     return buf->buf_length; 
348 }
349
350 /**
351  * @brief put data in the head
352  * 
353  * @param buf
354  * @param len (how much data to put)
355  * 
356  * @return new data pointer ,NULL if the len is more than the
357  *         space available in the head frag.
358  */
359 static inline a_uint8_t *       
360 __adf_nbuf_push_head(__adf_nbuf_t buf, adf_os_size_t len)
361 {
362     a_uint8_t *ptr = NULL; 
363     VDESC *desc = buf->desc_list;
364     
365     desc->data_offset -= len;
366     desc->data_size += len;
367     buf->buf_length += len;
368     ptr = desc->buf_addr + desc->data_offset;
369     return(ptr);
370 }
371
372 /**
373  * 
374  * @brief add data in the end of tail
375  * 
376  * @param buf
377  * @param len (how much data to put)
378  * 
379  * @return previous tail (data+len),NULL if the len is more than
380  *         space available
381  */
382 static inline a_uint8_t *
383 __adf_nbuf_put_tail(__adf_nbuf_t buf, adf_os_size_t len)
384 {
385     a_uint8_t *tail = NULL;
386     VDESC *last_desc = __adf_nbuf_last(buf);
387     
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;
391     
392     return tail;
393 }
394
395 /**
396  * @brief strip data from head
397  * 
398  * @param adf_nbuf
399  * @param len (how much data to rip)
400  * 
401  * @return new data pointer
402  */
403 static inline a_uint8_t * 
404 __adf_nbuf_pull_head(__adf_nbuf_t buf, adf_os_size_t len)
405 {
406     a_uint8_t *ptr = NULL;
407     VDESC *desc = buf->desc_list;
408     
409     desc->data_offset += len;
410     desc->data_size -= len;
411     buf->buf_length -= len;
412     ptr = desc->buf_addr + desc->data_offset;
413     
414     return ptr;
415 }
416
417 /**
418  * @brief retrieve the priv space pointer from nbuf
419  * 
420  * @param buf (nbuf to attach the priv space)
421  * 
422  * @return uint8_t* ( pointer to the data )
423  */
424 static inline a_uint8_t *
425 __adf_nbuf_get_priv(__adf_nbuf_t buf)
426 {
427     //adf_os_assert(buf != NULL);
428
429     return buf->ctx;
430 }
431
432 /**
433  * @brief returns the first guy in the Q
434  * @param qhead
435  * 
436  * @return (NULL if the Q is empty)
437  */
438 static inline __adf_nbuf_t   
439 __adf_nbuf_queue_first(__adf_nbuf_queue_t *qhead)
440 {
441     return qhead->head;
442 }
443 /**
444  * @brief return the next packet from packet chain
445  * 
446  * @param buf (packet)
447  * 
448  * @return (NULL if no packets are there)
449  */
450 static inline __adf_nbuf_t   
451 __adf_nbuf_queue_next(__adf_nbuf_t  buf)
452 {
453     return buf->next_buf;
454 }
455
456 #endif
457
458 #endif
459