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