8 * Copyright (c) 2008 Atheros Communications Inc.
15 #include <vdesc_api.h>
16 #include <Magpie_api.h>
20 #define VDESC_SIZE sizeof(VDESC)
21 //#define VDESC_TX_SIZE sizeof(VDESC_TX)
22 //#define VDESC_RX_SIZE sizeof(VDESC_RX)
24 static VDESC* alloc_rx_desc(void);
25 static VDESC* alloc_tx_desc(void);
26 void _vdesc_init(int nDesc);
27 A_UINT8* _vdesc_get_hw_desc(VDESC *desc);
28 VDESC* _vdesc_alloc_desc();
29 void _vdesc_swap_vdesc(VDESC *dest, VDESC *src);
31 struct VDESC_CONTEXT g_vdescCtx;
33 void _vdesc_init(int nDesc)
37 //int nextAddr = dataAddr;
38 //int nDesc = nTxDesc + nRxDesc;
40 // Initialize VDESC_TX for nTxDesc number
41 //vdesc = (VDESC*)dataAddr;
42 vdesc = (VDESC *)A_ALLOCRAM(sizeof(VDESC));
43 vdesc->next_desc = NULL;
47 g_vdescCtx.free_vdesc_head = vdesc;
49 for(i=1; i<nDesc; i++)
51 //nextAddr = dataAddr + i*VDESC_SIZE;
52 //vdesc = (VDESC*)nextAddr;
53 vdesc = (VDESC *)A_ALLOCRAM(sizeof(VDESC));
57 vdesc->next_desc = g_vdescCtx.free_vdesc_head;
58 g_vdescCtx.free_vdesc_head = vdesc;
61 //nextAddr = nextAddr + VDESC_SIZE;
65 g_vdescCtx.free_vdesc_tx_head = vdesc;
66 for(i=1; i<nTxDesc; i++)
68 nextAddr = dataAddr + i*VDESC_TX_SIZE;
69 vdesc = (VDESC*)nextAddr;
72 vdesc->next_desc = g_vdescCtx.free_vdesc_tx_head;
73 g_vdescCtx.free_vdesc_tx_head = vdesc;
76 nextAddr = nextAddr + VDESC_TX_SIZE;
78 // Initialize VDESC_RX for nTxDesc number
79 vdesc = (VDESC*)nextAddr;
80 vdesc->next_desc = NULL;
83 g_vdescCtx.free_vdesc_rx_head = vdesc;
84 for(i=1; i<nRxDesc; i++)
86 //nextAddr = nextAddr + i*VDESC_RX_SIZE;
87 vdesc = (VDESC*)(nextAddr + i*VDESC_RX_SIZE);
90 vdesc->next_desc = g_vdescCtx.free_vdesc_rx_head;
91 g_vdescCtx.free_vdesc_rx_head = vdesc;
94 return (nextAddr + nRxDesc*VDESC_RX_SIZE);
99 static VDESC* alloc_tx_desc(void)
101 VDESC *allocDesc = NULL;
103 if ( g_vdescCtx.free_vdesc_tx_head != NULL )
105 allocDesc = g_vdescCtx.free_vdesc_tx_head;
107 //g_vbufCtx.nVbufNum--;
109 g_vdescCtx.free_vdesc_tx_head = allocDesc->next_desc;
110 allocDesc->next_desc = NULL;
116 static VDESC* alloc_rx_desc(void)
118 VDESC *allocDesc = NULL;
120 if ( g_vdescCtx.free_vdesc_rx_head != NULL )
122 allocDesc = g_vdescCtx.free_vdesc_rx_head;
123 //g_vbufCtx.nVbufNum--;
125 g_vdescCtx.free_vdesc_rx_head = allocDesc->next_desc;
126 allocDesc->next_desc = NULL;
133 VDESC* _vdesc_alloc_desc()
136 VDESC *allocDesc = NULL;
138 if ( g_vdescCtx.free_vdesc_head != NULL )
140 allocDesc = g_vdescCtx.free_vdesc_head;
141 //g_vbufCtx.nVbufNum--;
143 g_vdescCtx.free_vdesc_head = allocDesc->next_desc;
144 allocDesc->next_desc = NULL;
149 if ( type == VDESC_TYPE_RX )
151 return alloc_rx_desc();
155 return alloc_tx_desc();
160 A_UINT8* _vdesc_get_hw_desc(VDESC *desc)
163 return desc->hw_desc_buf;
165 if ( type == VDESC_TYPE_RX )
167 return ((VDESC_RX*)desc)->hw_desc_buf;
171 return ((VDESC_TX*)desc)->hw_desc_buf;
176 void _vdesc_swap_vdesc(VDESC *dest, VDESC *src)
181 tmp = dest->buf_size;
182 dest->buf_size = src->buf_size;
185 tmp = dest->data_offset;
186 dest->data_offset = src->data_offset;
187 src->data_offset = tmp;
189 tmp = dest->data_size;
190 dest->data_size = src->data_size;
191 src->data_size = tmp;
194 dest->control = src->control;
197 tmpAddr = dest->buf_addr;
198 dest->buf_addr = src->buf_addr;
199 src->buf_addr = tmpAddr;
202 /* the exported entry point into this module. All apis are accessed through
203 * function pointers */
204 void vdesc_module_install(struct vdesc_api *apis)
207 apis->_init = _vdesc_init;
208 apis->_alloc_vdesc = _vdesc_alloc_desc;
209 apis->_get_hw_desc = _vdesc_get_hw_desc;
210 apis->_swap_vdesc = _vdesc_swap_vdesc;
212 //apis->_free_vbuf = _vbuf_free_vbuf;
214 /* save ptr to the ptr to the context for external code to inspect/modify internal module state */
215 //apis->pReserved = &g_pMboxHWContext;