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.
45 #include <vdesc_api.h>
46 #include <Magpie_api.h>
50 #define VDESC_SIZE sizeof(VDESC)
51 //#define VDESC_TX_SIZE sizeof(VDESC_TX)
52 //#define VDESC_RX_SIZE sizeof(VDESC_RX)
54 static VDESC* alloc_rx_desc(void);
55 static VDESC* alloc_tx_desc(void);
56 void _vdesc_init(int nDesc);
57 A_UINT8* _vdesc_get_hw_desc(VDESC *desc);
58 VDESC* _vdesc_alloc_desc();
59 void _vdesc_swap_vdesc(VDESC *dest, VDESC *src);
61 struct VDESC_CONTEXT g_vdescCtx;
63 void _vdesc_init(int nDesc)
67 //int nextAddr = dataAddr;
68 //int nDesc = nTxDesc + nRxDesc;
70 // Initialize VDESC_TX for nTxDesc number
71 //vdesc = (VDESC*)dataAddr;
72 vdesc = (VDESC *)A_ALLOCRAM(sizeof(VDESC));
73 vdesc->next_desc = NULL;
77 g_vdescCtx.free_vdesc_head = vdesc;
79 for(i=1; i<nDesc; i++)
81 //nextAddr = dataAddr + i*VDESC_SIZE;
82 //vdesc = (VDESC*)nextAddr;
83 vdesc = (VDESC *)A_ALLOCRAM(sizeof(VDESC));
87 vdesc->next_desc = g_vdescCtx.free_vdesc_head;
88 g_vdescCtx.free_vdesc_head = vdesc;
91 //nextAddr = nextAddr + VDESC_SIZE;
95 g_vdescCtx.free_vdesc_tx_head = vdesc;
96 for(i=1; i<nTxDesc; i++)
98 nextAddr = dataAddr + i*VDESC_TX_SIZE;
99 vdesc = (VDESC*)nextAddr;
102 vdesc->next_desc = g_vdescCtx.free_vdesc_tx_head;
103 g_vdescCtx.free_vdesc_tx_head = vdesc;
106 nextAddr = nextAddr + VDESC_TX_SIZE;
108 // Initialize VDESC_RX for nTxDesc number
109 vdesc = (VDESC*)nextAddr;
110 vdesc->next_desc = NULL;
113 g_vdescCtx.free_vdesc_rx_head = vdesc;
114 for(i=1; i<nRxDesc; i++)
116 //nextAddr = nextAddr + i*VDESC_RX_SIZE;
117 vdesc = (VDESC*)(nextAddr + i*VDESC_RX_SIZE);
120 vdesc->next_desc = g_vdescCtx.free_vdesc_rx_head;
121 g_vdescCtx.free_vdesc_rx_head = vdesc;
124 return (nextAddr + nRxDesc*VDESC_RX_SIZE);
129 static VDESC* alloc_tx_desc(void)
131 VDESC *allocDesc = NULL;
133 if ( g_vdescCtx.free_vdesc_tx_head != NULL )
135 allocDesc = g_vdescCtx.free_vdesc_tx_head;
137 //g_vbufCtx.nVbufNum--;
139 g_vdescCtx.free_vdesc_tx_head = allocDesc->next_desc;
140 allocDesc->next_desc = NULL;
146 static VDESC* alloc_rx_desc(void)
148 VDESC *allocDesc = NULL;
150 if ( g_vdescCtx.free_vdesc_rx_head != NULL )
152 allocDesc = g_vdescCtx.free_vdesc_rx_head;
153 //g_vbufCtx.nVbufNum--;
155 g_vdescCtx.free_vdesc_rx_head = allocDesc->next_desc;
156 allocDesc->next_desc = NULL;
163 VDESC* _vdesc_alloc_desc()
166 VDESC *allocDesc = NULL;
168 if ( g_vdescCtx.free_vdesc_head != NULL )
170 allocDesc = g_vdescCtx.free_vdesc_head;
171 //g_vbufCtx.nVbufNum--;
173 g_vdescCtx.free_vdesc_head = allocDesc->next_desc;
174 allocDesc->next_desc = NULL;
179 if ( type == VDESC_TYPE_RX )
181 return alloc_rx_desc();
185 return alloc_tx_desc();
190 A_UINT8* _vdesc_get_hw_desc(VDESC *desc)
193 return desc->hw_desc_buf;
195 if ( type == VDESC_TYPE_RX )
197 return ((VDESC_RX*)desc)->hw_desc_buf;
201 return ((VDESC_TX*)desc)->hw_desc_buf;
206 void _vdesc_swap_vdesc(VDESC *dest, VDESC *src)
211 tmp = dest->buf_size;
212 dest->buf_size = src->buf_size;
215 tmp = dest->data_offset;
216 dest->data_offset = src->data_offset;
217 src->data_offset = tmp;
219 tmp = dest->data_size;
220 dest->data_size = src->data_size;
221 src->data_size = tmp;
224 dest->control = src->control;
227 tmpAddr = dest->buf_addr;
228 dest->buf_addr = src->buf_addr;
229 src->buf_addr = tmpAddr;
232 /* the exported entry point into this module. All apis are accessed through
233 * function pointers */
234 void vdesc_module_install(struct vdesc_api *apis)
237 apis->_init = _vdesc_init;
238 apis->_alloc_vdesc = _vdesc_alloc_desc;
239 apis->_get_hw_desc = _vdesc_get_hw_desc;
240 apis->_swap_vdesc = _vdesc_swap_vdesc;
242 //apis->_free_vbuf = _vbuf_free_vbuf;
244 /* save ptr to the ptr to the context for external code to inspect/modify internal module state */
245 //apis->pReserved = &g_pMboxHWContext;